@@ -261,33 +261,34 @@ def artifact_to_python_content_data(filename, artifact, domain=None):
261261 return data
262262
263263
264- def artifact_to_metadata_artifact (filename : str , artifact : Artifact ) -> Artifact | None :
264+ def artifact_to_metadata_artifact (
265+ filename : str , artifact : Artifact , tmp_dir : str = "."
266+ ) -> Artifact | None :
265267 """
266268 Creates artifact for metadata from the provided wheel artifact.
267269 """
268270 if not filename .endswith (".whl" ):
269271 return None
270272
271- with tempfile .TemporaryDirectory (dir = settings .WORKING_DIRECTORY ) as temp_dir_name :
272- with tempfile .NamedTemporaryFile (dir = temp_dir_name , suffix = filename ) as temp_file :
273- artifact .file .seek (0 )
274- shutil .copyfileobj (artifact .file , temp_file )
275- temp_file .flush ()
276- metadata_content = extract_wheel_metadata (temp_file .name )
277- if not metadata_content :
278- return None
279-
280- with tempfile .NamedTemporaryFile (dir = temp_dir_name , suffix = ".metadata" ) as temp_md :
281- temp_md .write (metadata_content )
282- temp_md .flush ()
283- metadata_artifact = Artifact .init_and_validate (temp_md .name )
284- try :
285- metadata_artifact .save ()
286- except IntegrityError :
287- metadata_artifact = Artifact .objects .get (
288- sha256 = metadata_artifact .sha256 , pulp_domain = get_domain ()
289- )
290- return metadata_artifact
273+ with tempfile .NamedTemporaryFile ("wb" , dir = tmp_dir , suffix = filename ) as temp_file :
274+ artifact .file .seek (0 )
275+ shutil .copyfileobj (artifact .file , temp_file )
276+ temp_file .flush ()
277+ metadata_content = extract_wheel_metadata (temp_file .name )
278+ if not metadata_content :
279+ return None
280+
281+ with tempfile .NamedTemporaryFile ("wb" , dir = tmp_dir , suffix = ".metadata" ) as temp_md :
282+ temp_md .write (metadata_content )
283+ temp_md .flush ()
284+ metadata_artifact = Artifact .init_and_validate (temp_md .name )
285+ try :
286+ metadata_artifact .save ()
287+ except IntegrityError :
288+ metadata_artifact = Artifact .objects .get (
289+ sha256 = metadata_artifact .sha256 , pulp_domain = get_domain ()
290+ )
291+ return metadata_artifact
291292
292293
293294def fetch_json_release_metadata (name : str , version : str , remotes : set [Remote ]) -> dict :
0 commit comments