kopia lustrzana https://github.com/jupyterhub/repo2docker
Cache python_version detection in conda buildpack
rodzic
bcf3aedce2
commit
e913fce474
|
@ -48,7 +48,7 @@ class CondaBuildPack(BuildPack):
|
||||||
files = {
|
files = {
|
||||||
'conda/install-miniconda.bash': '/tmp/install-miniconda.bash',
|
'conda/install-miniconda.bash': '/tmp/install-miniconda.bash',
|
||||||
}
|
}
|
||||||
py_version = self.get_python_version()
|
py_version = self.python_version
|
||||||
self.log.info("Building conda environment for python=%s" % py_version)
|
self.log.info("Building conda environment for python=%s" % py_version)
|
||||||
# Select the frozen base environment based on Python version.
|
# Select the frozen base environment based on Python version.
|
||||||
# avoids expensive and possibly conflicting upgrades when changing
|
# avoids expensive and possibly conflicting upgrades when changing
|
||||||
|
@ -70,42 +70,46 @@ class CondaBuildPack(BuildPack):
|
||||||
files['conda/' + frozen_name] = '/tmp/environment.yml'
|
files['conda/' + frozen_name] = '/tmp/environment.yml'
|
||||||
return files
|
return files
|
||||||
|
|
||||||
def get_python_version(self):
|
@property
|
||||||
|
def python_version(self):
|
||||||
"""
|
"""
|
||||||
Detect the Python version for a given environment.yml
|
Detect the Python version for a given environment.yml
|
||||||
|
|
||||||
Will return 'x.y' if found, or Falsy '' if not.
|
Will return 'x.y' if found, or Falsy '' if not.
|
||||||
"""
|
"""
|
||||||
py_version = None
|
|
||||||
environment_yml = self.binder_path('environment.yml')
|
environment_yml = self.binder_path('environment.yml')
|
||||||
if not os.path.exists(environment_yml):
|
if not os.path.exists(environment_yml):
|
||||||
return ''
|
return ''
|
||||||
with open(environment_yml) as f:
|
|
||||||
env = YAML().load(f)
|
|
||||||
for dep in env.get('dependencies', []):
|
|
||||||
if not isinstance(dep, str):
|
|
||||||
continue
|
|
||||||
match = PYTHON_REGEX.match(dep)
|
|
||||||
if not match:
|
|
||||||
continue
|
|
||||||
py_version = match.group(1)
|
|
||||||
break
|
|
||||||
|
|
||||||
# extract major.minor
|
if not hasattr(self, '_python_version'):
|
||||||
if py_version:
|
py_version = None
|
||||||
if len(py_version) == 1:
|
with open(environment_yml) as f:
|
||||||
return self.major_pythons.get(py_version[0])
|
env = YAML().load(f)
|
||||||
|
for dep in env.get('dependencies', []):
|
||||||
|
if not isinstance(dep, str):
|
||||||
|
continue
|
||||||
|
match = PYTHON_REGEX.match(dep)
|
||||||
|
if not match:
|
||||||
|
continue
|
||||||
|
py_version = match.group(1)
|
||||||
|
break
|
||||||
|
|
||||||
|
# extract major.minor
|
||||||
|
if py_version:
|
||||||
|
if len(py_version) == 1:
|
||||||
|
self._python_version = self.major_pythons.get(py_version[0])
|
||||||
|
else:
|
||||||
|
# return major.minor
|
||||||
|
self._python_version = '.'.join(py_version[:2])
|
||||||
else:
|
else:
|
||||||
# return major.minor
|
self._python_version = ''
|
||||||
return '.'.join(py_version[:2])
|
|
||||||
|
|
||||||
return ''
|
return self._python_version
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def py2(self):
|
def py2(self):
|
||||||
"""Am I building a Python 2 kernel environment?"""
|
"""Am I building a Python 2 kernel environment?"""
|
||||||
python_version = self.get_python_version()
|
return self.python_version and self.python_version.split('.')[0] == '2'
|
||||||
return python_version and python_version.split('.')[0] == '2'
|
|
||||||
|
|
||||||
def get_assemble_scripts(self):
|
def get_assemble_scripts(self):
|
||||||
assembly_scripts = []
|
assembly_scripts = []
|
||||||
|
|
Ładowanie…
Reference in New Issue