Skip to content

Allow the GH issue + Section as --flags and take news via stdin #45

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

gpshead
Copy link
Member

@gpshead gpshead commented Jun 29, 2025

At a high level I wanted this feature:

  • Add automation support to blurb add command:
  • Uses cyclopts for command line parsing instead of rolling our own to reduce our code size, this changes the help format and brings in a dependency.

That led to a rabbit hole, I did the feature in the first commit without cyclopts and really wished we were using it (or the older defopt) given the decorated function pattern being used for commands already.

More code deleted than added while gaining the above features. (until pulling in #16 brought in more, but that makes things nicer anyways)

gpshead and others added 3 commits June 29, 2025 00:39
This commit adds three new options to 'blurb add' for automation:
- --gh_issue: Specify GitHub issue number
- --section: Specify NEWS section (must be from the sacred list)
- --rst_on_stdin: Read the news entry from stdin (no editor needed)

When using --rst_on_stdin, one must provide both --gh_issue and
--section, lest they be turned into a newt (they'll get better).

Added comprehensive test coverage including:
- Unit tests for parameter validation
- Integration tests with mock CPython repo (ruled by Brian of Nazareth)
- CLI tests that actually run the blurb command

Also fixed the command-line parser to handle non-boolean options
specifically for the add command, and improved error handling
for temporary file cleanup.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
This holy grail of refactoring reduces the code by >150 lines!
We've eliminated the bureaucracy of wrapper functions and now
apply `@app.command` decorators directly to the original functions.

Just like the Knights of Ni demanded a shrubbery, cyclopts demands
clear, typed parameters - and we have delivered! The code is now
cleaner than the Holy Grail's cup after being washed by the
French Taunter.

Key improvements:
- Moved cyclopts imports to top of file (no more silly walks)
- Applied `@app.command` directly to functions (no indirection!)
- Removed 'help' parameter from add() - cyclopts handles it
- Simplified main() from ~200 lines to ~40 lines
- Updated tests for new option naming (--gh-issue not --gh_issue)
- All 28 tests still pass - it's not dead yet!

'Tis but a scratch compared to the original implementation!

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

(with a few human touchups by Greg)
@gpshead gpshead force-pushed the knights-who-say-stdin branch from 4249861 to 67a6c0c Compare June 29, 2025 05:44
@gpshead gpshead requested a review from hugovk June 29, 2025 05:48
@gpshead gpshead force-pushed the knights-who-say-stdin branch from 56b3eab to e79dd63 Compare June 29, 2025 05:49
@gpshead gpshead changed the title Allow the GH issue & Section on the command line & news entry via stdin Allow the GH issue + Section as --flags and take news via stdin Jun 29, 2025
@hugovk
Copy link
Member

hugovk commented Jun 29, 2025

This overlaps with #16, cc @picnixz.

@picnixz
Copy link
Member

picnixz commented Jun 29, 2025

May I suggest keeping the cycleopts stuff (looks better than our ugly hacks) but keep my way for rendering available sections etc? (because I also support URLs extractions which are usually easier when coming from a browser)

Integrate the user-friendly features from PR python#16 by @picnixz into the
automation support from PR python#45, making the CLI more intuitive:

- Change --gh-issue to --issue, accepting multiple formats:
  * Plain numbers: --issue 12345
  * With gh- prefix: --issue gh-12345
  * GitHub URLs: --issue python/cpython#12345

- Add smart section matching with:
  * Case-insensitive matching: --section lib matches "Library"
  * Partial matching: --section doc matches "Documentation"
  * Common aliases: --section api matches "C API"
  * Separator normalization: --section core-and-builtins

- Improve error messages for invalid sections

This combines the automation features from PR python#45 with the interface
improvements suggested by @picnixz in PR python#16, as reviewed by @hugovk
and @larryhastings.

Co-authored-by: picnixz <[email protected]>
gpshead and others added 2 commits July 3, 2025 21:18
Integrate the user-friendly features from PR python#16 by @picnixz into the automation support from PR python#45, making the CLI more intuitive:

- Change --gh-issue to --issue, accepting multiple formats:
  * Plain numbers: --issue 12345
  * With gh- prefix: --issue gh-12345
  * GitHub URLs: --issue python/cpython#12345

- Add smart section matching with:
  * Case-insensitive matching: --section lib matches "Library"
  * Partial matching: --section doc matches "Documentation"
  * Common aliases: --section api matches "C API"
  * Separator normalization: --section core-and-builtins

- Improve error messages for invalid sections

This combines the automation features from PR python#45 with the interface improvements suggested by @picnixz in PR python#16, as reviewed by @hugovk and @larryhastings.
Now 'blurb -i 123' works the same as 'blurb add -i 123', because nobody
expects the Spanish Inquisition... or having to type 'add' every time.

- Forward all add command parameters to the default command
- Update help text to indicate 'add' is the default command
- Parameters like --issue, --section, and --rst-on-stdin now work
  directly with 'blurb' without specifying 'add'
@gpshead
Copy link
Member Author

gpshead commented Jul 4, 2025

I brought in the #16 features, please take another look.

gpshead and others added 2 commits July 4, 2025 09:02
Eliminated 4 redundant test methods from TestAddCommandAutomation that
duplicated validation logic already covered by existing parametrized tests.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@gpshead gpshead requested a review from picnixz July 4, 2025 16:36
normalized = ''.join(section_words).lower()

# Check special aliases
aliases = {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe make this a global variable?

GitHub issue number or URL (e.g. '12345', 'gh-12345', or 'https://github.com/python/cpython/issues/12345').
section : str, optional
NEWS section. Can use partial matching (e.g. 'lib' for 'Library'). One of {sections_csv}.
rst_on_stdin : bool
Copy link
Member

Choose a reason for hiding this comment

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

Can we have a short option for this one, maybe -D for description for instance?

@@ -57,13 +53,19 @@
import tempfile
import textwrap
import time
from typing import Optional, Annotated
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
from typing import Optional, Annotated
from typing import Annotated, Optional

Can we add a comment saying that it's needed for cycleopts? Otherwise this could be assumed to be unnecessary.

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.

3 participants