Skip to content

Commit

Permalink
Tighten linting
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Feb 13, 2024
1 parent 5f10e6d commit 0a589ba
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 195 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ ci:

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

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.0
rev: v0.2.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
140 changes: 0 additions & 140 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@
# Usually you set "language" from the command line for these cases.
language = "en"

# 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"]
Expand All @@ -81,24 +75,10 @@
# 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

# Move type hints into the description block, instead of the func definition.
autodoc_typehints = "description"
autodoc_typehints_description_target = "documented"

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

# 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

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False

Expand All @@ -117,106 +97,21 @@
html_static_path = ["_static"]
html_css_files = ["custom.css"]

# Add any paths that contain custom themes here, relative to this directory.
# html_theme_path = []

# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
# html_title = None

# A shorter title for the navigation bar. Default is the same as html_title.
# html_short_title = None

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

# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
# html_favicon = None

# 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 = []

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
# html_extra_path = []

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
# html_last_updated_fmt = '%b %d, %Y'

# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
html_use_smartypants = True

# Custom sidebar templates, maps document names to template names.
# html_sidebars = {}

# Additional templates that should be rendered to pages, maps page names to
# template names.
# html_additional_pages = {}

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

# If false, no index is generated.
# html_use_index = True

# If true, the index is split into individual pages for each letter.
# html_split_index = False

# If true, links to the reST sources are added to the pages.
# html_show_sourcelink = True

# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
# html_show_sphinx = True

# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
# html_show_copyright = True

# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
# html_use_opensearch = ''

# This is the file name suffix for HTML files (e.g. ".xhtml").
# html_file_suffix = None

# Language to be used for generating the HTML full-text search index.
# Sphinx supports the following languages:
# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja'
# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr'
# html_search_language = 'en'

# A dictionary with options for the search language support, empty by default.
# Now only 'ja' uses this config value
# html_search_options = {'type': 'default'}

# The name of a javascript file (relative to the configuration directory) that
# implements a search results scorer. If empty, the default will be used.
# html_search_scorer = 'scorer.js'

# Output file base name for HTML help builder.
htmlhelp_basename = "environ-configdoc"

# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
# 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',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
Expand All @@ -230,26 +125,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 ---------------------------------------

Expand All @@ -259,9 +134,6 @@
(master_doc, "environ-config", "environ-config Documentation", [author], 1)
]

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


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

Expand All @@ -280,18 +152,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


# Refer to the Python standard library.and attrts
intersphinx_mapping = {
Expand Down
51 changes: 27 additions & 24 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,39 +149,42 @@ text = """
src = ["src", "tests", "noxfile.py"]

[tool.ruff.lint]
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
]
select = ["ALL"]

ignore = [
"E501", # leave line-length enforcement to Black
"RUF001", # leave my smart characters alone
"A001", # shadowing is fine
"A002", # shadowing is fine
"ANN", # Mypy is better at this
"ARG001", # unused arguments are normal when implementing interfaces
"ARG002", # unused arguments are normal when implementing interfaces
"COM", # Black takes care of our commas
"D", # We prefer our own docstring style.
"E501", # leave line-length enforcement to Black
"FBT", # bools are fine
"INP001", # sometimes we want Python files outside of packages
"PLR0913", # sometimes 6 arguments are ok
"RUF001", # leave my smart characters alone
"SLF001", # private members are accessed by friendly functions
"TCH", # TYPE_CHECKING blocks break autodocs
"TID252", # relative imports are always awesome
]

[tool.ruff.lint.per-file-ignores]
"tests/*" = [
"ARG005", # we need stub lambdas
"B018", # useless statements can be actually useful
"EM101", # no need for exception msg hygiene 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
"PLR2004", # magic constants are fine in tests
"S101", # assert
"S104", # Possible binding to all interfaces
"SIM300", # Yoda rocks in tests
"SIM300", # Yoda rocks in asserts
"TRY002", # stock exceptions are fine in tests
]
"noxfile.py" = [
"ERA001", # Cog uses commented out code
]

[tool.ruff.lint.isort]
Expand Down
3 changes: 2 additions & 1 deletion src/environ/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,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
8 changes: 2 additions & 6 deletions src/environ/_environ_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,7 @@ def _generate_var_name(prefix, field_name):
field_name: the name of the field from which the variable is derived
"""
return (
"_".join((prefix, field_name)).upper()
if prefix
else field_name.upper()
)
return f"{prefix}_{field_name}".upper() if prefix else field_name.upper()


def _generate_new_prefix(current_prefix, class_name):
Expand All @@ -413,7 +409,7 @@ def _generate_new_prefix(current_prefix, class_name):
field_name: the name of the field from which the variable is derived
"""
return (
"_".join((current_prefix, class_name)).upper()
f"{current_prefix}_{class_name}".upper()
if current_prefix
else class_name.upper()
)
Expand Down
18 changes: 8 additions & 10 deletions src/environ/secrets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from __future__ import annotations

import logging
import os
import sys

from configparser import NoOptionError, RawConfigParser
Expand All @@ -33,7 +32,7 @@
from environ._environ_config import CNF_KEY, RAISE, _ConfigEntry
from environ.exceptions import MissingSecretImplementationError

from ._utils import _get_default_secret, _open_file
from ._utils import _get_default_secret


try:
Expand All @@ -42,9 +41,8 @@

class SecretsManagerSecrets:
def secret(self, *args, **kwargs):
raise MissingSecretImplementationError(
"AWS secrets manager requires boto3"
)
msg = "AWS secrets manager requires boto3"
raise MissingSecretImplementationError(msg)


__all__ = [
Expand Down Expand Up @@ -231,13 +229,11 @@ def _get(self, environ, metadata, prefix, name) -> _SecretStr:
else:
secrets_dir = self.secrets_dir

secret_path = os.path.join(secrets_dir, filename)
secret_path = Path(secrets_dir) / filename
log.debug("looking for secret in file '%s'.", secret_path)

try:
with _open_file(secret_path) as f:
val = f.read()
return _SecretStr(val)
return _SecretStr(secret_path.read_text())
except FileOpenError:
return _get_default_secret(filename, ce.default)

Expand Down Expand Up @@ -295,6 +291,8 @@ class _SecretStr(str):
String that censors its __repr__ if called from an attrs repr.
"""

__slots__ = ()

def __repr__(self) -> str:
# The frame numbers varies across attrs versions. Use this convoluted
# form to make the call lazy.
Expand All @@ -320,7 +318,7 @@ def _load_ini(path: str) -> RawConfigParser:
Load an INI file from *path*.
"""
cfg = RawConfigParser()
with _open_file(path) as f:
with Path(path).open() as f:
cfg.read_file(f)

return cfg
Loading

0 comments on commit 0a589ba

Please sign in to comment.