Skip to content

Commit d5b9d6e

Browse files
authored
Move _re/_sys imports out of loop and _RESERVED_STEP_IDS to module level
1 parent 8e254b4 commit d5b9d6e

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/specify_cli/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5933,6 +5933,11 @@ def workflow_step_list():
59335933
)
59345934

59355935

5936+
# IDs that map to internal names used under .specify/workflows/steps/ and must
5937+
# not be used as custom step IDs (dotfile check is done separately at runtime).
5938+
_RESERVED_STEP_IDS: frozenset[str] = frozenset({".cache", "step-registry.json"})
5939+
5940+
59365941
@workflow_step_app.command("add")
59375942
def workflow_step_add(
59385943
step_id: str = typer.Argument(..., help="Step type ID from catalog"),
@@ -6033,7 +6038,6 @@ def _safe_fetch(url: str) -> bytes:
60336038
# Reject IDs that collide with internal names used under steps_base_dir
60346039
# (dotfiles, the cache dir, and the registry filename) to prevent
60356040
# corrupting caching or registry persistence.
6036-
_RESERVED_STEP_IDS = {".cache", "step-registry.json"}
60376041
if step_id.startswith(".") or step_id in _RESERVED_STEP_IDS:
60386042
console.print(
60396043
f"[red]Error:[/red] '{step_id}' is a reserved name and cannot be used as a step ID"

src/specify_cli/workflows/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def load_custom_steps(project_root: Path) -> list[str]:
8181
Silently skips packages that fail to import or validate.
8282
"""
8383
import importlib.util as _importlib_util
84+
import re as _re
85+
import sys as _sys
8486

8587
steps_dir = Path(project_root) / ".specify" / "workflows" / "steps"
8688
if not steps_dir.is_dir():
@@ -108,9 +110,6 @@ def load_custom_steps(project_root: Path) -> list[str]:
108110
if type_key in STEP_REGISTRY:
109111
continue
110112

111-
import re as _re
112-
import sys as _sys
113-
114113
# Sanitize type_key so the synthetic module name is a valid identifier
115114
# (e.g. "test-custom" → "_speckit_custom_step_test_custom").
116115
safe_key = _re.sub(r"[^A-Za-z0-9_]", "_", type_key)

0 commit comments

Comments
 (0)