Skip to content

Commit

Permalink
Tighten linting
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Apr 11, 2024
1 parent 5cf3b27 commit 5c365f6
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 182 deletions.
11 changes: 5 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
repos:
- repo: https://github.com/psf/black
rev: 23.12.1
rev: 24.3.0
hooks:
- id: black

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.13
rev: v0.3.6
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand All @@ -18,14 +18,13 @@ repos:
args: [-L, fo]

- repo: https://github.com/econchick/interrogate
rev: 1.5.0
rev: 1.7.0
hooks:
- id: interrogate
language_version: python3.11
args: [tests, -v]
args: [tests]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand Down
84 changes: 0 additions & 84 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
from importlib import metadata


# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
# sys.path.insert(0, os.path.abspath('.'))

# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
Expand Down Expand Up @@ -45,9 +35,6 @@
# The suffix of source filenames.
source_suffix = ".rst"

# The encoding of source files.
# source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = "index"

Expand All @@ -68,44 +55,10 @@
if "dev" in release:
release = version = "UNRELEASED"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
# language = None

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
# today = ''
# Else, today_fmt is used as the format for a strftime call.
# today_fmt = '%B %d, %Y'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ["_build"]

# The reST default role (used for this markup: `text`) to use for all
# documents.
# default_role = None

# If true, '()' will be appended to :func: etc. cross-reference text.
# add_function_parentheses = True

# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
# add_module_names = True

# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
# show_authors = False

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

# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []

# If true, keep warnings as "system message" paragraphs in the built documents.
# keep_warnings = False


# -- Options for HTML output ----------------------------------------------

Expand Down Expand Up @@ -142,27 +95,6 @@
)
]

# The name of an image file (relative to this directory) to place at the top of
# the title page.
# latex_logo = None

# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
# latex_use_parts = False

# If true, show page references after internal links.
# latex_show_pagerefs = False

# If true, show URL addresses after external links.
# latex_show_urls = False

# Documents to append as an appendix to all manuals.
# latex_appendices = []

# If false, no module index is generated.
# latex_domain_indices = True


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

# One entry per manual page. List of tuples
Expand All @@ -177,10 +109,6 @@
)
]

# If true, show URL addresses after external links.
# man_show_urls = False


# -- Options for Texinfo output -------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
Expand All @@ -198,18 +126,6 @@
)
]

# Documents to append as an appendix to all manuals.
# texinfo_appendices = []

# If false, no module index is generated.
# texinfo_domain_indices = True

# How to display URL addresses: 'footnote', 'no', or 'inline'.
# texinfo_show_urls = 'footnote'

# If true, do not generate a @detailmenu in the "Top" node's menu.
# texinfo_no_detailmenu = False


intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
Expand Down
60 changes: 31 additions & 29 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,43 +138,45 @@ line-length = 79

[tool.ruff]
src = ["src", "tests"]
select = [
"E", # pycodestyle
"W", # pycodestyle
"F", # Pyflakes
"UP", # pyupgrade
"N", # pep8-naming
"YTT", # flake8-2020
"S", # flake8-bandit
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"T10", # flake8-debugger
"ISC", # flake8-implicit-str-concat
"RET", # flake8-return
"SIM", # flake8-simplify
"DTZ", # flake8-datetimez
"I", # isort
"PGH", # pygrep-hooks
"PLC", # Pylint
"PIE", # flake8-pie
"RUF", # ruff
]

[tool.ruff.lint]
select = ["ALL"]
ignore = [
"RUF001", # leave my smart characters alone
"N801", # some artistic freedom when naming things after RFCs
"N802", # ditto
"A001", # shadowing is fine
"ANN", # Mypy is better at this
"ARG001", # we don't control all args passed in
"ARG005", # we need stub lambdas
"COM", # Black takes care of our commas
"D", # We prefer our own docstring style.
"E501", # leave line-length enforcement to Black
"FIX", # Yes, we want XXX as a marker.
"INP001", # sometimes we want Python files outside of packages
"N801", # some artistic freedom when naming things after RFCs
"N802", # ditto
"PLR2004", # numbers are sometimes fine
"RUF001", # leave my smart characters alone
"SLF001", # private members are accessed by friendly functions
"TCH", # TYPE_CHECKING blocks break autodocs
"TD", # we don't follow other people's todo style
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"tests/*" = [
"B018", # "useless" expressions can be useful in tests
"PLC1901", # empty strings are falsey, but are less specific in tests
"PT005", # we always add underscores and explicit name
"PT011", # broad is fine
"S101", # assert
"S301", # I know pickle is bad, but people use it.
"SIM300", # Yoda rocks in tests
"PLC1901", # empty strings are falsey, but are less specific in tests
"B018", # "useless" expressions can be useful in tests
"SIM300", # Yoda rocks in asserts
"TRY301", # tests need to raise exceptions
]
"docs/pyopenssl_example.py" = [
"T201", # print is fine in the example
"T203", # pprint is fine in the example
]

[tool.ruff.isort]
[tool.ruff.lint.isort]
lines-between-types = 1
lines-after-imports = 2

Expand Down
4 changes: 2 additions & 2 deletions src/service_identity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Verify service identities.
"""


from . import cryptography, hazmat, pyopenssl
from .exceptions import (
CertificateError,
Expand Down Expand Up @@ -38,7 +37,8 @@ def __getattr__(name: str) -> str:
"__email__": "",
}
if name not in dunder_to_metadata:
raise AttributeError(f"module {__name__} has no attribute {name}")
msg = f"module {__name__} has no attribute {name}"
raise AttributeError(msg)

import warnings

Expand Down
3 changes: 2 additions & 1 deletion src/service_identity/cryptography.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ def extract_patterns(cert: Certificate) -> Sequence[CertificatePattern]:
if isinstance(srv, IA5String):
ids.append(SRVPattern.from_bytes(srv.asOctets()))
else: # pragma: no cover
raise CertificateError("Unexpected certificate content.")
msg = "Unexpected certificate content."
raise CertificateError(msg)

return ids

Expand Down
Loading

0 comments on commit 5c365f6

Please sign in to comment.