@@ -151,7 +151,9 @@ def _create(
151
151
conda_dep = yaml .safe_load (mfile .read ())
152
152
# If manifest exists in the environment.yaml file, use that
153
153
manifest = conda_dep .get ("manifest" , {})
154
- slug = manifest .get ("slug" , f"{ name } _v{ version } " .replace (" " , "" ).replace ("." , "_" ).lower ())
154
+ slug = manifest .get (
155
+ "slug" , f"{ name } _v{ version } " .replace (" " , "" ).replace ("." , "_" ).lower ()
156
+ )
155
157
pack_folder_path = os .path .join (
156
158
os .path .abspath (os .path .expanduser (conda_pack_folder )), slug
157
159
)
@@ -176,7 +178,9 @@ def _create(
176
178
177
179
os .makedirs (pack_folder_path , exist_ok = True )
178
180
179
- logger .info (f"Preparing manifest. Manifest in the environment: { conda_dep .get ('manifest' )} " )
181
+ logger .info (
182
+ f"Preparing manifest. Manifest in the environment: { conda_dep .get ('manifest' )} "
183
+ )
180
184
manifest = _fetch_manifest_template ()
181
185
if not "name" in conda_dep ["manifest" ]:
182
186
manifest ["manifest" ]["name" ] = name
@@ -196,12 +200,22 @@ def _create(
196
200
manifest ["manifest" ]["manifest_version" ] = "1.0"
197
201
198
202
logger .info (f"Creating conda environment { slug } " )
199
- conda_dep ["manifest" ].update ({k : manifest ["manifest" ][k ] for k in manifest ["manifest" ] if manifest ["manifest" ][k ]})
203
+ conda_dep ["manifest" ].update (
204
+ {
205
+ k : manifest ["manifest" ][k ]
206
+ for k in manifest ["manifest" ]
207
+ if manifest ["manifest" ][k ]
208
+ }
209
+ )
200
210
logger .info (f"Updated conda environment manifest: { conda_dep .get ('manifest' )} " )
201
211
202
212
if is_in_notebook_session () or NO_CONTAINER :
203
213
command = f"conda env create --prefix { pack_folder_path } --file { os .path .abspath (os .path .expanduser (env_file ))} "
204
- run_command (command , shell = True )
214
+ proc = run_command (command , shell = True )
215
+ if proc .returncode != 0 :
216
+ raise RuntimeError (
217
+ f"Failed to create conda environment. (exit code { proc .returncode } )"
218
+ )
205
219
else :
206
220
_check_job_image_exists (gpu )
207
221
docker_pack_folder_path = os .path .join (DEFAULT_IMAGE_HOME_DIR , slug )
@@ -210,13 +224,12 @@ def _create(
210
224
)
211
225
212
226
create_command = f"conda env create --prefix { docker_pack_folder_path } --file { docker_env_file_path } "
213
-
227
+
214
228
volumes = {
215
229
pack_folder_path : {"bind" : docker_pack_folder_path },
216
230
os .path .abspath (os .path .expanduser (env_file )): {
217
231
"bind" : docker_env_file_path
218
232
},
219
-
220
233
}
221
234
222
235
if gpu :
@@ -227,26 +240,42 @@ def _create(
227
240
if prepare_publish :
228
241
tmp_file = tempfile .NamedTemporaryFile (suffix = ".yaml" )
229
242
# Save the manifest in the temp file that can be mounted inside the container so that archiving will work
230
- with open (tmp_file .name , 'w' ) as f :
231
- yaml .safe_dump (conda_dep , f )
243
+ with open (tmp_file .name , "w" ) as f :
244
+ yaml .safe_dump (conda_dep , f )
232
245
233
- pack_script = os .path .join (os .path .dirname (os .path .abspath (__file__ )), "pack.py" )
246
+ pack_script = os .path .join (
247
+ os .path .dirname (os .path .abspath (__file__ )), "pack.py"
248
+ )
234
249
pack_command = f"python { os .path .join (DEFAULT_IMAGE_HOME_DIR , 'pack.py' )} --conda-path { docker_pack_folder_path } --manifest-location { os .path .join (DEFAULT_IMAGE_HOME_DIR , 'manifest.yaml' )} "
235
250
236
251
# add pack script and manifest file to the mount so that archive can be created in the same container run
237
252
condapack_script = {
238
- pack_script : {"bind" : os .path .join (DEFAULT_IMAGE_HOME_DIR , "pack.py" )},
239
- tmp_file .name : {"bind" : os .path .join (DEFAULT_IMAGE_HOME_DIR , "manifest.yaml" )}
253
+ pack_script : {
254
+ "bind" : os .path .join (DEFAULT_IMAGE_HOME_DIR , "pack.py" )
255
+ },
256
+ tmp_file .name : {
257
+ "bind" : os .path .join (DEFAULT_IMAGE_HOME_DIR , "manifest.yaml" )
258
+ },
240
259
}
241
- volumes = {** volumes , ** condapack_script } # | not supported in python 3.8
260
+ volumes = {
261
+ ** volumes ,
262
+ ** condapack_script ,
263
+ } # | not supported in python 3.8
242
264
243
265
run_container (
244
- image = image , bind_volumes = volumes , entrypoint = "/bin/bash -c " , env_vars = {}, command = f" '{ create_command } && { pack_command } '"
266
+ image = image ,
267
+ bind_volumes = volumes ,
268
+ entrypoint = "/bin/bash -c " ,
269
+ env_vars = {},
270
+ command = f" '{ create_command } && { pack_command } '" ,
245
271
)
246
272
else :
247
273
run_container (
248
- image = image , bind_volumes = volumes , env_vars = {}, command = create_command
249
- )
274
+ image = image ,
275
+ bind_volumes = volumes ,
276
+ env_vars = {},
277
+ command = create_command ,
278
+ )
250
279
except Exception :
251
280
if os .path .exists (pack_folder_path ):
252
281
shutil .rmtree (pack_folder_path )
@@ -517,9 +546,11 @@ def publish(**kwargs) -> None:
517
546
conda_pack_folder = exec_config ["conda_pack_folder" ],
518
547
gpu = exec_config .get ("gpu" , False ),
519
548
overwrite = exec_config ["overwrite" ],
520
- prepare_publish = True
549
+ prepare_publish = True ,
550
+ )
551
+ skip_archive = (
552
+ True # The conda pack archive is already created during create process.
521
553
)
522
- skip_archive = True # The conda pack archive is already created during create process.
523
554
else :
524
555
slug = exec_config .get ("slug" )
525
556
if not slug :
@@ -536,10 +567,10 @@ def publish(**kwargs) -> None:
536
567
oci_profile = exec_config .get ("oci_profile" ),
537
568
overwrite = exec_config ["overwrite" ],
538
569
auth_type = exec_config ["auth" ],
539
- skip_archive = skip_archive
570
+ skip_archive = skip_archive ,
540
571
)
541
572
542
-
573
+
543
574
def _publish (
544
575
conda_slug : str ,
545
576
conda_uri_prefix : str ,
@@ -548,7 +579,7 @@ def _publish(
548
579
oci_profile : str ,
549
580
overwrite : bool ,
550
581
auth_type : str ,
551
- skip_archive : bool = False
582
+ skip_archive : bool = False ,
552
583
) -> None :
553
584
"""Publish a local conda pack to object storage location
554
585
@@ -628,7 +659,11 @@ def _publish(
628
659
if is_in_notebook_session () or NO_CONTAINER :
629
660
# Set the CONDA_PUBLISH_TYPE environment variable so that the `type` attribute inside the manifest is not changed
630
661
command = f"CONDA_PUBLISH_TYPE={ os .environ .get ('CONDA_PUBLISH_TYPE' ,'' )} python { pack_script } --conda-path { pack_folder_path } "
631
- run_command (command , shell = True )
662
+ proc = run_command (command , shell = True )
663
+ if proc .returncode != 0 :
664
+ raise RuntimeError (
665
+ f"Failed to archive the conda environment. (exit code { proc .returncode } )"
666
+ )
632
667
else :
633
668
volumes = {
634
669
pack_folder_path : {
@@ -652,7 +687,9 @@ def _publish(
652
687
NOT_ALLOWED_CHARS = "@#$%^&*/"
653
688
654
689
if any (chr in conda_slug for chr in NOT_ALLOWED_CHARS ):
655
- raise ValueError (f"Invalid conda_slug. Found { NOT_ALLOWED_CHARS } in slug name. Please use a different slug name." )
690
+ raise ValueError (
691
+ f"Invalid conda_slug. Found { NOT_ALLOWED_CHARS } in slug name. Please use a different slug name."
692
+ )
656
693
pack_file = os .path .join (pack_folder_path , f"{ conda_slug } .tar.gz" )
657
694
if not os .path .exists (pack_file ):
658
695
raise RuntimeError (f"Pack { pack_file } was not created." )
0 commit comments