Skip to content

Commit d00509e

Browse files
Copilotmnriem
andauthored
Fix IOError messages, close tf.extractfile() handles, mention .tgz in error messages
Agent-Logs-Url: https://github.com/github/spec-kit/sessions/891dfd6f-0f75-4522-bcd2-8a6fffb2d5f7 Co-authored-by: mnriem <15701806+mnriem@users.noreply.github.com>
1 parent c44cc24 commit d00509e

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/specify_cli/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,7 +2645,7 @@ def preset_add(
26452645

26462646
if not archive_fmt:
26472647
console.print("[red]Error:[/red] Could not determine archive format from URL or Content-Type.")
2648-
console.print("Ensure the URL points to a .zip or .tar.gz file.")
2648+
console.print("Ensure the URL points to a .zip or .tar.gz/.tgz file.")
26492649
raise typer.Exit(1)
26502650

26512651
suffix = ".tar.gz" if archive_fmt == "tar.gz" else ".zip"
@@ -3659,7 +3659,7 @@ def extension_add(
36593659

36603660
if not archive_fmt:
36613661
console.print("[red]Error:[/red] Could not determine archive format from URL or Content-Type.")
3662-
console.print("Ensure the URL points to a .zip or .tar.gz file.")
3662+
console.print("Ensure the URL points to a .zip or .tar.gz/.tgz file.")
36633663
raise typer.Exit(1)
36643664

36653665
suffix = ".tar.gz" if archive_fmt == "tar.gz" else ".zip"
@@ -4343,14 +4343,16 @@ def extension_update(
43434343
m = tf.getmember("extension.yml")
43444344
f = tf.extractfile(m)
43454345
if f is not None:
4346-
manifest_data = yaml.safe_load(f.read()) or {}
4346+
with f:
4347+
manifest_data = yaml.safe_load(f.read()) or {}
43474348
except KeyError:
43484349
# Look for extension.yml in a single top-level subdirectory
43494350
members = [m for m in tf.getmembers() if m.name.endswith("/extension.yml") and m.name.count("/") == 1]
43504351
if len(members) == 1:
43514352
f = tf.extractfile(members[0])
43524353
if f is not None:
4353-
manifest_data = yaml.safe_load(f.read()) or {}
4354+
with f:
4355+
manifest_data = yaml.safe_load(f.read()) or {}
43544356
else:
43554357
with zipfile.ZipFile(zip_path, "r") as zf:
43564358
namelist = zf.namelist()
@@ -4944,7 +4946,8 @@ def _extract_workflow_yml(archive_path: Path, archive_fmt: str) -> bytes:
49444946
try:
49454947
f = tf.extractfile(tf.getmember("workflow.yml"))
49464948
if f is not None:
4947-
return f.read()
4949+
with f:
4950+
return f.read()
49484951
except KeyError:
49494952
pass # Root-level workflow.yml not found; fall through to subdirectory search below.
49504953
# Look in a single top-level subdirectory.
@@ -4955,7 +4958,8 @@ def _extract_workflow_yml(archive_path: Path, archive_fmt: str) -> bytes:
49554958
if len(candidates) == 1:
49564959
f = tf.extractfile(candidates[0])
49574960
if f is not None:
4958-
return f.read()
4961+
with f:
4962+
return f.read()
49594963
else:
49604964
with zipfile.ZipFile(archive_path, "r") as zf:
49614965
namelist = zf.namelist()

src/specify_cli/extensions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,13 +2148,13 @@ def download_extension(self, extension_id: str, target_dir: Optional[Path] = Non
21482148
except urllib.error.URLError as e:
21492149
raise ExtensionError(f"Failed to download extension from {download_url}: {e}")
21502150
except IOError as e:
2151-
raise ExtensionError(f"Failed to save extension archive: {e}")
2151+
raise ExtensionError(f"Failed to read extension archive from {download_url}: {e}")
21522152

21532153
# Choose file extension based on detected format.
21542154
if not archive_fmt:
21552155
raise ExtensionError(
21562156
f"Could not determine archive format for {download_url}. "
2157-
"Ensure the URL points to a .zip or .tar.gz file."
2157+
"Ensure the URL points to a .zip or .tar.gz/.tgz file."
21582158
)
21592159
if archive_fmt == "tar.gz":
21602160
archive_filename = f"{extension_id}-{version}.tar.gz"

src/specify_cli/presets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,13 +2328,13 @@ def download_pack(
23282328
f"Failed to download preset from {download_url}: {e}"
23292329
)
23302330
except IOError as e:
2331-
raise PresetError(f"Failed to save preset archive: {e}")
2331+
raise PresetError(f"Failed to read preset archive from {download_url}: {e}")
23322332

23332333
# Choose file extension based on detected format.
23342334
if not archive_fmt:
23352335
raise PresetError(
23362336
f"Could not determine archive format for {download_url}. "
2337-
"Ensure the URL points to a .zip or .tar.gz file."
2337+
"Ensure the URL points to a .zip or .tar.gz/.tgz file."
23382338
)
23392339
if archive_fmt == "tar.gz":
23402340
archive_filename = f"{pack_id}-{version}.tar.gz"

0 commit comments

Comments
 (0)