@@ -151,7 +151,9 @@ def _create(
151151 conda_dep = yaml .safe_load (mfile .read ())
152152 # If manifest exists in the environment.yaml file, use that
153153 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+ )
155157 pack_folder_path = os .path .join (
156158 os .path .abspath (os .path .expanduser (conda_pack_folder )), slug
157159 )
@@ -176,9 +178,11 @@ def _create(
176178
177179 os .makedirs (pack_folder_path , exist_ok = True )
178180
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+ )
180184 manifest = _fetch_manifest_template ()
181- if not "name" in conda_dep [ " manifest" ] :
185+ if not "name" in manifest :
182186 manifest ["manifest" ]["name" ] = name
183187 manifest ["manifest" ]["slug" ] = slug
184188 if not "type" in conda_dep ["manifest" ]:
@@ -196,7 +200,13 @@ def _create(
196200 manifest ["manifest" ]["manifest_version" ] = "1.0"
197201
198202 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+ )
200210 logger .info (f"Updated conda environment manifest: { conda_dep .get ('manifest' )} " )
201211
202212 if is_in_notebook_session () or NO_CONTAINER :
@@ -210,13 +220,12 @@ def _create(
210220 )
211221
212222 create_command = f"conda env create --prefix { docker_pack_folder_path } --file { docker_env_file_path } "
213-
223+
214224 volumes = {
215225 pack_folder_path : {"bind" : docker_pack_folder_path },
216226 os .path .abspath (os .path .expanduser (env_file )): {
217227 "bind" : docker_env_file_path
218228 },
219-
220229 }
221230
222231 if gpu :
@@ -227,26 +236,42 @@ def _create(
227236 if prepare_publish :
228237 tmp_file = tempfile .NamedTemporaryFile (suffix = ".yaml" )
229238 # 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 )
232241
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+ )
234245 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' )} "
235246
236247 # add pack script and manifest file to the mount so that archive can be created in the same container run
237248 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+ },
240255 }
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
242260
243261 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 } '" ,
245267 )
246268 else :
247269 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+ )
250275 except Exception :
251276 if os .path .exists (pack_folder_path ):
252277 shutil .rmtree (pack_folder_path )
@@ -517,9 +542,11 @@ def publish(**kwargs) -> None:
517542 conda_pack_folder = exec_config ["conda_pack_folder" ],
518543 gpu = exec_config .get ("gpu" , False ),
519544 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.
521549 )
522- skip_archive = True # The conda pack archive is already created during create process.
523550 else :
524551 slug = exec_config .get ("slug" )
525552 if not slug :
@@ -536,10 +563,10 @@ def publish(**kwargs) -> None:
536563 oci_profile = exec_config .get ("oci_profile" ),
537564 overwrite = exec_config ["overwrite" ],
538565 auth_type = exec_config ["auth" ],
539- skip_archive = skip_archive
566+ skip_archive = skip_archive ,
540567 )
541568
542-
569+
543570def _publish (
544571 conda_slug : str ,
545572 conda_uri_prefix : str ,
@@ -548,7 +575,7 @@ def _publish(
548575 oci_profile : str ,
549576 overwrite : bool ,
550577 auth_type : str ,
551- skip_archive : bool = False
578+ skip_archive : bool = False ,
552579) -> None :
553580 """Publish a local conda pack to object storage location
554581
@@ -627,7 +654,10 @@ def _publish(
627654 if not skip_archive :
628655 if is_in_notebook_session () or NO_CONTAINER :
629656 # 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 } "
631661 run_command (command , shell = True )
632662 else :
633663 volumes = {
@@ -652,7 +682,9 @@ def _publish(
652682 NOT_ALLOWED_CHARS = "@#$%^&*/"
653683
654684 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+ )
656688 pack_file = os .path .join (pack_folder_path , f"{ conda_slug } .tar.gz" )
657689 if not os .path .exists (pack_file ):
658690 raise RuntimeError (f"Pack { pack_file } was not created." )
0 commit comments