@@ -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,9 +178,11 @@ 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
- if not "name" in conda_dep [ " manifest" ] :
185
+ if not "name" in manifest :
182
186
manifest ["manifest" ]["name" ] = name
183
187
manifest ["manifest" ]["slug" ] = slug
184
188
if not "type" in conda_dep ["manifest" ]:
@@ -196,7 +200,13 @@ 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 :
@@ -210,13 +220,12 @@ def _create(
210
220
)
211
221
212
222
create_command = f"conda env create --prefix { docker_pack_folder_path } --file { docker_env_file_path } "
213
-
223
+
214
224
volumes = {
215
225
pack_folder_path : {"bind" : docker_pack_folder_path },
216
226
os .path .abspath (os .path .expanduser (env_file )): {
217
227
"bind" : docker_env_file_path
218
228
},
219
-
220
229
}
221
230
222
231
if gpu :
@@ -227,26 +236,42 @@ def _create(
227
236
if prepare_publish :
228
237
tmp_file = tempfile .NamedTemporaryFile (suffix = ".yaml" )
229
238
# 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 )
239
+ with open (tmp_file .name , "w" ) as f :
240
+ yaml .safe_dump (conda_dep , f )
232
241
233
- pack_script = os .path .join (os .path .dirname (os .path .abspath (__file__ )), "pack.py" )
242
+ pack_script = os .path .join (
243
+ os .path .dirname (os .path .abspath (__file__ )), "pack.py"
244
+ )
234
245
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
246
236
247
# add pack script and manifest file to the mount so that archive can be created in the same container run
237
248
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" )}
249
+ pack_script : {
250
+ "bind" : os .path .join (DEFAULT_IMAGE_HOME_DIR , "pack.py" )
251
+ },
252
+ tmp_file .name : {
253
+ "bind" : os .path .join (DEFAULT_IMAGE_HOME_DIR , "manifest.yaml" )
254
+ },
240
255
}
241
- volumes = {** volumes , ** condapack_script } # | not supported in python 3.8
256
+ volumes = {
257
+ ** volumes ,
258
+ ** condapack_script ,
259
+ } # | not supported in python 3.8
242
260
243
261
run_container (
244
- image = image , bind_volumes = volumes , entrypoint = "/bin/bash -c " , env_vars = {}, command = f" '{ create_command } && { pack_command } '"
262
+ image = image ,
263
+ bind_volumes = volumes ,
264
+ entrypoint = "/bin/bash -c " ,
265
+ env_vars = {},
266
+ command = f" '{ create_command } && { pack_command } '" ,
245
267
)
246
268
else :
247
269
run_container (
248
- image = image , bind_volumes = volumes , env_vars = {}, command = create_command
249
- )
270
+ image = image ,
271
+ bind_volumes = volumes ,
272
+ env_vars = {},
273
+ command = create_command ,
274
+ )
250
275
except Exception :
251
276
if os .path .exists (pack_folder_path ):
252
277
shutil .rmtree (pack_folder_path )
@@ -517,9 +542,11 @@ def publish(**kwargs) -> None:
517
542
conda_pack_folder = exec_config ["conda_pack_folder" ],
518
543
gpu = exec_config .get ("gpu" , False ),
519
544
overwrite = exec_config ["overwrite" ],
520
- prepare_publish = True
545
+ prepare_publish = True ,
546
+ )
547
+ skip_archive = (
548
+ True # The conda pack archive is already created during create process.
521
549
)
522
- skip_archive = True # The conda pack archive is already created during create process.
523
550
else :
524
551
slug = exec_config .get ("slug" )
525
552
if not slug :
@@ -536,10 +563,10 @@ def publish(**kwargs) -> None:
536
563
oci_profile = exec_config .get ("oci_profile" ),
537
564
overwrite = exec_config ["overwrite" ],
538
565
auth_type = exec_config ["auth" ],
539
- skip_archive = skip_archive
566
+ skip_archive = skip_archive ,
540
567
)
541
568
542
-
569
+
543
570
def _publish (
544
571
conda_slug : str ,
545
572
conda_uri_prefix : str ,
@@ -548,7 +575,7 @@ def _publish(
548
575
oci_profile : str ,
549
576
overwrite : bool ,
550
577
auth_type : str ,
551
- skip_archive : bool = False
578
+ skip_archive : bool = False ,
552
579
) -> None :
553
580
"""Publish a local conda pack to object storage location
554
581
@@ -627,7 +654,10 @@ def _publish(
627
654
if not skip_archive :
628
655
if is_in_notebook_session () or NO_CONTAINER :
629
656
# Set the CONDA_PUBLISH_TYPE environment variable so that the `type` attribute inside the manifest is not changed
630
- command = f"CONDA_PUBLISH_TYPE={ os .environ .get ('CONDA_PUBLISH_TYPE' ,'' )} python { pack_script } --conda-path { pack_folder_path } "
657
+ publish_type = os .environ .get ("CONDA_PUBLISH_TYPE" )
658
+ command = "python {pack_script} --conda-path {pack_folder_path}"
659
+ if publish_type :
660
+ command = f"CONDA_PUBLISH_TYPE={ publish_type } { command } "
631
661
run_command (command , shell = True )
632
662
else :
633
663
volumes = {
@@ -652,7 +682,9 @@ def _publish(
652
682
NOT_ALLOWED_CHARS = "@#$%^&*/"
653
683
654
684
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." )
685
+ raise ValueError (
686
+ f"Invalid conda_slug. Found { NOT_ALLOWED_CHARS } in slug name. Please use a different slug name."
687
+ )
656
688
pack_file = os .path .join (pack_folder_path , f"{ conda_slug } .tar.gz" )
657
689
if not os .path .exists (pack_file ):
658
690
raise RuntimeError (f"Pack { pack_file } was not created." )
0 commit comments