@@ -23,19 +23,49 @@ class CondaBuildPack(BaseImage):
2323
2424 """
2525
26+ # The kernel conda environment file, if any.
27+ # As an absolute path within the container.
28+ _kernel_environment_file = ""
29+ # extra pip requirements.txt for the kernel
30+ _kernel_requirements_file = ""
31+
32+ # The notebook server environment file.
33+ # As an absolute path within the container.
34+ _nb_environment_file = ""
35+ # extra pip requirements.txt for the notebook env
36+ _nb_requirements_file = ""
37+
2638 def get_build_env (self ):
2739 """Return environment variables to be set.
2840
2941 We set `CONDA_DIR` to the conda install directory and
3042 the `NB_PYTHON_PREFIX` to the location of the jupyter binary.
3143
3244 """
45+ if not self ._nb_environment_file :
46+ # get_build_script_files locates requirements/environment files,
47+ # populating the _nb_environment_file attribute and others.
48+ # FIXME: move file detection and initialization of those attributes to its own step?
49+ self .get_build_script_files ()
50+
3351 env = super ().get_build_env () + [
3452 ("CONDA_DIR" , "${APP_BASE}/conda" ),
3553 ("NB_PYTHON_PREFIX" , "${CONDA_DIR}/envs/notebook" ),
54+ ("NB_ENVIRONMENT_FILE" , self ._nb_environment_file ),
3655 ]
37- if self .py2 :
38- env .append (("KERNEL_PYTHON_PREFIX" , "${CONDA_DIR}/envs/kernel" ))
56+ if self ._nb_requirements_file :
57+ env .append (("NB_REQUIREMENTS_FILE" , self ._nb_requirements_file ))
58+
59+ if self ._kernel_environment_file :
60+ # if kernel environment file is separate
61+ env .extend (
62+ [
63+ ("KERNEL_PYTHON_PREFIX" , "${CONDA_DIR}/envs/kernel" ),
64+ ("KERNEL_ENVIRONMENT_FILE" , self ._kernel_environment_file ),
65+ ]
66+ )
67+ if self ._kernel_requirements_file :
68+ env .append (("KERNEL_REQUIREMENTS_FILE" , self ._kernel_requirements_file ))
3969 else :
4070 env .append (("KERNEL_PYTHON_PREFIX" , "${NB_PYTHON_PREFIX}" ))
4171 return env
@@ -81,7 +111,7 @@ def get_build_scripts(self):
81111 r"""
82112 TIMEFORMAT='time: %3R' \
83113 bash -c 'time /tmp/install-miniforge.bash' && \
84- rm /tmp/install-miniforge.bash /tmp/environment.yml
114+ rm -rf /tmp/install-miniforge.bash /tmp/env
85115 """ ,
86116 )
87117 ]
@@ -114,20 +144,38 @@ def get_build_script_files(self):
114144 # major Python versions during upgrade.
115145 # If no version is specified or no matching X.Y version is found,
116146 # the default base environment is used.
117- frozen_name = "environment.frozen.yml"
147+ frozen_name = "environment.lock"
148+ pip_frozen_name = "requirements.txt"
118149 if py_version :
119150 if self .py2 :
120151 # python 2 goes in a different env
121152 files [
122- "conda/environment.py-2.7.frozen.yml"
123- ] = "/tmp/kernel-environment.yml"
153+ "conda/environment.py-2.7.lock"
154+ ] = self ._kernel_environment_file = "/tmp/env/kernel-environment.lock"
155+ # additional pip requirements for kernel env
156+ if os .path .exists (os .path .join (HERE , "requirements.py-2.7.txt" )):
157+ files [
158+ "conda/requirements.py-2.7.txt"
159+ ] = (
160+ self ._kernel_requirements_file
161+ ) = "/tmp/env/kernel-requirements.txt"
124162 else :
125- py_frozen_name = "environment.py-{py}.frozen.yml" . format ( py = py_version )
163+ py_frozen_name = f "environment.py-{ py_version } .lock"
126164 if os .path .exists (os .path .join (HERE , py_frozen_name )):
127165 frozen_name = py_frozen_name
128- else :
129- self .log .warning ("No frozen env: %s" , py_frozen_name )
130- files ["conda/" + frozen_name ] = "/tmp/environment.yml"
166+ pip_frozen_name = f"requirements.py-{ py_version } .txt"
167+ if not frozen_name :
168+ self .log .warning (f"No frozen env for { py_version } " )
169+ files [
170+ "conda/" + frozen_name
171+ ] = self ._nb_environment_file = "/tmp/env/environment.lock"
172+
173+ # add requirements.txt, if present
174+ if os .path .exists (os .path .join (HERE , pip_frozen_name )):
175+ files [
176+ "conda/" + pip_frozen_name
177+ ] = self ._nb_requirements_file = "/tmp/env/requirements.txt"
178+
131179 files .update (super ().get_build_script_files ())
132180 return files
133181
0 commit comments