Skip to content

Fix: All python -m semver commands fail with 'error: invalid choice:' #393

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

Merged
merged 1 commit into from
Feb 22, 2023

Conversation

zanecodes
Copy link
Contributor

This was caused by __main__.py passing sys.argv to cli.main(), which includes the path of the script in sys.argv[0]. argparse.ArgumentParser.parse_args() parses this as the subcommand name, causing it to throw an error.

This could also be fixed by removing sys.argv entirely from the arguments passed to cli.main(), as argparse.ArgumentParser.parse_args() will use sys.argv[1:] by default.

I'm not sure if this change warrants an added test, as the existing tests cover cli.main() directly, but such a test would be reasonably straightforward to create and I can do so if you like.

This was caused by __main__.py passing `sys.argv` to `cli.main()`,
which includes the path of the script in `sys.argv[0]`.
`argparse.ArgumentParser.parse_args()` parses this as the subcommand
name, causing it to throw an error.
@tomschr
Copy link
Member

tomschr commented Feb 9, 2023

Thanks @zanecodes! This is great! 👍

You are right, this should be fixed.

I'm not sure if this change warrants an added test, as the existing tests cover cli.main() directly, but such a test would be reasonably straightforward to create and I can do so if you like.

Good question. I've looked in the file tests/test_pysemver-cli.py. There are a couple of tests that call main(), but nothing which tests this specific issue. If it's not too much of a hassle, I would like to integrate such a test in the test suite.

@tomschr tomschr added Bug Error, flaw or fault to produce incorrect or unexpected results Release_3.x.y Only for the major release 3 labels Feb 22, 2023
@tomschr
Copy link
Member

tomschr commented Feb 22, 2023

Hi @zanecodes,
I merge it nevertheless the missing test case. If you come up with a good test case, please create another PR.
Thank you!

@tomschr tomschr merged commit 7e062c8 into python-semver:master Feb 22, 2023
tomschr added a commit that referenced this pull request Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Error, flaw or fault to produce incorrect or unexpected results Release_3.x.y Only for the major release 3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy