Skip to content

Add -i/--issue and -s/--section flags to blurb add - #16

Closed
picnixz wants to merge 36 commits into
python:mainfrom
picnixz:add-gh-flags
Closed

Add -i/--issue and -s/--section flags to blurb add#16
picnixz wants to merge 36 commits into
python:mainfrom
picnixz:add-gh-flags

Conversation

@picnixz

@picnixzpicnixz commented Jun 25, 2024

Copy link
Copy Markdown
Member

Fixes#6. This is an alternative to #15.

@hugovk I've taken out your way of handling positional arguments (but would you consider a PR which refactors blurb in order to use argparse instead?). If you prefer --gh, I can also rename the variable!

@hugovk

Copy link
Copy Markdown
Member

would you consider a PR which refactors blurb in order to use argparse instead?

That could make things easier, but I've not used subcommands much in argparse, how are they? We'd need to make sure all the commands and options work in the same way, blurb is used in a few different bits of automation and we wouldn't want to break any of them.

Comment threadsrc/blurb/blurb.py Outdated
Comment threadsrc/blurb/blurb.py Outdated
Comment threadREADME.md Outdated
Comment threadREADME.md Outdated
Comment threadsrc/blurb/blurb.py Outdated
Comment threadtests/test_blurb_add.py Outdated
@picnixz

Copy link
Copy Markdown
MemberAuthor

That could make things easier, but I've not used subcommands much in argparse, how are they? We'd need to make sure all the commands and options work in the same way, blurb is used in a few different bits of automation and we wouldn't want to break any of them.

From my personal usage of subcommands, it works the same. Actually, a subcommand is just an action that invokes an ArgumentParser. However, it might indeed come with some corner cases which I would first extensively test. If you can tell me where it's being used in automaton parts, then I'd be glad to check if I can make the transition.

@hugovk

Copy link
Copy Markdown
Member

If you can tell me where it's being used in automaton parts, then I'd be glad to check if I can make the transition.

Hmm, well at least here:

Comment threadtests/test_blurb_add.py Outdated
Comment threadtests/test_blurb_add.py Outdated
Comment threadtests/test_blurb_add.py Outdated
@hugovkhugovk added the enhancement New feature or request label Jun 26, 2024

@larryhastingslarryhastings left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some initial comments. I'll confer further with Hugo.

Comment threadREADME.md Outdated
Comment threadsrc/blurb/blurb.py Outdated
Comment threadsrc/blurb/blurb.py Outdated
Comment threadsrc/blurb/blurb.py Outdated
@picnixz

Copy link
Copy Markdown
MemberAuthor

Thank you Larry for your comments. I'll address them tomorrow (I don't have access to the project now)

- remove section IDs matching
- do not render the table in case of a multi-match
- simplify `add` docstring construction
- update tests
- update README.md
Comment threadREADME.md Outdated
Comment threadREADME.md Outdated
Comment threadsrc/blurb/blurb.py Outdated
picnixzand others added 3 commits July 13, 2024 11:32
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
@picnixz

Copy link
Copy Markdown
MemberAuthor

I don't think we necessarily need to match "builtins" -> "Core and Builtins" or "demo" -> "Tools/Demos", but "capi" -> "C API" would help, and maybe also "api" -> "C API"?

I ended up making them match like that (the tests should reflect what is now possible). I don't have a better way to cover the use cases so don't hesistate to tell me which cases should be checked.

@larryhastings

Copy link
Copy Markdown
Contributor

Would it be sufficient to create a "nickname map", like

{ "".join(section.split()).lower(): section for section in sections }

@picnixz

Copy link
Copy Markdown
MemberAuthor

{ "".join(section.split()).lower(): section for section in sections }

Yes. But to construct additional patterns, I needed to use:

_sanitized=re.sub(r'[ /]', ' ', _section)
_section_words=re.split(r'\s+', _sanitized)
_section_names_lower_nosep[_section] =''.join(_section_words).lower()

(Your suggestion is in my case implemented as ''.join(_section_words).lower())

