kopia lustrzana https://github.com/jupyterhub/repo2docker
Black formatting applied
rodzic
e58b5c316e
commit
6de7a8c97a
|
@ -4,6 +4,7 @@ import re
|
|||
|
||||
from ..conda import CondaBuildPack
|
||||
|
||||
|
||||
class PipfileBuildPack(CondaBuildPack):
|
||||
"""Setup Python with pipfile for use with a repository."""
|
||||
|
||||
|
@ -15,30 +16,30 @@ class PipfileBuildPack(CondaBuildPack):
|
|||
Falsy empty string '' if not found.
|
||||
"""
|
||||
|
||||
if hasattr(self, '_python_version'):
|
||||
if hasattr(self, "_python_version"):
|
||||
return self._python_version
|
||||
|
||||
files_to_search_in_order = [
|
||||
{
|
||||
'path': self.binder_path('Pipfile.lock'),
|
||||
'pattern': r'\s*\"python_(?:full_)?version\": \"?([0-9a-z\.]*)\"?', # ' "python_version": "3.6"'
|
||||
"path": self.binder_path("Pipfile.lock"),
|
||||
"pattern": r"\s*\"python_(?:full_)?version\": \"?([0-9a-z\.]*)\"?", # ' "python_version": "3.6"'
|
||||
},
|
||||
{
|
||||
'path': self.binder_path('Pipfile'),
|
||||
'pattern': r'python_(?:full_)?version\s*=+\s*\"?([0-9a-z\.]*)\"?', # 'python_version = "3.6"'
|
||||
"path": self.binder_path("Pipfile"),
|
||||
"pattern": r"python_(?:full_)?version\s*=+\s*\"?([0-9a-z\.]*)\"?", # 'python_version = "3.6"'
|
||||
},
|
||||
{
|
||||
'path': self.binder_path('runtime.txt'),
|
||||
'pattern': r'\s*python-([0-9a-z\.]*)\s*', # 'python-3.6'
|
||||
"path": self.binder_path("runtime.txt"),
|
||||
"pattern": r"\s*python-([0-9a-z\.]*)\s*", # 'python-3.6'
|
||||
},
|
||||
]
|
||||
|
||||
py_version = None
|
||||
for file in files_to_search_in_order:
|
||||
try:
|
||||
with open(file['path']) as f:
|
||||
with open(file["path"]) as f:
|
||||
for line in f:
|
||||
match = re.match(file['pattern'], line)
|
||||
match = re.match(file["pattern"], line)
|
||||
if not match:
|
||||
continue
|
||||
py_version = match.group(1)
|
||||
|
@ -54,11 +55,11 @@ class PipfileBuildPack(CondaBuildPack):
|
|||
self._python_version = self.major_pythons.get(py_version[0])
|
||||
else:
|
||||
# return major.minor
|
||||
self._python_version = '.'.join(py_version.split('.')[:2])
|
||||
self._python_version = ".".join(py_version.split(".")[:2])
|
||||
return self._python_version
|
||||
else:
|
||||
# use the default Python
|
||||
self._python_version = self.major_pythons['3']
|
||||
self._python_version = self.major_pythons["3"]
|
||||
return self._python_version
|
||||
|
||||
def get_assemble_scripts(self):
|
||||
|
@ -73,36 +74,45 @@ class PipfileBuildPack(CondaBuildPack):
|
|||
if self.py2:
|
||||
# using python 2 kernel,
|
||||
# requirements3.txt allows installation in the notebook server env
|
||||
nb_requirements_file = self.binder_path('requirements3.txt')
|
||||
nb_requirements_file = self.binder_path("requirements3.txt")
|
||||
if os.path.exists(nb_requirements_file):
|
||||
assemble_scripts.append((
|
||||
'${NB_USER}',
|
||||
# want the $NB_PYHTON_PREFIX environment variable, not for
|
||||
# Python's string formatting to try and replace this
|
||||
'${{NB_PYTHON_PREFIX}}/bin/pip install --no-cache-dir -r "{}"'.format(nb_requirements_file)
|
||||
))
|
||||
assemble_scripts.append(
|
||||
(
|
||||
"${NB_USER}",
|
||||
# want the $NB_PYHTON_PREFIX environment variable, not for
|
||||
# Python's string formatting to try and replace this
|
||||
'${{NB_PYTHON_PREFIX}}/bin/pip install --no-cache-dir -r "{}"'.format(
|
||||
nb_requirements_file
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
# install Pipfile.lock or fallback to installing Pipfile
|
||||
pipenv = '${KERNEL_PYTHON_PREFIX}/bin/pipenv'
|
||||
python = '${KERNEL_PYTHON_PREFIX}/bin/python'
|
||||
pipfile = self.binder_path('Pipfile')
|
||||
pipfile_lock = self.binder_path('Pipfile.lock')
|
||||
working_directory = self.binder_dir or '.'
|
||||
assemble_scripts.append((
|
||||
'${NB_USER}',
|
||||
'pip install pipenv'
|
||||
))
|
||||
pipenv = "${KERNEL_PYTHON_PREFIX}/bin/pipenv"
|
||||
python = "${KERNEL_PYTHON_PREFIX}/bin/python"
|
||||
pipfile = self.binder_path("Pipfile")
|
||||
pipfile_lock = self.binder_path("Pipfile.lock")
|
||||
working_directory = self.binder_dir or "."
|
||||
assemble_scripts.append(("${NB_USER}", "pip install pipenv"))
|
||||
# if Pipfile.lock isn't found, Pipfile is used to create one
|
||||
if not os.path.exists(pipfile_lock):
|
||||
assemble_scripts.append((
|
||||
'${NB_USER}',
|
||||
'(cd {} && {} lock --python {})'.format(working_directory, pipenv, python)
|
||||
))
|
||||
assemble_scripts.append(
|
||||
(
|
||||
"${NB_USER}",
|
||||
"(cd {} && {} lock --python {})".format(
|
||||
working_directory, pipenv, python
|
||||
),
|
||||
)
|
||||
)
|
||||
# install Pipfile.lock
|
||||
assemble_scripts.append((
|
||||
'${NB_USER}',
|
||||
'(cd {} && {} install --ignore-pipfile --deploy --system --dev --python {})'.format(working_directory, pipenv, python)
|
||||
))
|
||||
assemble_scripts.append(
|
||||
(
|
||||
"${NB_USER}",
|
||||
"(cd {} && {} install --ignore-pipfile --deploy --system --dev --python {})".format(
|
||||
working_directory, pipenv, python
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
return assemble_scripts
|
||||
|
||||
|
@ -110,14 +120,14 @@ class PipfileBuildPack(CondaBuildPack):
|
|||
"""Check if current repo should be built with the Python buildpack.
|
||||
"""
|
||||
# first make sure python is not explicitly unwanted
|
||||
runtime_txt = self.binder_path('runtime.txt')
|
||||
runtime_txt = self.binder_path("runtime.txt")
|
||||
if os.path.exists(runtime_txt):
|
||||
with open(runtime_txt) as f:
|
||||
runtime = f.read().strip()
|
||||
if not runtime.startswith("python-"):
|
||||
return False
|
||||
|
||||
pipfile = self.binder_path('Pipfile')
|
||||
pipfile_lock = self.binder_path('Pipfile.lock')
|
||||
pipfile = self.binder_path("Pipfile")
|
||||
pipfile_lock = self.binder_path("Pipfile.lock")
|
||||
|
||||
return os.path.exists(pipfile) or os.path.exists(pipfile_lock)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name='Dummy',
|
||||
version='1.0.0',
|
||||
url='https://git-place.org/dummy/dummy.git',
|
||||
author='Dummy Name',
|
||||
author_email='dummy@my-email.com',
|
||||
description='Dummy package for testing purposes only',
|
||||
name="Dummy",
|
||||
version="1.0.0",
|
||||
url="https://git-place.org/dummy/dummy.git",
|
||||
author="Dummy Name",
|
||||
author_email="dummy@my-email.com",
|
||||
description="Dummy package for testing purposes only",
|
||||
packages=find_packages(),
|
||||
install_requires=['pypi-pkg-test==0.0.4'],
|
||||
install_requires=["pypi-pkg-test==0.0.4"],
|
||||
)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name='Dummy',
|
||||
version='1.0.0',
|
||||
url='https://git-place.org/dummy/dummy.git',
|
||||
author='Dummy Name',
|
||||
author_email='dummy@my-email.com',
|
||||
description='Dummy package for testing purposes only',
|
||||
name="Dummy",
|
||||
version="1.0.0",
|
||||
url="https://git-place.org/dummy/dummy.git",
|
||||
author="Dummy Name",
|
||||
author_email="dummy@my-email.com",
|
||||
description="Dummy package for testing purposes only",
|
||||
packages=find_packages(),
|
||||
install_requires=['pypi-pkg-test==0.0.4'],
|
||||
install_requires=["pypi-pkg-test==0.0.4"],
|
||||
)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name='Dummy',
|
||||
version='1.0.0',
|
||||
url='https://git-place.org/dummy/dummy.git',
|
||||
author='Dummy Name',
|
||||
author_email='dummy@my-email.com',
|
||||
description='Dummy package for testing purposes only',
|
||||
name="Dummy",
|
||||
version="1.0.0",
|
||||
url="https://git-place.org/dummy/dummy.git",
|
||||
author="Dummy Name",
|
||||
author_email="dummy@my-email.com",
|
||||
description="Dummy package for testing purposes only",
|
||||
packages=find_packages(),
|
||||
install_requires=['pypi-pkg-test==0.0.4'],
|
||||
install_requires=["pypi-pkg-test==0.0.4"],
|
||||
)
|
||||
|
|
Ładowanie…
Reference in New Issue