From efc9e6ffddde5aa1466ce80b3477233bfd85d969 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 9 Apr 2022 09:51:07 +0200 Subject: [PATCH 1/7] Remove unneeded compat code Courtesy of pyupgrade. --- src/towncrier/_builder.py | 27 ++++---- src/towncrier/_project.py | 7 +-- src/towncrier/_settings/fragment_types.py | 10 +-- src/towncrier/_settings/load.py | 10 +-- src/towncrier/_writer.py | 9 ++- src/towncrier/build.py | 1 - src/towncrier/check.py | 7 +-- src/towncrier/create.py | 5 +- src/towncrier/test/test_build.py | 28 ++++----- src/towncrier/test/test_check.py | 2 +- src/towncrier/test/test_create.py | 2 +- src/towncrier/test/test_format.py | 75 +++++++++++------------ src/towncrier/test/test_settings.py | 10 +-- src/towncrier/test/test_write.py | 36 +++++------ tox.ini | 1 - 15 files changed, 109 insertions(+), 121 deletions(-) diff --git a/src/towncrier/_builder.py b/src/towncrier/_builder.py index 387dd75a..3295b9cb 100644 --- a/src/towncrier/_builder.py +++ b/src/towncrier/_builder.py @@ -1,7 +1,6 @@ # Copyright (c) Amber Brown, 2015 # See LICENSE for details. -from __future__ import absolute_import, division, print_function import os import textwrap @@ -134,7 +133,7 @@ def prefixed_lines(): for line in text.splitlines(True): yield (prefix + line if line.strip() else line) - return u"".join(prefixed_lines()) + return "".join(prefixed_lines()) # Takes the output from find_fragments above. Probably it would be useful to @@ -153,13 +152,13 @@ def split_fragments(fragments, definitions, all_bullets=True): # By default all fragmetns are append by "-" automatically, # and need to be indented because of that. # (otherwise, assume they are formatted correctly) - content = indent(content.strip(), u" ")[2:] + content = indent(content.strip(), " ")[2:] else: # Assume the text is formatted correctly content = content.rstrip() if definitions[category]["showcontent"] is False: - content = u"" + content = "" texts = section.get(category, OrderedDict()) @@ -180,7 +179,7 @@ def issue_key(issue): # issues to sort as strings. We arbitrarily put string issues before # integer issues (hopefully no-one uses both at once). try: - return (int(issue), u"") + return (int(issue), "") except Exception: # Maybe we should sniff strings like "gh-10" -> (10, "gh-10")? return (-1, issue) @@ -195,11 +194,11 @@ def bullet_key(entry): text, _ = entry if not text: return -1 - if text[:2] == u"- ": + if text[:2] == "- ": return 0 elif text[:2] == "* ": return 1 - elif text[:3] == u"#. ": + elif text[:3] == "#. ": return 2 return 3 @@ -208,7 +207,7 @@ def render_issue(issue_format, issue): if issue_format is None: try: int(issue) - return u"#" + issue + return "#" + issue except Exception: return issue else: @@ -276,11 +275,11 @@ def get_indent(text): # If bullets are not assumed and we wrap, the subsequent # indentation depends on whether or not this is a bullet point. # (it is probably usually best to disable wrapping in that case) - if all_bullets or text[:2] == u"- " or text[:2] == u"* ": - return u" " + if all_bullets or text[:2] == "- " or text[:2] == "* ": + return " " elif text[:3] == "#. ": - return u" " - return u"" + return " " + return "" res = jinja_template.render( render_title=render_title, @@ -292,7 +291,7 @@ def get_indent(text): get_indent=get_indent, # simplify indentation in the jinja template. ) - for line in res.split(u"\n"): + for line in res.split("\n"): if wrap: done.append( textwrap.fill( @@ -306,4 +305,4 @@ def get_indent(text): else: done.append(line) - return u"\n".join(done).rstrip() + u"\n" + return "\n".join(done).rstrip() + "\n" diff --git a/src/towncrier/_project.py b/src/towncrier/_project.py index 1999eab0..e9568fc1 100644 --- a/src/towncrier/_project.py +++ b/src/towncrier/_project.py @@ -5,7 +5,6 @@ Responsible for getting the version and name from a project. """ -from __future__ import absolute_import, division import sys @@ -26,9 +25,9 @@ def _get_package(package_dir, package): try: module = import_module(package) except ImportError as e: - err = "tried to import {}, but ran into this error: {}".format(package, e) + err = f"tried to import {package}, but ran into this error: {e}" # NOTE: this might be redirected via "towncrier --draft > …". - print("ERROR: {}".format(err)) + print(f"ERROR: {err}") raise finally: sys.path.pop(0) @@ -55,11 +54,9 @@ def get_version(package_dir, package): return ".".join(map(str, version)).strip() raise Exception( - ( "I only know how to look at a __version__ that is a str, " "an Increment Version, or a tuple. If you can't provide " "that, use the --version argument and specify one." - ) ) diff --git a/src/towncrier/_settings/fragment_types.py b/src/towncrier/_settings/fragment_types.py index 5eb28600..3262b4ac 100644 --- a/src/towncrier/_settings/fragment_types.py +++ b/src/towncrier/_settings/fragment_types.py @@ -34,11 +34,11 @@ class DefaultFragmentTypesLoader(BaseFragmentTypesLoader): _default_types = clt.OrderedDict( [ - (u"feature", {"name": u"Features", "showcontent": True}), - (u"bugfix", {"name": u"Bugfixes", "showcontent": True}), - (u"doc", {"name": u"Improved Documentation", "showcontent": True}), - (u"removal", {"name": u"Deprecations and Removals", "showcontent": True}), - (u"misc", {"name": u"Misc", "showcontent": False}), + ("feature", {"name": "Features", "showcontent": True}), + ("bugfix", {"name": "Bugfixes", "showcontent": True}), + ("doc", {"name": "Improved Documentation", "showcontent": True}), + ("removal", {"name": "Deprecations and Removals", "showcontent": True}), + ("misc", {"name": "Misc", "showcontent": False}), ] ) diff --git a/src/towncrier/_settings/load.py b/src/towncrier/_settings/load.py index 67a08e33..9fa8ee7f 100644 --- a/src/towncrier/_settings/load.py +++ b/src/towncrier/_settings/load.py @@ -14,10 +14,10 @@ class ConfigError(Exception): def __init__(self, *args, **kwargs): self.failing_option = kwargs.get("failing_option") - super(ConfigError, self).__init__(*args) + super().__init__(*args) -_start_string = u".. towncrier release notes start\n" +_start_string = ".. towncrier release notes start\n" _title_format = None _template_fname = "towncrier:default" _underlines = ["=", "-", "~"] @@ -40,7 +40,7 @@ def load_config_from_options(directory, config): if config is None: raise ConfigError( - "No configuration file found.\nLooked in: %s" % (base_directory,) + f"No configuration file found.\nLooked in: {base_directory}" ) return base_directory, config @@ -62,7 +62,7 @@ def load_config(directory): def load_config_from_file(directory, config_file): - with io.open(config_file, "rb") as conffile: + with open(config_file, "rb") as conffile: config = tomli.load(conffile) return parse_toml(directory, config) @@ -123,7 +123,7 @@ def parse_toml(base_path, config): if not os.path.exists(template): raise ConfigError( - "The template file '%s' does not exist." % (template,), + f"The template file '{template}' does not exist.", failing_option="template", ) diff --git a/src/towncrier/_writer.py b/src/towncrier/_writer.py index fbab7d0c..913e18f3 100644 --- a/src/towncrier/_writer.py +++ b/src/towncrier/_writer.py @@ -6,7 +6,6 @@ affecting existing content. """ -from __future__ import absolute_import, division import io import os @@ -20,13 +19,13 @@ def append_to_newsfile( if single_file: if not os.path.exists(news_file): - existing_content = u"" + existing_content = "" else: - with io.open(news_file, "r", encoding="utf8") as f: + with open(news_file, "r", encoding="utf8") as f: existing_content = f.read() existing_content = existing_content.split(start_string, 1) else: - existing_content = [u""] + existing_content = [""] if top_line and top_line in existing_content: raise ValueError("It seems you've already produced newsfiles for this version?") @@ -36,7 +35,7 @@ def append_to_newsfile( if len(existing_content) > 1: f.write(existing_content.pop(0).rstrip().encode("utf8")) if start_string: - f.write((u"\n\n" + start_string + u"\n").encode("utf8")) + f.write(("\n\n" + start_string + "\n").encode("utf8")) f.write(content.encode("utf8")) if existing_content: diff --git a/src/towncrier/build.py b/src/towncrier/build.py index 55695256..b85804ce 100644 --- a/src/towncrier/build.py +++ b/src/towncrier/build.py @@ -5,7 +5,6 @@ Build a combined news file from news fragments. """ -from __future__ import absolute_import, division, print_function import os import click diff --git a/src/towncrier/check.py b/src/towncrier/check.py index 4319d7b2..aaa71336 100644 --- a/src/towncrier/check.py +++ b/src/towncrier/check.py @@ -1,7 +1,6 @@ # Copyright (c) Amber Brown, 2018 # See LICENSE for details. -from __future__ import absolute_import, division import os import sys @@ -50,7 +49,7 @@ def __main(comparewith, directory, config): raise if not files_changed: - click.echo("On {} branch, or no diffs, so no newsfragment required.".format(comparewith)) + click.echo(f"On {comparewith} branch, or no diffs, so no newsfragment required.") sys.exit(0) files = { @@ -61,7 +60,7 @@ def __main(comparewith, directory, config): click.echo("Looking at these files:") click.echo("----") for n, change in enumerate(files, start=1): - click.echo("{}. {}".format(n, change)) + click.echo(f"{n}. {change}") click.echo("----") news_file = os.path.normpath(os.path.join(base_directory, config["filename"])) @@ -95,7 +94,7 @@ def __main(comparewith, directory, config): else: click.echo("Found:") for n, fragment in enumerate(fragments_in_branch, start=1): - click.echo("{}. {}".format(n, fragment)) + click.echo(f"{n}. {fragment}") sys.exit(0) diff --git a/src/towncrier/create.py b/src/towncrier/create.py index 2cc4a05b..82f47de6 100644 --- a/src/towncrier/create.py +++ b/src/towncrier/create.py @@ -5,7 +5,6 @@ Create a new fragment. """ -from __future__ import absolute_import import os import click @@ -69,7 +68,7 @@ def __main(ctx, directory, config, filename, edit, content): segment_file = os.path.join(fragments_directory, filename) if os.path.exists(segment_file): - raise click.ClickException("{} already exists".format(segment_file)) + raise click.ClickException(f"{segment_file} already exists") if edit: content = _get_news_content_from_user(content) @@ -81,7 +80,7 @@ def __main(ctx, directory, config, filename, edit, content): with open(segment_file, "w") as f: f.write(content) - click.echo("Created news fragment at {}".format(segment_file)) + click.echo(f"Created news fragment at {segment_file}") def _get_news_content_from_user(message): diff --git a/src/towncrier/test/test_build.py b/src/towncrier/test/test_build.py index 66a11230..8b9a8c61 100644 --- a/src/towncrier/test/test_build.py +++ b/src/towncrier/test/test_build.py @@ -185,8 +185,8 @@ def run_order_scenario(sections, types): sectdir = "news/" + section os.mkdir(sectdir) for type_ in types: - with open("{}/1.{}".format(sectdir, type_), "w") as f: - f.write("{} {}".format(section, type_)) + with open(f"{sectdir}/1.{type_}", "w") as f: + f.write(f"{section} {type_}") return runner.invoke( _main, ["--draft", "--date", "01-01-2001"], catch_exceptions=False @@ -196,10 +196,10 @@ def run_order_scenario(sections, types): self.assertEqual(0, result.exit_code) self.assertEqual( result.output, - u"Loading template...\nFinding news fragments...\nRendering news " - u"fragments...\nDraft only -- nothing has been written.\nWhat is " - u"seen below is what would be written.\n\nFoo 1.2.3 (01-01-2001)" - u"\n======================" + "Loading template...\nFinding news fragments...\nRendering news " + "fragments...\nDraft only -- nothing has been written.\nWhat is " + "seen below is what would be written.\n\nFoo 1.2.3 (01-01-2001)" + "\n======================" + dedent( """ section-a @@ -239,10 +239,10 @@ def run_order_scenario(sections, types): self.assertEqual(0, result.exit_code) self.assertEqual( result.output, - u"Loading template...\nFinding news fragments...\nRendering news " - u"fragments...\nDraft only -- nothing has been written.\nWhat is " - u"seen below is what would be written.\n\nFoo 1.2.3 (01-01-2001)" - u"\n======================" + "Loading template...\nFinding news fragments...\nRendering news " + "fragments...\nDraft only -- nothing has been written.\nWhat is " + "seen below is what would be written.\n\nFoo 1.2.3 (01-01-2001)" + "\n======================" + dedent( """ section-b @@ -532,7 +532,7 @@ def test_single_file(self): self.assertEqual(0, result.exit_code, result.output) self.assertTrue(os.path.exists("7.8.9-notes.rst"), os.listdir(".")) - with open("7.8.9-notes.rst", "r") as f: + with open("7.8.9-notes.rst") as f: output = f.read() self.assertEqual( @@ -601,7 +601,7 @@ def test_single_file_false(self): self.assertEqual(0, result.exit_code, result.output) self.assertTrue(os.path.exists("{version}-notes.rst"), os.listdir(".")) self.assertFalse(os.path.exists("7.8.9-notes.rst"), os.listdir(".")) - with open("{version}-notes.rst", "r") as f: + with open("{version}-notes.rst") as f: output = f.read() self.assertEqual( @@ -650,7 +650,7 @@ def test_bullet_points_false(self): ) self.assertEqual(0, result.exit_code, result.output) - with open("NEWS.rst", "r") as f: + with open("NEWS.rst") as f: output = f.read() self.assertEqual( @@ -823,7 +823,7 @@ def test_start_string(self): self.assertEqual(0, result.exit_code, result.output) self.assertTrue(os.path.exists("NEWS.rst"), os.listdir(".")) - with open("NEWS.rst", "r") as f: + with open("NEWS.rst") as f: output = f.read() expected_output = dedent("""\ diff --git a/src/towncrier/test/test_check.py b/src/towncrier/test/test_check.py index 19604ba4..06fa9df8 100644 --- a/src/towncrier/test/test_check.py +++ b/src/towncrier/test/test_check.py @@ -65,7 +65,7 @@ def initial_commit(branch='main'): """ # --initial-branch is explicitly set to `main` because # git has deprecated the default branch name. - call(["git", "init", "--initial-branch={}".format(branch)]) + call(["git", "init", f"--initial-branch={branch}"]) # Without ``git config` user.name and user.email `git commit` fails # unless the settings are set globally call(["git", "config", "user.name", "user"]) diff --git a/src/towncrier/test/test_create.py b/src/towncrier/test/test_create.py index 31ef226d..efa5b35a 100644 --- a/src/towncrier/test/test_create.py +++ b/src/towncrier/test/test_create.py @@ -3,9 +3,9 @@ import os from textwrap import dedent +from unittest import mock from twisted.trial.unittest import TestCase -import mock from click.testing import CliRunner diff --git a/src/towncrier/test/test_format.py b/src/towncrier/test/test_format.py index 26caa05c..1324b216 100644 --- a/src/towncrier/test/test_format.py +++ b/src/towncrier/test/test_format.py @@ -1,7 +1,6 @@ # Copyright (c) Amber Brown, 2015 # See LICENSE for details. -from __future__ import absolute_import, division import pkg_resources @@ -17,27 +16,27 @@ def test_split(self): fragments = { "": { - ("1", "misc", 0): u"", - ("baz", "misc", 0): u"", - ("2", "feature", 0): u"Foo added.", - ("5", "feature", 0): u"Foo added. \n", - ("6", "bugfix", 0): u"Foo added.", + ("1", "misc", 0): "", + ("baz", "misc", 0): "", + ("2", "feature", 0): "Foo added.", + ("5", "feature", 0): "Foo added. \n", + ("6", "bugfix", 0): "Foo added.", }, "Web": { - ("3", "bugfix", 0): u"Web fixed. ", - ("4", "feature", 0): u"Foo added.", + ("3", "bugfix", 0): "Web fixed. ", + ("4", "feature", 0): "Foo added.", }, } expected_output = { "": { "misc": {"": ["1", "baz"]}, - "feature": {u"Foo added.": ["2", "5"]}, - "bugfix": {u"Foo added.": ["6"]}, + "feature": {"Foo added.": ["2", "5"]}, + "bugfix": {"Foo added.": ["6"]}, }, "Web": { - "bugfix": {u"Web fixed.": ["3"]}, - "feature": {u"Foo added.": ["4"]}, + "bugfix": {"Web fixed.": ["3"]}, + "feature": {"Foo added.": ["4"]}, }, } @@ -65,19 +64,19 @@ def test_basic(self): { # asciibetical sorting will do 1, 142, 9 # we want 1, 9, 142 instead - ("142", "misc", 0): u"", - ("1", "misc", 0): u"", - ("9", "misc", 0): u"", - ("bar", "misc", 0): u"", - ("4", "feature", 0): u"Stuff!", - ("2", "feature", 0): u"Foo added.", - ("72", "feature", 0): u"Foo added.", - ("9", "feature", 0): u"Foo added.", - ("baz", "feature", 0): u"Fun!", + ("142", "misc", 0): "", + ("1", "misc", 0): "", + ("9", "misc", 0): "", + ("bar", "misc", 0): "", + ("4", "feature", 0): "Stuff!", + ("2", "feature", 0): "Foo added.", + ("72", "feature", 0): "Foo added.", + ("9", "feature", 0): "Foo added.", + ("baz", "feature", 0): "Fun!", }, ), ("Names", {}), - ("Web", {("3", "bugfix", 0): u"Web fixed."}), + ("Web", {("3", "bugfix", 0): "Web fixed."}), ] ) @@ -89,7 +88,7 @@ def test_basic(self): ] ) - expected_output = u"""MyProject 1.0 (never) + expected_output = """MyProject 1.0 (never) ===================== Features @@ -138,7 +137,7 @@ def test_basic(self): self.assertEqual(output, expected_output) # Check again with non-default underlines - expected_output_weird_underlines = u"""MyProject 1.0 (never) + expected_output_weird_underlines = """MyProject 1.0 (never) ===================== Features @@ -192,16 +191,16 @@ def test_issue_format(self): "": { # asciibetical sorting will do 1, 142, 9 # we want 1, 9, 142 instead - ("142", "misc", 0): u"", - ("1", "misc", 0): u"", - ("9", "misc", 0): u"", - ("bar", "misc", 0): u"", + ("142", "misc", 0): "", + ("1", "misc", 0): "", + ("9", "misc", 0): "", + ("bar", "misc", 0): "", } } definitions = OrderedDict([("misc", {"name": "Misc", "showcontent": False})]) - expected_output = u"""MyProject 1.0 (never) + expected_output = """MyProject 1.0 (never) ===================== Misc @@ -217,7 +216,7 @@ def test_issue_format(self): fragments = split_fragments(fragments, definitions) output = render_fragments( template, - u"xx{issue}", + "xx{issue}", fragments, definitions, ["-", "~"], @@ -239,11 +238,11 @@ def test_line_wrapping(self): "1", "feature", 0, - ): u""" + ): """ asdf asdf asdf asdf looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong newsfragment. """, # NOQA - ("2", "feature", 0): u"https://google.com/q=?" + u"-" * 100, - ("3", "feature", 0): u"a " * 80, + ("2", "feature", 0): "https://google.com/q=?" + "-" * 100, + ("3", "feature", 0): "a " * 80, } } @@ -251,7 +250,7 @@ def test_line_wrapping(self): [("feature", {"name": "Features", "showcontent": True})] ) - expected_output = u"""MyProject 1.0 (never) + expected_output = """MyProject 1.0 (never) ===================== Features @@ -296,11 +295,11 @@ def test_line_wrapping_disabled(self): "1", "feature", 0, - ): u""" + ): """ asdf asdf asdf asdf looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong newsfragment. """, # NOQA - ("2", "feature", 0): u"https://google.com/q=?" + u"-" * 100, - ("3", "feature", 0): u"a " * 80, + ("2", "feature", 0): "https://google.com/q=?" + "-" * 100, + ("3", "feature", 0): "a " * 80, } } @@ -308,7 +307,7 @@ def test_line_wrapping_disabled(self): [("feature", {"name": "Features", "showcontent": True})] ) - expected_output = u"""MyProject 1.0 (never) + expected_output = """MyProject 1.0 (never) ===================== Features diff --git a/src/towncrier/test/test_settings.py b/src/towncrier/test/test_settings.py index 2e0e0e28..7cfd9003 100644 --- a/src/towncrier/test/test_settings.py +++ b/src/towncrier/test/test_settings.py @@ -226,8 +226,8 @@ def test_custom_types_as_tables_array_deprecated(self): """ toml_content = textwrap.dedent(toml_content) expected = [ - (u"foo", {"name": u"Foo", "showcontent": False, }), - (u"spam", {"name": u"Spam", "showcontent": True, },), + ("foo", {"name": "Foo", "showcontent": False, }), + ("spam", {"name": "Spam", "showcontent": True, },), ] expected = clt.OrderedDict(expected) config = self.load_config_from_string(toml_content, ) @@ -253,9 +253,9 @@ def test_custom_types_as_tables(self): """ toml_content = textwrap.dedent(toml_content) expected = [ - (u"chore", {"name": u"Other Tasks", "showcontent": False, }), - (u"feat", {"name": u"Feat", "showcontent": True, }), - (u"fix", {"name": u"Fix", "showcontent": True, }), + ("chore", {"name": "Other Tasks", "showcontent": False, }), + ("feat", {"name": "Feat", "showcontent": True, }), + ("fix", {"name": "Fix", "showcontent": True, }), ] expected = clt.OrderedDict(expected) diff --git a/src/towncrier/test/test_write.py b/src/towncrier/test/test_write.py index 14287497..b3eddb58 100644 --- a/src/towncrier/test/test_write.py +++ b/src/towncrier/test/test_write.py @@ -22,17 +22,17 @@ def test_append_at_top(self): "", OrderedDict( [ - (("142", "misc", 0), u""), - (("1", "misc", 0), u""), - (("4", "feature", 0), u"Stuff!"), - (("4", "feature", 1), u"Second Stuff!"), - (("2", "feature", 0), u"Foo added."), - (("72", "feature", 0), u"Foo added."), + (("142", "misc", 0), ""), + (("1", "misc", 0), ""), + (("4", "feature", 0), "Stuff!"), + (("4", "feature", 1), "Second Stuff!"), + (("2", "feature", 0), "Foo added."), + (("72", "feature", 0), "Foo added."), ] ), ), ("Names", {}), - ("Web", {("3", "bugfix", 0): u"Web fixed."}), + ("Web", {("3", "bugfix", 0): "Web fixed."}), ] ) @@ -107,7 +107,7 @@ def test_append_at_top(self): ), ) - with open(os.path.join(tempdir, "NEWS.rst"), "r") as f: + with open(os.path.join(tempdir, "NEWS.rst")) as f: output = f.read() self.assertEqual(expected_output, output) @@ -122,16 +122,16 @@ def test_append_at_top_with_hint(self): ( "", { - ("142", "misc", 0): u"", - ("1", "misc", 0): u"", - ("4", "feature", 0): u"Stuff!", - ("2", "feature", 0): u"Foo added.", - ("72", "feature", 0): u"Foo added.", - ("99", "feature", 0): u"Foo! " * 100, + ("142", "misc", 0): "", + ("1", "misc", 0): "", + ("4", "feature", 0): "Stuff!", + ("2", "feature", 0): "Foo added.", + ("72", "feature", 0): "Foo added.", + ("99", "feature", 0): "Foo! " * 100, }, ), ("Names", {}), - ("Web", {("3", "bugfix", 0): u"Web fixed."}), + ("Web", {("3", "bugfix", 0): "Web fixed."}), ] ) @@ -193,10 +193,8 @@ def test_append_at_top_with_hint(self): with open(os.path.join(tempdir, "NEWS.rst"), "w") as f: f.write( - ( "Hello there! Here is some info.\n\n" ".. towncrier release notes start\nOld text.\n" - ) ) fragments = split_fragments(fragments, definitions) @@ -221,7 +219,7 @@ def test_append_at_top_with_hint(self): ), ) - with open(os.path.join(tempdir, "NEWS.rst"), "r") as f: + with open(os.path.join(tempdir, "NEWS.rst")) as f: output = f.read() self.assertEqual(expected_output, output) @@ -259,7 +257,7 @@ def test_multiple_file_no_start_string(self): content=content, ) - with open(os.path.join(tempdir, "NEWS.rst"), "r") as f: + with open(os.path.join(tempdir, "NEWS.rst")) as f: output = f.read() expected_output = dedent("""\ diff --git a/tox.ini b/tox.ini index 3c4746b5..2db10132 100644 --- a/tox.ini +++ b/tox.ini @@ -24,7 +24,6 @@ deps = Twisted coverage incremental - mock commands = python -V From fcf17451138550ff283be487a908b2aced0abf61 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 9 Apr 2022 09:52:29 +0200 Subject: [PATCH 2/7] More cruft --- admin/check_tag_version_match.py | 6 +++--- docs/conf.py | 19 +++++++++---------- setup.py | 1 - src/towncrier/_writer.py | 2 +- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/admin/check_tag_version_match.py b/admin/check_tag_version_match.py index a4596565..1fbd344f 100644 --- a/admin/check_tag_version_match.py +++ b/admin/check_tag_version_match.py @@ -21,14 +21,14 @@ run_version = sys.argv[1] if not run_version.startswith(TAG_PREFIX): - print("Not a twisted release tag name '{}.".format(run_version)) + print(f"Not a twisted release tag name '{run_version}.") sys.exit(1) run_version = run_version[len(TAG_PREFIX) :] if run_version != branch_version: - print("Branch is at '{}' while tag is '{}'".format(branch_version, run_version)) + print(f"Branch is at '{branch_version}' while tag is '{run_version}'") exit(1) -print("All good. Branch and tag versions match for '{}'.".format(branch_version)) +print(f"All good. Branch and tag versions match for '{branch_version}'.") sys.exit(0) diff --git a/docs/conf.py b/docs/conf.py index 56fff086..c6300a0c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Towncrier documentation build configuration file, created by # sphinx-quickstart on Mon Aug 21 20:46:13 2017. @@ -45,18 +44,18 @@ master_doc = 'index' # General information about the project. -project = u'Towncrier' -copyright = u'2017, Amber Brown' -author = u'Amber Brown' +project = 'Towncrier' +copyright = '2017, Amber Brown' +author = 'Amber Brown' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'17.08' +version = '17.08' # The full version, including alpha/beta/rc tags. -release = u'17.08' +release = '17.08' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -141,8 +140,8 @@ # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'Towncrier.tex', u'Towncrier Documentation', - u'Amber Brown', 'manual'), + (master_doc, 'Towncrier.tex', 'Towncrier Documentation', + 'Amber Brown', 'manual'), ] @@ -151,7 +150,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'towncrier', u'Towncrier Documentation', + (master_doc, 'towncrier', 'Towncrier Documentation', [author], 1) ] @@ -162,7 +161,7 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'Towncrier', u'Towncrier Documentation', + (master_doc, 'Towncrier', 'Towncrier Documentation', author, 'Towncrier', 'One line description of project.', 'Miscellaneous'), ] diff --git a/setup.py b/setup.py index 696ac747..3241e35a 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,5 @@ #!/usr/bin/env python -from __future__ import absolute_import, division, print_function from setuptools import setup, find_packages diff --git a/src/towncrier/_writer.py b/src/towncrier/_writer.py index 913e18f3..e4591b7c 100644 --- a/src/towncrier/_writer.py +++ b/src/towncrier/_writer.py @@ -21,7 +21,7 @@ def append_to_newsfile( if not os.path.exists(news_file): existing_content = "" else: - with open(news_file, "r", encoding="utf8") as f: + with open(news_file, encoding="utf8") as f: existing_content = f.read() existing_content = existing_content.split(start_string, 1) else: From 174636035c21a1f52a700a3c5b6fcbf9fab60b36 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 9 Apr 2022 10:07:24 +0200 Subject: [PATCH 3/7] Ensure blast stays off --- .pre-commit-config.yaml | 7 +++++++ MANIFEST.in | 1 + tox.ini | 8 +++++++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..e7ee28de --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,7 @@ +--- +repos: + - repo: https://github.com/asottile/pyupgrade + rev: v2.31.1 + hooks: + - id: pyupgrade + args: [--py37-plus] diff --git a/MANIFEST.in b/MANIFEST.in index f96a124a..f98a8d8a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -6,6 +6,7 @@ include pyproject.toml include tox.ini include tox_build.sh include tox_check-release.sh +include *.yaml recursive-include src *.rst exclude bin diff --git a/tox.ini b/tox.ini index 2db10132..4ad01f85 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = cov-erase, flake8, {pypy37,pypy38,py37,py38,py39,py310}-tests, flake8, check-manifest, check-newsfragment, cov-report +envlist = cov-erase, flake8, pre-commit, {pypy37,pypy38,py37,py38,py39,py310}-tests, flake8, check-manifest, check-newsfragment, cov-report isolated_build=true skip_missing_envs = true @@ -10,6 +10,12 @@ deps = commands = flake8 src/towncrier/ +[testenv:pre-commit] +skip_install = True +deps = pre-commit +commands = + pre-commit run --all-files --verbose + [testenv:check-newsfragment] commands = python -m towncrier.check From 2784f3eec611c7b68b64af07a4f23ae0d3148cab Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 9 Apr 2022 10:08:28 +0200 Subject: [PATCH 4/7] Run in CI too --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4fc71bca..4cabc95d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -134,6 +134,8 @@ jobs: tox: flake8 - name: Check Newsfragment tox: check-newsfragment + - name: Run pre-commit hooks + tox: pre-commit steps: - uses: actions/checkout@v2 From 415380cf1e4541db7e076c9748024972f062a329 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 9 Apr 2022 10:20:31 +0200 Subject: [PATCH 5/7] Add newsfragment --- src/towncrier/newsfragments/380.misc.rst | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/towncrier/newsfragments/380.misc.rst diff --git a/src/towncrier/newsfragments/380.misc.rst b/src/towncrier/newsfragments/380.misc.rst new file mode 100644 index 00000000..e69de29b From b15f9872f3d7bd6c845e834e08cc5a24106947d0 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 9 Apr 2022 10:40:18 +0200 Subject: [PATCH 6/7] Remove unused imports --- src/towncrier/_settings/load.py | 1 - src/towncrier/_writer.py | 1 - 2 files changed, 2 deletions(-) diff --git a/src/towncrier/_settings/load.py b/src/towncrier/_settings/load.py index 9fa8ee7f..2562e9be 100644 --- a/src/towncrier/_settings/load.py +++ b/src/towncrier/_settings/load.py @@ -1,7 +1,6 @@ # Copyright (c) Amber Brown, 2015 # See LICENSE for details. -import io import os import pkg_resources diff --git a/src/towncrier/_writer.py b/src/towncrier/_writer.py index e4591b7c..4b58b20a 100644 --- a/src/towncrier/_writer.py +++ b/src/towncrier/_writer.py @@ -7,7 +7,6 @@ """ -import io import os From 425325f51a65d224e35a5ee3c71ccac61d146a4e Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Sun, 10 Apr 2022 16:36:14 +0100 Subject: [PATCH 7/7] Update test to update the coverage. --- src/towncrier/test/test_build.py | 67 +++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/src/towncrier/test/test_build.py b/src/towncrier/test/test_build.py index 8b9a8c61..0b45a924 100644 --- a/src/towncrier/test/test_build.py +++ b/src/towncrier/test/test_build.py @@ -622,6 +622,9 @@ def test_single_file_false(self): def test_bullet_points_false(self): """ When all_bullets is false, subsequent lines are not indented. + + The automatic ticket number inserted by towcier will allign with the + manual bullet. """ runner = CliRunner() @@ -634,7 +637,24 @@ def test_bullet_points_false(self): ) os.mkdir("newsfragments") with open("newsfragments/123.feature", "w") as f: - f.write("wow!\n~~~~\n\nAdds levitation.") + f.write( + "wow!\n" + "~~~~\n" + "\n" + "No indentation at all." + ) + with open("newsfragments/124.bugfix", "w") as f: + f.write( + "#. Numbered bullet list." + ) + with open("newsfragments/125.removal", "w") as f: + f.write( + "- Hyphen based bullet list." + ) + with open("newsfragments/126.doc", "w") as f: + f.write( + "* Asterisk based bullet list." + ) result = runner.invoke( _main, @@ -650,26 +670,45 @@ def test_bullet_points_false(self): ) self.assertEqual(0, result.exit_code, result.output) - with open("NEWS.rst") as f: + with open("NEWS.rst", "r") as f: output = f.read() self.assertEqual( output, - dedent( - """ - foo 7.8.9 (01-01-2001) - ====================== + """ +foo 7.8.9 (01-01-2001) +====================== - Features - -------- +Features +-------- - wow! - ~~~~ +wow! +~~~~ - Adds levitation. - (#123) - """ - ).lstrip(), +No indentation at all. +(#123) + + +Bugfixes +-------- + +#. Numbered bullet list. + (#124) + + +Improved Documentation +---------------------- + +* Asterisk based bullet list. + (#126) + + +Deprecations and Removals +------------------------- + +- Hyphen based bullet list. + (#125) +""".lstrip(), ) def test_title_format_custom(self):