Skip to content

fix(main): use package name instead of __main__.py in usage output - #690

Open
jlaportebot wants to merge 1 commit into
google:masterfrom
jlaportebot:fix/main-py-name-display
Open

fix(main): use package name instead of __main__.py in usage output#690
jlaportebot wants to merge 1 commit into
google:masterfrom
jlaportebot:fix/main-py-name-display

Conversation

@jlaportebot

Copy link
Copy Markdown

Summary

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.

Changes

This fix extracts the package name from the parent directory when the script name is __main__.py, applied in two places:

  1. fire/main.py (line 59-62): When importing a file path for python -m fire /path/to/pkg/__main__.py
  2. fire/core.py (line 107-110): When using fire.Fire() directly in a __main__.py file

Testing

  • All 261 existing tests pass
  • Manual testing confirms:
    • python -m fire /tmp/testpkg/__main__.py now shows testpkg instead of __main__.py
    • python -m testpkg (with fire.Fire() inside) now shows testpkg in usage/help

Related Issue

Fixes #76: "Use package name when main.py is used"

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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use package name when __main__.py is used

1 participant