Skip to content

Commit d78ead1

Browse files
Copilotmnriem
andauthored
Remove unnecessary import aliases, use consistent names
Agent-Logs-Url: https://github.com/github/spec-kit/sessions/9fb9a8ea-0967-4baf-b95c-7101e423ff58 Co-authored-by: mnriem <15701806+mnriem@users.noreply.github.com>
1 parent b3a60f5 commit d78ead1

1 file changed

Lines changed: 20 additions & 22 deletions

File tree

src/specify_cli/__init__.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4320,14 +4320,14 @@ def extension_update(
43204320
try:
43214321
# 6. Validate extension ID from archive BEFORE modifying installation
43224322
# Handle both root-level and nested extension.yml (GitHub auto-generated archives)
4323-
from .extensions import _detect_archive_format as _ext_det_fmt
4324-
import tarfile as _tarfile
4325-
archive_fmt = _ext_det_fmt(str(zip_path))
4323+
from .extensions import _detect_archive_format
4324+
import tarfile
4325+
archive_fmt = _detect_archive_format(str(zip_path))
43264326
import yaml
43274327
manifest_data = None
43284328

43294329
if archive_fmt == "tar.gz":
4330-
with _tarfile.open(zip_path, "r:gz") as tf:
4330+
with tarfile.open(zip_path, "r:gz") as tf:
43314331
# First try root-level extension.yml
43324332
try:
43334333
m = tf.getmember("extension.yml")
@@ -4906,7 +4906,7 @@ def workflow_list():
49064906
console.print()
49074907

49084908

4909-
def _wf_extract_workflow_yml(archive_path: Path, archive_fmt: str) -> bytes:
4909+
def _extract_workflow_yml(archive_path: Path, archive_fmt: str) -> bytes:
49104910
"""Extract ``workflow.yml`` from a ZIP or ``.tar.gz`` archive.
49114911
49124912
Searches the archive root and a single nested top-level subdirectory
@@ -4922,11 +4922,10 @@ def _wf_extract_workflow_yml(archive_path: Path, archive_fmt: str) -> bytes:
49224922
Raises:
49234923
ValueError: If no ``workflow.yml`` is found in the archive.
49244924
"""
4925-
import tarfile as _tf
4926-
import zipfile as _zf
4925+
import tarfile
49274926

49284927
if archive_fmt == "tar.gz":
4929-
with _tf.open(archive_path, "r:gz") as tf:
4928+
with tarfile.open(archive_path, "r:gz") as tf:
49304929
# Try root-level first.
49314930
try:
49324931
return tf.extractfile(tf.getmember("workflow.yml")).read()
@@ -4940,7 +4939,7 @@ def _wf_extract_workflow_yml(archive_path: Path, archive_fmt: str) -> bytes:
49404939
if len(candidates) == 1:
49414940
return tf.extractfile(candidates[0]).read()
49424941
else:
4943-
with _zf.ZipFile(archive_path, "r") as zf:
4942+
with zipfile.ZipFile(archive_path, "r") as zf:
49444943
namelist = zf.namelist()
49454944
if "workflow.yml" in namelist:
49464945
return zf.read("workflow.yml")
@@ -5007,7 +5006,7 @@ def _validate_and_install_local(yaml_path: Path, source_label: str) -> None:
50075006
from ipaddress import ip_address
50085007
from urllib.parse import urlparse
50095008
from urllib.request import urlopen # noqa: S310
5010-
from .extensions import _detect_archive_format as _wf_det_fmt
5009+
from .extensions import _detect_archive_format
50115010

50125011
parsed_src = urlparse(source)
50135012
src_host = parsed_src.hostname or ""
@@ -5040,10 +5039,10 @@ def _validate_and_install_local(yaml_path: Path, source_label: str) -> None:
50405039
raise typer.Exit(1)
50415040

50425041
# Detect archive format from the final URL or Content-Type header.
5043-
archive_fmt = _wf_det_fmt(final_url)
5042+
archive_fmt = _detect_archive_format(final_url)
50445043
if not archive_fmt:
50455044
content_type = resp.headers.get("Content-Type", "")
5046-
archive_fmt = _wf_det_fmt(final_url, content_type)
5045+
archive_fmt = _detect_archive_format(final_url, content_type)
50475046

50485047
raw_data = resp.read()
50495048
except typer.Exit:
@@ -5061,7 +5060,7 @@ def _validate_and_install_local(yaml_path: Path, source_label: str) -> None:
50615060
arc_tmp.write(raw_data)
50625061
arc_tmp_path = Path(arc_tmp.name)
50635062
try:
5064-
wf_yaml = _wf_extract_workflow_yml(arc_tmp_path, archive_fmt)
5063+
wf_yaml = _extract_workflow_yml(arc_tmp_path, archive_fmt)
50655064
with tempfile.NamedTemporaryFile(suffix=".yml", delete=False) as tmp:
50665065
tmp.write(wf_yaml)
50675066
tmp_path = Path(tmp.name)
@@ -5095,10 +5094,10 @@ def _validate_and_install_local(yaml_path: Path, source_label: str) -> None:
50955094
source.endswith(".tar.gz") or source.endswith(".tgz") or source.endswith(".zip")
50965095
):
50975096
# Local archive file containing workflow.yml
5098-
from .extensions import _detect_archive_format as _wf_local_fmt
5099-
local_fmt = _wf_local_fmt(source)
5097+
from .extensions import _detect_archive_format
5098+
local_fmt = _detect_archive_format(source)
51005099
try:
5101-
wf_yaml = _wf_extract_workflow_yml(source_path, local_fmt)
5100+
wf_yaml = _extract_workflow_yml(source_path, local_fmt)
51025101
except (ValueError, Exception) as exc:
51035102
console.print(f"[red]Error:[/red] Failed to extract workflow from archive: {exc}")
51045103
raise typer.Exit(1)
@@ -5174,8 +5173,7 @@ def _validate_and_install_local(yaml_path: Path, source_label: str) -> None:
51745173

51755174
try:
51765175
from urllib.request import urlopen # noqa: S310 — URL comes from catalog
5177-
from .extensions import _detect_archive_format as _wf_cat_fmt
5178-
import tempfile as _wf_tmpmod
5176+
from .extensions import _detect_archive_format
51795177

51805178
workflow_dir.mkdir(parents=True, exist_ok=True)
51815179
with urlopen(workflow_url, timeout=30) as response: # noqa: S310
@@ -5200,21 +5198,21 @@ def _validate_and_install_local(yaml_path: Path, source_label: str) -> None:
52005198
raise typer.Exit(1)
52015199

52025200
# Detect archive format from the final URL or Content-Type header.
5203-
cat_archive_fmt = _wf_cat_fmt(final_url)
5201+
cat_archive_fmt = _detect_archive_format(final_url)
52045202
if not cat_archive_fmt:
52055203
cat_ct = response.headers.get("Content-Type", "")
5206-
cat_archive_fmt = _wf_cat_fmt(final_url, cat_ct)
5204+
cat_archive_fmt = _detect_archive_format(final_url, cat_ct)
52075205

52085206
raw_response = response.read()
52095207

52105208
if cat_archive_fmt in ("tar.gz", "zip"):
52115209
# Download URL points to an archive — extract workflow.yml from it.
52125210
suffix = ".tar.gz" if cat_archive_fmt == "tar.gz" else ".zip"
5213-
with _wf_tmpmod.NamedTemporaryFile(suffix=suffix, delete=False) as arc_f:
5211+
with tempfile.NamedTemporaryFile(suffix=suffix, delete=False) as arc_f:
52145212
arc_f.write(raw_response)
52155213
arc_tmp = Path(arc_f.name)
52165214
try:
5217-
wf_yaml_bytes = _wf_extract_workflow_yml(arc_tmp, cat_archive_fmt)
5215+
wf_yaml_bytes = _extract_workflow_yml(arc_tmp, cat_archive_fmt)
52185216
finally:
52195217
arc_tmp.unlink(missing_ok=True)
52205218
workflow_file.write_bytes(wf_yaml_bytes)

0 commit comments

Comments
 (0)