-
Notifications
You must be signed in to change notification settings - Fork 129
#714 feature(create): added option 'index' which allows direct access to indexed snippets #735
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
e082237
b2a8f85
6d2e535
d1a1712
360b6d3
6fe2f50
6804203
1900c74
cd1e930
543388e
c1bdf57
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 |
|---|---|---|
|
|
@@ -52,6 +52,7 @@ def bar(): | |
| bar | ||
|
|
||
| """ | ||
|
|
||
| import warnings | ||
|
|
||
| import click | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -54,6 +54,13 @@ | |||||
| type=str, | ||||||
| help="The section to create the fragment for.", | ||||||
| ) | ||||||
| @click.option( | ||||||
| "--index", | ||||||
|
Member
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. Index is kind of generic...
Suggested change
I don't know if "index" is the best name for this feature... maybe we can call it
Author
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. hmmm, it's like an index - 0 is the first fragment, 1 the next, etc. but i can live with any text. |
||||||
| type=click.IntRange(min=0), | ||||||
| metavar="N", | ||||||
| default=None, | ||||||
| help="Optional numeric index of the fragment", | ||||||
| ) | ||||||
| @click.argument("filename", default="") | ||||||
| def _main( | ||||||
| ctx: click.Context, | ||||||
|
|
@@ -63,6 +70,7 @@ def _main( | |||||
| edit: bool | None, | ||||||
| content: str, | ||||||
| section: str | None, | ||||||
| index: int | None, | ||||||
| ) -> None: | ||||||
| """ | ||||||
| Create a new news fragment. | ||||||
|
|
@@ -83,7 +91,7 @@ def _main( | |||||
| If the FILENAME base is just '+' (to create a fragment not tied to an | ||||||
| issue), it will be appended with a random hex string. | ||||||
| """ | ||||||
| __main(ctx, directory, config, filename, edit, content, section) | ||||||
| __main(ctx, directory, config, filename, edit, content, section, index) | ||||||
|
|
||||||
|
|
||||||
| def __main( | ||||||
|
|
@@ -94,6 +102,7 @@ def __main( | |||||
| edit: bool | None, | ||||||
| content: str, | ||||||
| section: str | None, | ||||||
| index: int | None, | ||||||
| ) -> None: | ||||||
| """ | ||||||
| The main entry point. | ||||||
|
|
@@ -187,6 +196,7 @@ def __main( | |||||
| "where '{{name}}' is an arbitrary slug and '{{type}}' is " | ||||||
| "one of: {}".format(filename, ", ".join(config.types)) | ||||||
| ) | ||||||
|
|
||||||
| if filename_parts[-1] in config.types and filename_ext: | ||||||
| filename += filename_ext | ||||||
|
|
||||||
|
|
@@ -198,15 +208,22 @@ def __main( | |||||
|
|
||||||
| segment_file = os.path.join(fragments_directory, filename) | ||||||
|
|
||||||
| retry = 0 | ||||||
| if filename.split(".")[-1] not in config.types: | ||||||
| filename, extra_ext = os.path.splitext(filename) | ||||||
| else: | ||||||
| extra_ext = "" | ||||||
| while os.path.exists(segment_file): | ||||||
| retry += 1 | ||||||
|
|
||||||
| if index is None: | ||||||
| retry = 0 | ||||||
| while os.path.exists(segment_file): | ||||||
| retry += 1 | ||||||
| segment_file = os.path.join( | ||||||
| fragments_directory, f"{filename}.{retry}{extra_ext}" | ||||||
| ) | ||||||
| else: | ||||||
| segment_file = os.path.join( | ||||||
| fragments_directory, f"{filename}.{retry}{extra_ext}" | ||||||
| fragments_directory, | ||||||
| f"{filename}{'.' + str(index) if index > 0 else ''}{extra_ext}", | ||||||
| ) | ||||||
|
|
||||||
| if edit: | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| The `towncrier create` command line tool now has the `--index` option that is used when creating multiple fragments for the same issue number. |
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.
is this change needed?
Uh oh!
There was an error while loading. Please reload this page.
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.
this was one of the "auto fixes" of pre-commit.
no, it's not needed in my eyes, but i have to commit it using "--no-verify".
if you don't mind, i will leave it as it is to satisfy the pre-commit tools.