Skip to content

Commit 2d3920d

Browse files
mnriemCopilot
andcommitted
fix: build argv flags before early returns, use any() for dir scan
- Move argv flag-building (--integration, --script, --preset, --ignore-agent-tools) before the non-empty-dir and OSError early returns so output['argv'] always reflects the complete command. - --force is appended after the check since it may be set implicitly. - Replace list comprehension with any() generator expression to short-circuit without allocating a full list of DirEntry objects. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e8857ca commit 2d3920d

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

src/specify_cli/workflows/steps/init/__init__.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ def execute(self, config: dict[str, Any], context: StepContext) -> StepResult:
103103
# No explicit target → initialize the current directory.
104104
argv.append(".")
105105

106+
# Build the full argv (except --force, which may be set implicitly
107+
# below) so early-return outputs always reflect the complete command.
108+
if integration:
109+
argv.extend(["--integration", str(integration)])
110+
if integration_options:
111+
argv.extend(["--integration-options", str(integration_options)])
112+
if script:
113+
argv.extend(["--script", str(script)])
114+
if preset:
115+
argv.extend(["--preset", str(preset)])
116+
if ignore_agent_tools:
117+
argv.append("--ignore-agent-tools")
118+
106119
# When the target is the current directory and ``force`` is not set,
107120
# ``specify init`` prompts for confirmation if the directory is not
108121
# empty. Workflows run unattended (no stdin), so the prompt would
@@ -115,10 +128,9 @@ def execute(self, config: dict[str, Any], context: StepContext) -> StepResult:
115128
base = context.project_root or os.getcwd()
116129
try:
117130
with os.scandir(base) as it:
118-
non_engine_entries = [
119-
entry for entry in it
120-
if entry.name not in _ENGINE_OWNED_DIRS
121-
]
131+
has_non_engine_content = any(
132+
entry.name not in _ENGINE_OWNED_DIRS for entry in it
133+
)
122134
except OSError as exc:
123135
error_message = (
124136
f"Cannot inspect target directory {base!r}: {exc}"
@@ -141,7 +153,7 @@ def execute(self, config: dict[str, Any], context: StepContext) -> StepResult:
141153
},
142154
error=error_message,
143155
)
144-
if non_engine_entries:
156+
if has_non_engine_content:
145157
error_message = (
146158
f"Target directory {base!r} is not empty. Set "
147159
"'force: true' to merge into a non-empty directory."
@@ -169,18 +181,8 @@ def execute(self, config: dict[str, Any], context: StepContext) -> StepResult:
169181
# init doesn't prompt about the non-empty directory.
170182
force = True
171183

172-
if integration:
173-
argv.extend(["--integration", str(integration)])
174-
if integration_options:
175-
argv.extend(["--integration-options", str(integration_options)])
176-
if script:
177-
argv.extend(["--script", str(script)])
178-
if preset:
179-
argv.extend(["--preset", str(preset)])
180184
if force:
181185
argv.append("--force")
182-
if ignore_agent_tools:
183-
argv.append("--ignore-agent-tools")
184186

185187
exit_code, stdout, stderr = self._run_init(argv, context)
186188

0 commit comments

Comments
 (0)