Move path and env from traitlets to methods
MODIFY
repo2docker/buildpacks/base.py
repo2docker/buildpacks/base.py
@@ -162,9 +162,8 @@ class BuildPack(LoggingConfigurable):
"npm",
}
- env = List(
- [],
- help="""
+ def get_env(self):
+ """
Ordered list of environment variables to be set for this image.
Ordered so that environment variables can use other environment
@@ -173,17 +172,16 @@ class BuildPack(LoggingConfigurable):
Expects tuples, with the first item being the environment variable
name and the second item being the value.
"""
- )
+ return []
- path = List(
- [],
- help="""
+ def get_path(self):
+ """
Ordered list of file system paths to look for executables in.
Just sets the PATH environment variable. Separated out since
it is very commonly set by various buildpacks.
"""
- )
+ return []
labels = Dict(
{},
@@ -292,10 +290,9 @@ class BuildPack(LoggingConfigurable):
# FIXME: Temporary hack so we can refactor this piece by piece instead of all at once!
result.get_packages = lambda: self.get_packages().union(other.get_packages())
result.get_base_packages = lambda: self.get_base_packages().union(other.get_base_packages())
+ result.get_path = lambda: self.get_path() + other.get_path()
+ result.get_env = lambda: self.get_env() + other.get_env()
- result.path = self.path + other.path
- # FIXME: Deduplicate Env
- result.env = self.env + other.env
result.build_scripts = self.build_scripts + other.build_scripts
result.assemble_scripts = (self.assemble_scripts +
other.assemble_scripts)
@@ -351,8 +348,8 @@ class BuildPack(LoggingConfigurable):
return t.render(
packages=sorted(self.get_packages()),
- path=self.path,
- env=self.env,
+ path=self.get_path(),
+ env=self.get_env(),
labels=self.labels,
build_script_directives=build_script_directives,
assemble_script_directives=assemble_script_directives,

MODIFY
repo2docker/buildpacks/conda/__init__.py
repo2docker/buildpacks/conda/__init__.py
@@ -19,12 +19,14 @@ HERE = os.path.dirname(os.path.abspath(__file__))
class CondaBuildPack(BuildPack):
name = "conda"
version = "0.1"
- env = [
+ def get_env(self):
+ return [
('CONDA_DIR', '${APP_BASE}/conda'),
('NB_PYTHON_PREFIX', '${CONDA_DIR}'),
]
- path = ['${CONDA_DIR}/bin']
+ def get_path(self):
+ return ['${CONDA_DIR}/bin']
build_scripts = [
(

MODIFY
repo2docker/buildpacks/julia.py
repo2docker/buildpacks/julia.py
@@ -9,7 +9,9 @@ from .base import BuildPack
class JuliaBuildPack(BuildPack):
name = "julia"
version = "0.1"
- env = [
+
+ def get_env(self):
+ return [
('JULIA_PATH', '${APP_BASE}/julia'),
('JULIA_HOME', '${JULIA_PATH}/bin'),
('JULIA_PKGDIR', '${JULIA_PATH}/pkg'),
@@ -17,9 +19,8 @@ class JuliaBuildPack(BuildPack):
('JUPYTER', '${NB_PYTHON_PREFIX}/bin/jupyter')
]
- path = [
- '${JULIA_PATH}/bin'
- ]
+ def get_path(self):
+ return ['${JULIA_PATH}/bin']
build_scripts = [
(

MODIFY
repo2docker/buildpacks/python/__init__.py
repo2docker/buildpacks/python/__init__.py
@@ -17,13 +17,15 @@ class PythonBuildPack(BuildPack):
'python3-dev',
}
- env = [
+ def get_env(self):
+ return [
("VENV_PATH", "${APP_BASE}/venv"),
# Prefix to use for installing kernels and finding jupyter binary
("NB_PYTHON_PREFIX", "${VENV_PATH}"),
]
- path = [
+ def get_path(self):
+ return [
"${VENV_PATH}/bin"
]
@@ -100,11 +102,13 @@ class Python2BuildPack(BuildPack):
'python/requirements2.frozen.txt': '/tmp/requirements2.frozen.txt',
}
- env = [
+ def get_env(self):
+ return [
('VENV2_PATH', '${APP_BASE}/venv2')
]
- path = [
+ def get_path(self):
+ return [
"${VENV2_PATH}/bin"
]

Move path and env from traitlets to methods