Comment threadsrc/blurb/blurb.py Outdated
Comment threadsrc/blurb/blurb.py Outdated
Comment threadsrc/blurb/blurb.py Outdated
@hugovkhugovk changed the title gh-6: add -i/--issue and -s/--section flags to blurb addAdd -i/--issue and -s/--section flags to blurb addJun 2, 2025

@hugovkhugovk 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.

I'm not fully sold on the smart matching, I don't think we need to worry about things like blurb add --section "cOre _ and - bUILtins".

Would case-insensitive substring matching be enough, as long as the substring is unique?

So these would work:

blurb add --section mac
blurb add --section core
blurb add --section build
blurb add --section built

But not:

blurb add --section buil
blurb add --section i

Comment threadsrc/blurb/blurb.py
Comment on lines +835 to +836
if issue.startswith('gh-'):
issue = issue[3:]

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.

Suggested change
ifissue.startswith('gh-'):
issue=issue[3:]
issue=issue.removeprefix('gh-')

Comment threadsrc/blurb/blurb.py
Comment on lines +866 to +874
del _sanitized
# '_', '-', ' ' and '/' are the allowed (user) separators
_section_pattern = r'[_\- /]?'.join(map(re.escape, _section_words))
# add '$' to avoid matching after the pattern
_section_pattern = f'{_section_pattern}$'
del _section_words
_section_pattern = re.compile(_section_pattern, re.I)
_section_special_patterns[_section].add(_section_pattern)
del _section_pattern, _section

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.

Do we really need these dels?

Suggested change
del_sanitized
# '_', '-', ' ' and '/' are the allowed (user) separators
_section_pattern=r'[_\- /]?'.join(map(re.escape, _section_words))
# add '$' to avoid matching after the pattern
_section_pattern=f'{_section_pattern}$'
del_section_words
_section_pattern=re.compile(_section_pattern, re.I)
_section_special_patterns[_section].add(_section_pattern)
del_section_pattern, _section
# '_', '-', ' ' and '/' are the allowed (user) separators
_section_pattern=r'[_\- /]?'.join(map(re.escape, _section_words))
# add '$' to avoid matching after the pattern
_section_pattern=f'{_section_pattern}$'
_section_pattern=re.compile(_section_pattern, re.I)
_section_special_patterns[_section].add(_section_pattern)

Comment threadsrc/blurb/blurb.py
Comment on lines +1065 to +1069
del _sec_name_width
sections_table = '\n'.join(map(_format_row, sections))
del _format_row
sections_table = '\n'.join((_sec_row_rule, sections_table, _sec_row_rule))
del _sec_row_rule

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.

Suggested change
del_sec_name_width
sections_table='\n'.join(map(_format_row, sections))
del_format_row
sections_table='\n'.join((_sec_row_rule, sections_table, _sec_row_rule))
del_sec_row_rule
sections_table='\n'.join(map(_format_row, sections))
sections_table='\n'.join((_sec_row_rule, sections_table, _sec_row_rule))

Comment on lines +86 to +88
def check(section, expect):
actual = blurb._extract_section_name(section)
assert actual == expect

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.

To match the other test files:

Suggested change
defcheck(section, expect):
actual=blurb._extract_section_name(section)
assertactual==expect
defcheck(section, expected):
actual=blurb._extract_section_name(section)
assertactual==expected

res = blurb._update_blurb_template(issue=None, section=section)
res = res.splitlines()
for section_name in blurb.sections:
if section_name == expect:

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.

Suggested change
ifsection_name==expect:
ifsection_name==expected:

Comment on lines +100 to +107
('section', 'expect'),
tuple(zip(blurb.sections, blurb.sections))
)
def test_exact_names(self, section, expect):
self.check(section, expect)

