Skip to content

Commit

Permalink
Eliminate unnecessary variables
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Sep 16, 2022
1 parent 74751c2 commit 776273e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
11 changes: 4 additions & 7 deletions src/towncrier/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ def __main(

click.echo("Finding news fragments...", err=to_err)

definitions = config.types

if config.directory:
fragment_base_directory = os.path.abspath(config.directory)
fragment_directory = None
Expand All @@ -134,13 +132,13 @@ def __main(
fragment_base_directory,
config.sections,
fragment_directory,
definitions,
config.types,
config.orphan_prefix,
)

click.echo("Rendering news fragments...", err=to_err)
fragments = split_fragments(
fragment_contents, definitions, all_bullets=config.all_bullets
fragment_contents, config.types, all_bullets=config.all_bullets
)

if project_version is None:
Expand Down Expand Up @@ -188,7 +186,7 @@ def __main(
template,
config.issue_format,
fragments,
definitions,
config.types,
config.underlines[1:],
config.wrap,
{"name": project_name, "version": project_version, "date": project_date},
Expand Down Expand Up @@ -217,7 +215,6 @@ def __main(
click.echo(content)
else:
click.echo("Writing to newsfile...", err=to_err)
start_string = config.start_string
news_file = config.filename

if config.single_file is False:
Expand All @@ -230,7 +227,7 @@ def __main(
append_to_newsfile(
base_directory,
news_file,
start_string,
config.start_string,
top_line,
content,
single_file=config.single_file,
Expand Down
12 changes: 5 additions & 7 deletions src/towncrier/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,17 @@ def __main(
"""
base_directory, config = load_config_from_options(directory, config_path)

definitions = config.types or {}
orphan_prefix = config.orphan_prefix
if orphan_prefix and filename.startswith(f"{orphan_prefix}."):
if config.orphan_prefix and filename.startswith(f"{config.orphan_prefix}."):
# Append a random hex string to the orphan news fragment base name.
filename = f"{orphan_prefix}{os.urandom(4).hex()}{filename[1:]}"
filename = f"{config.orphan_prefix}{os.urandom(4).hex()}{filename[1:]}"
if len(filename.split(".")) < 2 or (
filename.split(".")[-1] not in definitions
and filename.split(".")[-2] not in definitions
filename.split(".")[-1] not in config.types
and filename.split(".")[-2] not in config.types
):
raise click.BadParameter(
"Expected filename '{}' to be of format '{{name}}.{{type}}', "
"where '{{name}}' is an arbitrary slug and '{{type}}' is "
"one of: {}".format(filename, ", ".join(definitions))
"one of: {}".format(filename, ", ".join(config.types))
)

if config.directory:
Expand Down

0 comments on commit 776273e

Please sign in to comment.