Skip to content

Commit 2a23433

Browse files
committed
Use pathlib module to work with workflow artifact archive paths
The sketches report workflow artifact is downloaded to a temporary folder and extracted. This requires working with paths. The pathlib module provides convenient and safe path handling and so should be used whenever there is significant involvement of paths in code.
1 parent 7a207ae commit 2a23433

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

reportsizedeltas/reportsizedeltas.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -267,17 +267,18 @@ def get_artifact(self, artifact_data):
267267
"""
268268
# Create temporary folder
269269
artifact_folder_object = tempfile.TemporaryDirectory(prefix="reportsizedeltas-")
270+
artifact_folder_path = pathlib.Path(artifact_folder_object.name)
270271
try:
271-
artifact_zip_file = artifact_folder_object.name + "/" + artifact_data["name"] + ".zip"
272+
artifact_zip_file_path = artifact_folder_path.joinpath(artifact_data["name"] + ".zip")
272273
# Download artifact
273-
with open(file=artifact_zip_file, mode="wb") as out_file:
274+
with artifact_zip_file_path.open(mode="wb") as out_file:
274275
with self.raw_http_request(url=artifact_data["archive_download_url"]) as fp:
275276
out_file.write(fp.read())
276277

277278
# Unzip artifact
278-
with zipfile.ZipFile(file=artifact_zip_file, mode="r") as zip_ref:
279-
zip_ref.extractall(path=artifact_folder_object.name)
280-
os.remove(artifact_zip_file)
279+
with zipfile.ZipFile(file=artifact_zip_file_path, mode="r") as zip_ref:
280+
zip_ref.extractall(path=artifact_folder_path)
281+
artifact_zip_file_path.unlink()
281282

282283
return artifact_folder_object
283284

0 commit comments

Comments
 (0)