@pytest.mark.parametrize(
('section', 'expect'), [

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.

Suggested change
('section', 'expect'),
tuple(zip(blurb.sections, blurb.sections))
)
deftest_exact_names(self, section, expect):
self.check(section, expect)
@pytest.mark.parametrize(
('section', 'expect'), [
('section', 'expected'),
tuple(zip(blurb.sections, blurb.sections))
)
deftest_exact_names(self, section, expected):
self.check(section, expected)
@pytest.mark.parametrize(
('section', 'expected'), [

Comment on lines +130 to +134
def test_partial_words(self, section, expect):
self.check(section, expect)

@pytest.mark.parametrize(
('section', 'expect'), [

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.

Suggested change
deftest_partial_words(self, section, expect):
self.check(section, expect)
@pytest.mark.parametrize(
('section', 'expect'), [
deftest_partial_words(self, section, expected):
self.check(section, expected)
@pytest.mark.parametrize(
('section', 'expected'), [

Comment on lines +146 to +150
def test_partial_special_names(self, section, expect):
self.check(section, expect)

@pytest.mark.parametrize(
('section', 'expect'), [

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.

Suggested change
deftest_partial_special_names(self, section, expect):
self.check(section, expect)
@pytest.mark.parametrize(
('section', 'expect'), [
deftest_partial_special_names(self, section, expected):
self.check(section, expected)
@pytest.mark.parametrize(
('section', 'expected'), [

Comment on lines +165 to +170
def test_partial_separators(self, section, expect):
# normalize the separtors '_', '-', ' ' and '/'
self.check(section, expect)

@pytest.mark.parametrize(
('prefix', 'expect'), [

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.

Plus a typo

Suggested change
deftest_partial_separators(self, section, expect):
# normalize the separtors '_', '-', ' ' and '/'
self.check(section, expect)
@pytest.mark.parametrize(
('prefix', 'expect'), [
deftest_partial_separators(self, section, expected):
# normalize the separators '_', '-', ' ' and '/'
self.check(section, expected)
@pytest.mark.parametrize(
('prefix', 'expected'), [

Comment on lines +184 to +200
def test_partial_prefix_words(self, prefix, expect):
# try to find a match using prefixes (without separators and lowercase)
self.check(prefix, expect)

@pytest.mark.parametrize(
('section', 'expect'),
[(name.lower(), name) for name in blurb.sections],
)
def test_exact_names_lowercase(self, section, expect):
self.check(section, expect)

@pytest.mark.parametrize(
('section', 'expect'),
[(name.upper(), name) for name in blurb.sections],
)
def test_exact_names_uppercase(self, section, expect):
self.check(section, expect)

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.

Suggested change
deftest_partial_prefix_words(self, prefix, expect):
# try to find a match using prefixes (without separators and lowercase)
self.check(prefix, expect)
@pytest.mark.parametrize(
('section', 'expect'),
[(name.lower(), name) fornameinblurb.sections],
)
deftest_exact_names_lowercase(self, section, expect):
self.check(section, expect)
@pytest.mark.parametrize(
('section', 'expect'),
[(name.upper(), name) fornameinblurb.sections],
)
deftest_exact_names_uppercase(self, section, expect):
self.check(section, expect)
deftest_partial_prefix_words(self, prefix, expected):
# try to find a match using prefixes (without separators and lowercase)
self.check(prefix, expected)
@pytest.mark.parametrize(
('section', 'expected'),
[(name.lower(), name) fornameinblurb.sections],
)
deftest_exact_names_lowercase(self, section, expected):
self.check(section, expected)
@pytest.mark.parametrize(
('section', 'expected'),
[(name.upper(), name) fornameinblurb.sections],
)
deftest_exact_names_uppercase(self, section, expected):
self.check(section, expected)

@picnixz

Copy link
Copy Markdown
MemberAuthor

I think it would be enough.

gpshead added a commit to gpshead/blurb that referenced this pull request Jul 4, 2025
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 <picnixz@users.noreply.github.com>
gpshead added a commit to gpshead/blurb that referenced this pull request Jul 4, 2025
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.
@AA-Turner

Copy link
Copy Markdown
Member

This has now been split into #46, #48, #49, and #65.

A

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

Labels

enhancementNew feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add --gh and --section flags to "blurb add"

4 participants

@picnixz@hugovk@larryhastings@AA-Turner