-
-
Notifications
You must be signed in to change notification settings - Fork 60
Add --bpo and --section flags to "blurb add". #312
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,6 @@ | ||||||
#!/usr/bin/env python3 | ||||||
"""Command-line tool to manage CPython Misc/NEWS.d entries.""" | ||||||
__version__ = "1.0.7" | ||||||
__version__ = "1.0.8" | ||||||
|
||||||
## | ||||||
## blurb version 1.0 | ||||||
|
@@ -76,7 +76,7 @@ | |||||
# | ||||||
# Please enter the relevant bugs.python.org issue number here: | ||||||
# | ||||||
.. bpo: | ||||||
.. bpo: {bpo} | ||||||
|
||||||
# | ||||||
# Uncomment one of these "section:" lines to specify which section | ||||||
|
@@ -93,7 +93,7 @@ | |||||
#.. section: IDLE | ||||||
#.. section: Tools/Demos | ||||||
#.. section: C API | ||||||
|
||||||
{section} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why don't you keep the same principle with the Do you make the construction before because you don't want to have a conditional template? is it right? |
||||||
# Write your Misc/NEWS entry below. It should be a simple ReST paragraph. | ||||||
# Don't start with "- Issue #<n>: " or "- bpo-<n>: " or that sort of stuff. | ||||||
########################################################################### | ||||||
|
@@ -483,6 +483,8 @@ def parse(self, text, *, metadata=None, filename="input"): | |||||
line_number = None | ||||||
|
||||||
def throw(s): | ||||||
nonlocal filename | ||||||
nonlocal line_number | ||||||
raise BlurbError(f("Error in {filename}:{line_number}:\n{s}")) | ||||||
|
||||||
def finish_entry(): | ||||||
|
@@ -902,7 +904,7 @@ def find_editor(): | |||||
|
||||||
|
||||||
@subcommand | ||||||
def add(): | ||||||
def add(*, bpo="", section=""): | ||||||
""" | ||||||
Add a blurb (a Misc/NEWS entry) to the current CPython repo. | ||||||
""" | ||||||
|
@@ -913,24 +915,19 @@ def add(): | |||||
os.close(handle) | ||||||
atexit.register(lambda : os.unlink(tmp_path)) | ||||||
|
||||||
def init_tmp_with_template(): | ||||||
with open(tmp_path, "wt", encoding="utf-8") as file: | ||||||
# hack: | ||||||
# my editor likes to strip trailing whitespace from lines. | ||||||
# normally this is a good idea. but in the case of the template | ||||||
# it's unhelpful. | ||||||
# so, manually ensure there's a space at the end of the bpo line. | ||||||
text = template | ||||||
|
||||||
bpo_line = ".. bpo:" | ||||||
without_space = "\n" + bpo_line + "\n" | ||||||
with_space = "\n" + bpo_line + " \n" | ||||||
if without_space not in text: | ||||||
sys.exit("Can't find BPO line to ensure there's a space on the end!") | ||||||
text = text.replace(without_space, with_space) | ||||||
file.write(text) | ||||||
if bpo: | ||||||
try: | ||||||
int(bpo) | ||||||
except ValueError: | ||||||
error("blurb add --bpo argument " + repr(bpo) + " is not a valid integer!") | ||||||
|
||||||
init_tmp_with_template() | ||||||
if section: | ||||||
if section not in sections: | ||||||
error("blurb add --section argument " + repr(section) + " is not a valid section!") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about printing the valid sections when this fails?
Suggested change
For example: $ python blurb.py add --bpo 123 --section aaa
Error: blurb add --section argument 'aaa' is not a valid section! Use one of:
Security
Core and Builtins
Library
Documentation
Tests
Build
Windows
macOS
IDLE
Tools/Demos
C API |
||||||
section = ".. section: " + section + "\n" | ||||||
|
||||||
with open(tmp_path, "wt", encoding="utf-8") as file: | ||||||
file.write(template.format(bpo=bpo, section=section)) | ||||||
|
||||||
# We need to be clever about EDITOR. | ||||||
# On the one hand, it might be a legitimate path to an | ||||||
|
@@ -1617,36 +1614,48 @@ def main(): | |||||
kwargs = {} | ||||||
for name, p in inspect.signature(fn).parameters.items(): | ||||||
if p.kind == inspect.Parameter.KEYWORD_ONLY: | ||||||
assert isinstance(p.default, bool), "blurb command-line processing only handles boolean options" | ||||||
assert isinstance(p.default, (bool, str)), "blurb command-line processing only handles boolean options and strings" | ||||||
kwargs[name] = p.default | ||||||
short_options[name[0]] = name | ||||||
long_options[name] = name | ||||||
|
||||||
filtered_args = [] | ||||||
done_with_options = False | ||||||
needs_oparg = None | ||||||
|
||||||
def handle_option(s, dict): | ||||||
def handle_option(s, dict, fn_name): | ||||||
nonlocal needs_oparg | ||||||
name = dict.get(s, None) | ||||||
if not name: | ||||||
sys.exit(f('blurb: Unknown option for {subcommand}: "{s}"')) | ||||||
kwargs[name] = not kwargs[name] | ||||||
sys.exit(f('blurb: Unknown option for {fn_name}: "{s}"')) | ||||||
value = kwargs[name] | ||||||
if isinstance(value, bool): | ||||||
kwargs[name] = not value | ||||||
else: | ||||||
needs_oparg = name | ||||||
|
||||||
# print(f("short_options {short_options} long_options {long_options}")) | ||||||
for a in args: | ||||||
if needs_oparg: | ||||||
kwargs[needs_oparg] = a | ||||||
needs_oparg = None | ||||||
continue | ||||||
if done_with_options: | ||||||
filtered_args.append(a) | ||||||
continue | ||||||
if a.startswith('-'): | ||||||
if a == "--": | ||||||
done_with_options = True | ||||||
elif a.startswith("--"): | ||||||
handle_option(a[2:], long_options) | ||||||
handle_option(a[2:], long_options, fn.__name__) | ||||||
else: | ||||||
for s in a[1:]: | ||||||
handle_option(s, short_options) | ||||||
handle_option(s, short_options, fn.__name__) | ||||||
continue | ||||||
filtered_args.append(a) | ||||||
|
||||||
if needs_oparg: | ||||||
sys.exit(f("Error: blurb {fn_name} {needs_oparg} must be followed by an option argument!")) | ||||||
|
||||||
sys.exit(fn(*filtered_args, **kwargs)) | ||||||
except TypeError as e: | ||||||
|
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.
Does it make sense to use the bpo abbreviation, or would it be better as
issue
now?