Skip to content

Commit

Permalink
Merge pull request #380 from hynek/drop-cruft
Browse files Browse the repository at this point in the history
Drop compat cruft
  • Loading branch information
adiroiban authored Apr 10, 2022
2 parents aead491 + 425325f commit 2e2208d
Show file tree
Hide file tree
Showing 22 changed files with 189 additions and 150 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.1
hooks:
- id: pyupgrade
args: [--py37-plus]
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions admin/check_tag_version_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
19 changes: 9 additions & 10 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Towncrier documentation build configuration file, created by
# sphinx-quickstart on Mon Aug 21 20:46:13 2017.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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'),
]


Expand All @@ -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)
]

Expand All @@ -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'),
]
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python

from __future__ import absolute_import, division, print_function

from setuptools import setup, find_packages

Expand Down
27 changes: 13 additions & 14 deletions src/towncrier/_builder.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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())

Expand All @@ -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)
Expand All @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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"
7 changes: 2 additions & 5 deletions src/towncrier/_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Responsible for getting the version and name from a project.
"""

from __future__ import absolute_import, division

import sys

Expand All @@ -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)
Expand All @@ -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."
)
)


Expand Down
10 changes: 5 additions & 5 deletions src/towncrier/_settings/fragment_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}),
]
)

Expand Down
11 changes: 5 additions & 6 deletions src/towncrier/_settings/load.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (c) Amber Brown, 2015
# See LICENSE for details.

import io
import os
import pkg_resources

Expand All @@ -14,10 +13,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 = ["=", "-", "~"]
Expand All @@ -40,7 +39,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
Expand All @@ -62,7 +61,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)
Expand Down Expand Up @@ -123,7 +122,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",
)

Expand Down
10 changes: 4 additions & 6 deletions src/towncrier/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
affecting existing content.
"""

from __future__ import absolute_import, division

import io
import os


Expand All @@ -20,13 +18,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, 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?")
Expand All @@ -36,7 +34,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:
Expand Down
1 change: 0 additions & 1 deletion src/towncrier/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Build a combined news file from news fragments.
"""

from __future__ import absolute_import, division, print_function

import os
import click
Expand Down
7 changes: 3 additions & 4 deletions src/towncrier/check.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (c) Amber Brown, 2018
# See LICENSE for details.

from __future__ import absolute_import, division

import os
import sys
Expand Down Expand Up @@ -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 = {
Expand All @@ -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"]))
Expand Down Expand Up @@ -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)


Expand Down
Loading

0 comments on commit 2e2208d

Please sign in to comment.