@@ -23,6 +23,14 @@ class CondaBuildPack(BaseImage):
23
23
24
24
"""
25
25
26
+ # The kernel environment file, if any.
27
+ # As an absolute path within the container.
28
+ _kernel_environment_file = ""
29
+
30
+ # The notebook server environment file, if any.
31
+ # As an absolute path within the container.
32
+ _nb_environment_file = ""
33
+
26
34
def get_build_env (self ):
27
35
"""Return environment variables to be set.
28
36
@@ -33,9 +41,15 @@ def get_build_env(self):
33
41
env = super ().get_build_env () + [
34
42
("CONDA_DIR" , "${APP_BASE}/conda" ),
35
43
("NB_PYTHON_PREFIX" , "${CONDA_DIR}/envs/notebook" ),
44
+ ("NB_ENVIRONMENT_FILE" , self ._nb_environment_file ),
36
45
]
37
46
if self .py2 :
38
- env .append (("KERNEL_PYTHON_PREFIX" , "${CONDA_DIR}/envs/kernel" ))
47
+ env .extend (
48
+ [
49
+ ("KERNEL_PYTHON_PREFIX" , "${CONDA_DIR}/envs/kernel" ),
50
+ ("KERNEL_ENVIRONMENT_FILE" , self ._kernel_environment_file ),
51
+ ]
52
+ )
39
53
else :
40
54
env .append (("KERNEL_PYTHON_PREFIX" , "${NB_PYTHON_PREFIX}" ))
41
55
return env
@@ -81,7 +95,7 @@ def get_build_scripts(self):
81
95
r"""
82
96
TIMEFORMAT='time: %3R' \
83
97
bash -c 'time /tmp/install-miniforge.bash' && \
84
- rm /tmp/install-miniforge.bash /tmp/environment.yml
98
+ rm /tmp/install-miniforge.bash ${NB_ENVIRONMENT_FILE}
85
99
""" ,
86
100
)
87
101
]
@@ -114,20 +128,25 @@ def get_build_script_files(self):
114
128
# major Python versions during upgrade.
115
129
# If no version is specified or no matching X.Y version is found,
116
130
# the default base environment is used.
117
- frozen_name = "environment.frozen.yml "
131
+ frozen_name = "environment.lock "
118
132
if py_version :
119
133
if self .py2 :
120
134
# python 2 goes in a different env
121
135
files [
122
- "conda/environment.py-2.7.frozen.yml "
123
- ] = "/tmp/kernel-environment.yml "
136
+ "conda/environment.py-2.7.lock "
137
+ ] = self . _kernel_environment_file = "/tmp/kernel-environment.lock "
124
138
else :
125
- py_frozen_name = "environment.py-{py}.frozen.yml" .format (py = py_version )
126
- if os .path .exists (os .path .join (HERE , py_frozen_name )):
127
- 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"
139
+ for ext in [".lock" , ".frozen.yml" ]:
140
+ py_frozen_name = f"environment.py-{ py_version } { ext } "
141
+ if os .path .exists (os .path .join (HERE , py_frozen_name )):
142
+ frozen_name = py_frozen_name
143
+ break
144
+ if not frozen_name :
145
+ self .log .warning (f"No frozen env for { py_version } " )
146
+ _ , frozen_ext = os .path .splitext (frozen_name )
147
+ files [
148
+ "conda/" + frozen_name
149
+ ] = self ._nb_environment_file = f"/tmp/environment{ frozen_ext } "
131
150
files .update (super ().get_build_script_files ())
132
151
return files
133
152
0 commit comments