Skip to content

Commit

Permalink
Add black & isort to pre-commit
Browse files Browse the repository at this point in the history
Use the default 88 columns from Black while allowing for 99 columns for longer (doc)strings.
  • Loading branch information
hynek committed Apr 11, 2022
1 parent 3b52db7 commit 9a58911
Show file tree
Hide file tree
Showing 29 changed files with 264 additions and 169 deletions.
15 changes: 13 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,31 @@ ci:
autoupdate_schedule: monthly

repos:
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black

- repo: https://github.com/asottile/pyupgrade
rev: v2.31.1
rev: v2.32.0
hooks:
- id: pyupgrade
args: [--py37-plus]

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
additional_dependencies: [toml]

- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
language_version: python3.10

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand Down
2 changes: 1 addition & 1 deletion admin/canonicalize_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def cli(version):

release_candidate = None
if parsed_version.pre is not None:
if parsed_version.pre[0] == 'rc':
if parsed_version.pre[0] == "rc":
release_candidate = parsed_version.pre[1]

incremental_version = incremental.Version(
Expand Down
1 change: 1 addition & 0 deletions admin/check_tag_version_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import pep517.meta


TAG_PREFIX = "refs/tags/"

if len(sys.argv) < 2:
Expand Down
5 changes: 4 additions & 1 deletion bin/towncrier
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#! /usr/bin/env python3
# flake8: noqa

import sys
import os.path
import sys


srcdir = os.path.join(os.path.dirname(__file__), "..", "src")
sys.path.insert(0, srcdir)

import towncrier


towncrier._main()
61 changes: 30 additions & 31 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,30 @@
extensions = []

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'Towncrier'
copyright = '2017, Amber Brown'
author = '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 = '17.08'
version = "17.08"
# The full version, including alpha/beta/rc tags.
release = '17.08'
release = "17.08"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -67,10 +67,10 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
Expand All @@ -81,7 +81,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "alabaster"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand All @@ -92,28 +92,28 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# This is required for the alabaster theme
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
html_sidebars = {
'**': [
'about.html',
'navigation.html',
'relations.html', # needs 'show_related': True theme option to display
'searchbox.html',
'donate.html',
"**": [
"about.html",
"navigation.html",
"relations.html", # needs 'show_related': True theme option to display
"searchbox.html",
"donate.html",
]
}


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'Towncrierdoc'
htmlhelp_basename = "Towncrierdoc"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -122,15 +122,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -140,19 +137,15 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'Towncrier.tex', 'Towncrier Documentation',
'Amber Brown', 'manual'),
(master_doc, "Towncrier.tex", "Towncrier Documentation", "Amber Brown", "manual"),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'towncrier', 'Towncrier Documentation',
[author], 1)
]
man_pages = [(master_doc, "towncrier", "Towncrier Documentation", [author], 1)]


# -- Options for Texinfo output -------------------------------------------
Expand All @@ -161,7 +154,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'Towncrier', 'Towncrier Documentation',
author, 'Towncrier', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"Towncrier",
"Towncrier Documentation",
author,
"Towncrier",
"One line description of project.",
"Miscellaneous",
),
]
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ exclude = '''
)
'''


[tool.isort]
profile = "attrs"


[build-system]
requires = [
"setuptools ~= 44.1.1",
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env python


from setuptools import setup, find_packages

# If incremental is not present then setuptools just silently uses v0.0.0 so
# let's import it and fail instead.
import incremental # noqa

from setuptools import find_packages, setup


setup(
name="towncrier",
Expand Down
1 change: 1 addition & 0 deletions src/towncrier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

from ._version import __version__


__all__ = ["__version__"]
1 change: 1 addition & 0 deletions src/towncrier/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from towncrier._shell import cli


cli()
8 changes: 4 additions & 4 deletions src/towncrier/_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ def parse_newfragment_basename(basename, definitions):
# NOTE: This allows news fragment names like fix-1.2.3.feature or
# something-cool.feature.ext for projects that don't use ticket
# numbers in news fragment names.
ticket = strip_if_integer_string(parts[i-1])
ticket = strip_if_integer_string(parts[i - 1])
counter = 0
# Use the following part as the counter if it exists and is a valid
# digit.
if len(parts) > (i + 1) and parts[i+1].isdigit():
counter = int(parts[i+1])
if len(parts) > (i + 1) and parts[i + 1].isdigit():
counter = int(parts[i + 1])
return ticket, category, counter
else:
# No valid category found.
Expand Down Expand Up @@ -92,7 +92,7 @@ def find_fragments(base_directory, sections, fragment_directory, definitions):
files = os.listdir(section_dir)
except FileNotFoundError as e:
message = "Failed to list the news fragment files.\n{}".format(
''.join(traceback.format_exception_only(type(e), e)),
"".join(traceback.format_exception_only(type(e), e)),
)
raise ConfigError(message)

Expand Down
3 changes: 2 additions & 1 deletion src/towncrier/_git.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Copyright (c) Amber Brown, 2015
# See LICENSE for details.

import os

from subprocess import call

import os
import click


Expand Down
6 changes: 3 additions & 3 deletions src/towncrier/_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +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."
"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
1 change: 1 addition & 0 deletions src/towncrier/_settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from towncrier._settings import load


load_config = load.load_config
ConfigError = load.ConfigError
load_config_from_options = load.load_config_from_options
Expand Down
9 changes: 5 additions & 4 deletions src/towncrier/_settings/fragment_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def factory(cls, config):
return new

@abc.abstractmethod
def load(self,):
def load(self):
"""Load fragment types."""


Expand All @@ -42,7 +42,7 @@ class DefaultFragmentTypesLoader(BaseFragmentTypesLoader):
]
)

def load(self,):
def load(self):
"""Load default types."""
return self._default_types

Expand All @@ -64,7 +64,7 @@ class ArrayFragmentTypesLoader(BaseFragmentTypesLoader):
"""

def load(self,):
def load(self):
"""Load types from toml array of mappings."""

types = clt.OrderedDict()
Expand Down Expand Up @@ -104,12 +104,13 @@ class TableFragmentTypesLoader(BaseFragmentTypesLoader):
# The content will be shown.
"""

def __init__(self, config):
"""Initialize."""
self.config = config
self.fragment_options = config.get("fragment", {})

def load(self,):
def load(self):
"""Load types from nested mapping."""
fragment_types = self.fragment_options.keys()
fragment_types = sorted(fragment_types)
Expand Down
13 changes: 5 additions & 8 deletions src/towncrier/_settings/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
# See LICENSE for details.

import os
import pkg_resources

from collections import OrderedDict

import pkg_resources
import tomli

from collections import OrderedDict
from .._settings import fragment_types as ft


Expand Down Expand Up @@ -38,9 +39,7 @@ def load_config_from_options(directory, config):
config = load_config_from_file(os.path.dirname(config), config)

if config is None:
raise ConfigError(
f"No configuration file found.\nLooked in: {base_directory}"
)
raise ConfigError(f"No configuration file found.\nLooked in: {base_directory}")

return base_directory, config

Expand Down Expand Up @@ -79,9 +78,7 @@ def parse_toml(base_path, config):
sections[x.get("name", "")] = x["path"]
else:
sections[""] = ""
fragment_types_loader = ft.BaseFragmentTypesLoader.factory(
config
)
fragment_types_loader = ft.BaseFragmentTypesLoader.factory(config)
types = fragment_types_loader.load()

wrap = config.get("wrap", False)
Expand Down
Loading

0 comments on commit 9a58911

Please sign in to comment.