@@ -23,19 +23,49 @@ class CondaBuildPack(BaseImage):
23
23
24
24
"""
25
25
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
+
26
38
def get_build_env (self ):
27
39
"""Return environment variables to be set.
28
40
29
41
We set `CONDA_DIR` to the conda install directory and
30
42
the `NB_PYTHON_PREFIX` to the location of the jupyter binary.
31
43
32
44
"""
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
+
33
51
env = super ().get_build_env () + [
34
52
("CONDA_DIR" , "${APP_BASE}/conda" ),
35
53
("NB_PYTHON_PREFIX" , "${CONDA_DIR}/envs/notebook" ),
54
+ ("NB_ENVIRONMENT_FILE" , self ._nb_environment_file ),
36
55
]
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 ))
39
69
else :
40
70
env .append (("KERNEL_PYTHON_PREFIX" , "${NB_PYTHON_PREFIX}" ))
41
71
return env
@@ -81,7 +111,7 @@ def get_build_scripts(self):
81
111
r"""
82
112
TIMEFORMAT='time: %3R' \
83
113
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
85
115
""" ,
86
116
)
87
117
]
@@ -114,20 +144,38 @@ def get_build_script_files(self):
114
144
# major Python versions during upgrade.
115
145
# If no version is specified or no matching X.Y version is found,
116
146
# the default base environment is used.
117
- frozen_name = "environment.frozen.yml"
147
+ frozen_name = "environment.lock"
148
+ pip_frozen_name = "requirements.txt"
118
149
if py_version :
119
150
if self .py2 :
120
151
# python 2 goes in a different env
121
152
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"
124
162
else :
125
- py_frozen_name = "environment.py-{py}.frozen.yml" . format ( py = py_version )
163
+ py_frozen_name = f "environment.py-{ py_version } .lock"
126
164
if os .path .exists (os .path .join (HERE , py_frozen_name )):
127
165
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
+
131
179
files .update (super ().get_build_script_files ())
132
180
return files
133
181
0 commit comments