From 776273e7be88b3668319aa4acf098decc113449c Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Fri, 16 Sep 2022 10:10:17 +0200 Subject: [PATCH] Eliminate unnecessary variables --- src/towncrier/build.py | 11 ++++------- src/towncrier/create.py | 12 +++++------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/towncrier/build.py b/src/towncrier/build.py index 148b70a8..f414319a 100644 --- a/src/towncrier/build.py +++ b/src/towncrier/build.py @@ -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 @@ -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: @@ -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}, @@ -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: @@ -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, diff --git a/src/towncrier/create.py b/src/towncrier/create.py index d6ba898c..92895a8a 100644 --- a/src/towncrier/create.py +++ b/src/towncrier/create.py @@ -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: