GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-66436: Improved prog default value for argparse.ArgumentParser by serhiy-storchaka · Pull Request #124799 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Sep 30, 2024 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

It can now have one of three forms:

  • basename(argv0) -- for simple scripts
  • python arv0 -- for directories, ZIP files, etc
  • python -m module -- for imported modules
  • Issue: argparse support for "python -m module" in help #66436

📚 Documentation preview 📚: https://cpython-previews--124799.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka
serhiy-storchaka requested a review from ncoghlan September 30, 2024 19:32
@serhiy-storchaka
serhiy-storchaka requested review from brettcannon, ericsnowcurrently and warsaw as code owners September 30, 2024 19:33
@bedevere-app bedevere-app Bot added the awaiting core review label Sep 30, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Sep 30, 2024
argparse support for "python -m module" in help #66436
Closed
@serhiy-storchaka
pythongh-66436: Improved prog default value for argparse.ArgumentParser
1977630
It can now have one of three forms:

* basename(argv0) -- for simple scripts
* python arv0 -- for directories, ZIP files, etc
* python -m module -- for imported modules
@serhiy-storchaka
serhiy-storchaka force-pushed the argparse-default-prog-name branch from 5ba9a91 to 1977630 Compare September 30, 2024 19:52
serhiy-storchaka
serhiy-storchaka commented Sep 30, 2024
View reviewed changes
Comment thread Lib/argparse.py Outdated
Comment on lines +1708 to +1709
if (modspec.name == '__main__' and not modspec.parent and modspec.has_location
and _os.path.dirname(modspec.origin) == _os.path.join(_os.getcwd(), arg0)):

@serhiy-storchaka serhiy-storchaka Sep 30, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

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.

Actually, it seems that this condition can be simplified to simply modspec.name == '__main__'. What are your thoughts @ncoghlan?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@serhiy-storchaka serhiy-storchaka Oct 1, 2024

Copy link
Copy Markdown
Member Author

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.

Actually, additionally checks were just an obstacle, because of differences in normalization between Unix and Windows. So I removed them.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
serhiy-storchaka added 5 commits October 1, 2024 09:09
@serhiy-storchaka
Fix encoding/decoding errors on Windows.
58cbd64
@serhiy-storchaka
Simplify the the code and fix the directory test on Windows.
291b6cf
@serhiy-storchaka
Fix test_calendar.
93c7a80
@serhiy-storchaka
Try to fix test_parent_help on CI.
0b72da9
@serhiy-storchaka
Fix test_embed.
5f62bbd
ncoghlan
ncoghlan approved these changes Oct 1, 2024
View reviewed changes

@ncoghlan ncoghlan left a comment

Copy link
Copy Markdown
Contributor

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.

LGTM! Assorted minor comments inline, either tweaking docs wording, or else making the code handle obscure edge cases more gracefully.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/argparse.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/argparse.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/argparse.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/argparse.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/argparse.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/whatsnew/3.14.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/argparse.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/argparse.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Misc/NEWS.d/next/Library/2024-09-30-19-59-28.gh-issue-66436.4gYN_n.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Oct 1, 2024
@serhiy-storchaka @ncoghlan
Apply suggestions from code review
99c7d98
Co-authored-by: Alyssa Coghlan <[email protected]>
serhiy-storchaka
serhiy-storchaka commented Oct 1, 2024
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member Author

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.

Thank you for your suggestions @ncoghlan. I applied them all.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/argparse.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka serhiy-storchaka mentioned this pull request Oct 1, 2024
import_helper.make_legacy_pyc() works incorrectly for source files in a directory #124842
Closed
serhiy-storchaka added 2 commits October 1, 2024 19:06
@serhiy-storchaka
Update Lib/argparse.py
92b9d07
@serhiy-storchaka
Merge branch 'main' into argparse-default-prog-name
f6810ee
@serhiy-storchaka
serhiy-storchaka removed request for brettcannon, ericsnowcurrently and warsaw October 1, 2024 16:09
@serhiy-storchaka
Try to fix other test on Windows CI.
1f0bfc1
@serhiy-storchaka
serhiy-storchaka merged commit 04bfea2 into python:main Oct 1, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Oct 1, 2024
@serhiy-storchaka
serhiy-storchaka deleted the argparse-default-prog-name branch October 1, 2024 19:51
@effigies effigies mentioned this pull request Mar 10, 2026
fix: Adjust tests to not depend on how pytest is invoked nipy/nibabel#1478
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ncoghlan ncoghlan ncoghlan approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@serhiy-storchaka @ncoghlan
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.