fix: execute installed file scripts with poetry run - #11108
Closed
Mohamedajab wants to merge 3 commits into
Closed
Mohamedajab wants to merge 3 commits into
Mohamedajab wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/poetry/console/commands/run.py" line_range="74-75" />
<code_context>
self._warning_not_installed_script(args[0])
+ if is_file_script:
+ return self.env.execute(*args)
+
if isinstance(script, dict):
</code_context>
<issue_to_address>
**issue (bug_risk):** When a file script is declared but not installed, `run_script` emits the not-installed warning and then calls `self.env.execute(*args)` with the bare script name. That raises `FileNotFoundError` instead of returning the command-not-found error handled by `handle`, so `poetry run <file-script>` produces an uncaught exception.
**Triggers:** When the project has a `type = "file"` script but `poetry install` has not installed its target, or installation skipped the script because its reference is invalid.
**Suggested fix:** Handle the missing-installed-file case explicitly before calling `self.env.execute`, or route the execution through the same `FileNotFoundError` handling used for ordinary commands.
```suggestion
if is_file_script:
try:
return self.env.execute(*args)
except FileNotFoundError:
self.line_error(f"<error>Command not found: <c1>{args[0]}</c1></error>")
return 1
```
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: src/poetry/console/commands/run.py:75
Contributor
|
Explain why not #11092 |
sourcery-ai
Bot
dismissed
their stale review
September 30, 2026 21:13
Sourcery withdrew this approval because the latest commits introduced blocking findings.
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves: #11090
File scripts declared with
type = "file"were passed to the console-entry-point code path, which expects acallablefield and raisedKeyError. Detect file scripts before that conversion, preserve their installed name on Windows instead of adding a.cmdsuffix, and execute the installed file directly with its arguments.Tested with:
python -m pytest tests/console/commands/test_run.py -q(20 passed)pre-commit run --files src/poetry/console/commands/run.py tests/console/commands/test_run.pymypy src/poetry/console/commands/run.py tests/console/commands/test_run.py