Skip to content

gh-134200: Add adaptive global alignment for help text#134308

Closed
lnperry wants to merge 7 commits into
python:mainfrom
lnperry:gh-134200
Closed

gh-134200: Add adaptive global alignment for help text#134308
lnperry wants to merge 7 commits into
python:mainfrom
lnperry:gh-134200

Conversation

@lnperry

@lnperry lnperry commented May 20, 2025

Copy link
Copy Markdown

Refactors HelpFormatter to improve help text readability and consistency,
addressing issues where argument string lengths varied widely.

Previously, a single very long option could push all help text excessively
to the right, or groups of only short options might not align optimally.

Key changes:

  1. A global help alignment column is now calculated by finding the display
    endpoint of the longest "reasonable" argument invocation string across
    all sections, adding a 2-space padding.

    • A "reasonable" argument is one whose own invocation string (plus
      indent and minimal padding) does not exceed the overall maximum help
      position (derived from max_help_position and terminal width, e.g., 24).
    • This calculated alignment column is itself capped by this overall
      maximum help position.
  2. Help text for arguments is formatted against this single global column:

    • Shorter arguments are padded so their help text (and any wrapped lines)
      begins at this alignment column.
    • Argument invocations too long to fit this same-line alignment will
      have their help text start on the next line, also indented to this
      alignment column.

This ensures:

  • Consistent alignment of help descriptions across all sections.
  • Outlier long options no longer distort the layout for other arguments.
  • Sets of only short options are aligned compactly based on their local
    longest member, rather than being forced to an unnecessarily wide default.
  • The option defining the alignment has exactly two spaces before its help.

@python-cla-bot

python-cla-bot Bot commented May 20, 2025

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app

bedevere-app Bot commented May 20, 2025

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app

bedevere-app Bot commented May 20, 2025

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app

bedevere-app Bot commented May 21, 2025

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app

bedevere-app Bot commented May 21, 2025

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app

bedevere-app Bot commented May 21, 2025

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app

bedevere-app Bot commented May 21, 2025

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app

bedevere-app Bot commented May 21, 2025

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@savannahostrowski savannahostrowski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for missing this back in May. Thanks for looking into this - I tested the changes and while they work as described, I think that the visual impact here is very minimal compared to code complexity this introduces. I'm also a bit concerned about the impact this will have on anyone whose tests depend on the current indentation. I don't think we should move forward with this change.

@savannahostrowski

Copy link
Copy Markdown
Member

I've closed the corresponding issue for this so will also close this. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants