fix(main): use package name instead of __main__.py in usage output - #690
Open
jlaportebot wants to merge 1 commit into
Open
fix(main): use package name instead of __main__.py in usage output#690jlaportebot wants to merge 1 commit into
jlaportebot wants to merge 1 commit into
Conversation
When running a package with 'python -m mypackage', sys.argv[0] points to mypackage/__main__.py. Previously this caused the usage/help output to show '__main__.py' as the command name instead of the actual package name. This fix extracts the package name from the parent directory when the script name is '__main__.py', applied in both fire/__main__.py (for python -m fire) and fire/core.py (for fire.Fire() calls).
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.
Summary
When running a package with
python -m mypackage,sys.argv[0]points tomypackage/__main__.py. Previously this caused the usage/help output to show__main__.pyas the command name instead of the actual package name.Changes
This fix extracts the package name from the parent directory when the script name is
__main__.py, applied in two places:python -m fire /path/to/pkg/__main__.pyfire.Fire()directly in a__main__.pyfileTesting
python -m fire /tmp/testpkg/__main__.pynow showstestpkginstead of__main__.pypython -m testpkg(with fire.Fire() inside) now showstestpkgin usage/helpRelated Issue
Fixes #76: "Use package name when main.py is used"