-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(app): improve global opt and run cmd parsing #10067
base: main
Are you sure you want to change the base?
Conversation
Reviewer's Guide by SourceryThis pull request simplifies the argument parsing for the Sequence diagram for the new run command argument parsingsequenceDiagram
participant User
participant Application
participant ArgParser
participant IO
User->>Application: poetry run command
Application->>Application: _configure_io()
Application->>Application: _configure_run_command()
Application->>ArgParser: parse_known_args(tokens)
ArgParser-->>Application: parsed_args, remaining_args
Application->>IO: set_input(sorted_input)
Note over Application: Reorders tokens in format:<br/>pre_run + options + run + -- + subcommand
Flow diagram for run command argument processingflowchart TD
A[Start] --> B[Get command tokens]
B --> C{Has '--' separator?}
C -->|Yes| D[Skip processing]
C -->|No| E[Find run command index]
E --> F[Parse tokens before run]
F --> G[Extract subcommand]
G --> H[Reorder tokens]
H --> I[Create new input]
I --> J[End]
style C decision
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @abn - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟡 Testing: 1 issue found
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
aeb98fb
to
2a053a7
Compare
Thank you for tackling this bug – it's a really thorny issue. I'm still seeing a lot of problems, and provide detailed reproduction steps below. I don't fully understand what's going on, but hope that the test cases help. I think this means that any command line parameter munging based on heuristics like "there is a token called Reproduction stepsI tried to exhaustively check different styles of passing the #!/bin/bash
set -euo pipefail
poetry="${1:-poetry}"
workdir="$(mktemp -d)"
cd "$workdir"
"$poetry" new run # create a new package called "run"
ln -sT run somepackage
eza -aT # show directory structure
experiment() {
if "$@"; then
echo PASS: "$*"
else
echo FAIL: "$*"
# exit 1 # uncomment this line to turn into automated test
fi
}
# start experiments, ALL of these should just echo "hi"
for package in run somepackage; do
experiment env --chdir=$package "$poetry" run echo hi # test without -P/--project option
# option before "run" command
experiment "$poetry" -P $package run echo hi
experiment "$poetry" -P$package run echo hi
experiment "$poetry" --package $package run echo hi
experiment "$poetry" --package=$package run echo hi
# option after "run" command
experiment "$poetry" run -P $package echo hi
experiment "$poetry" run -P$package echo hi
experiment "$poetry" run --package $package echo hi
experiment "$poetry" run --package=$package echo hi
done
cd -
rm -r "$workdir" The Output of my tests:
As we can see, most of the invocation styles still fail. It is easier to enumerate what did work:
For the failures, some seem to truncate the package path to the first letter (before turning it into an absolute path):
Other failures seem to ignore the
On a few cases, the subcommand detection seems to fail:
I also repeated the test with Poetry 2.0.1, which passes 6 test cases, which is one more than in 9d9cf30. Specifically, the example |
I'll look into it. But quite honestly I'll be happy if things are better than it was, and we should be careful of optimizing for edge cases too much. :) |
@latk I am not sure what |
This change fixes an issue introduced in python-poetry#10021 that led to options provided in the form `-<shortcut><value>` to be incorrectly handled. Further, it also simplifies and fixes run command processing. Resolves: python-poetry#10051
@sourcery-ai review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @abn - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@latk thank you for detailing the issues you faced. Most of the issues you encountered where one of two things, @python-poetry/core I would like some eyes on this, as I had to do a first parse of the input tokens using argparse before cleo gets to process the inputs. There unfortunately were multiple issues that made global option retrieval unreliable. Hopefully this improves the status quo, particularly of the |
This change fixes an issue introduced in #10021 that led to options provided in the form
-<shortcut><value>
to be incorrectly handled.Further, it also simplifies and fixes run command processing.
Resolves: #10051
Using pipx
Using a container (podman | docker)
Summary by Sourcery
Bug Fixes: