Skip to content

Commit

Permalink
chore(deps): pre-commit autoupdate (#604)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- https://github.com/charliermarsh/ruff-pre-commithttps://github.com/astral-sh/ruff-pre-commit
- [github.com/astral-sh/ruff-pre-commit: v0.0.270 → v0.0.284](astral-sh/ruff-pre-commit@v0.0.270...v0.0.284)
- [github.com/psf/black: 23.3.0 → 23.7.0](psf/black@23.3.0...23.7.0)
- [github.com/asottile/blacken-docs: 1.13.0 → 1.15.0](adamchainz/blacken-docs@1.13.0...1.15.0)
- [github.com/pre-commit/mirrors-prettier: v3.0.0-alpha.9-for-vscode → v3.0.1](pre-commit/mirrors-prettier@v3.0.0-alpha.9-for-vscode...v3.0.1)
- [github.com/pre-commit/mirrors-mypy: v1.3.0 → v1.5.0](pre-commit/mirrors-mypy@v1.3.0...v1.5.0)
- [github.com/commitizen-tools/commitizen: 3.2.2 → 3.6.0](commitizen-tools/commitizen@3.2.2...3.6.0)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* chore: fix ruff warnings

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: W. Augusto Andreoli <andreoliwa@gmail.com>
  • Loading branch information
pre-commit-ci[bot] and andreoliwa committed Aug 18, 2023
1 parent 45baf32 commit 24a1cc3
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 58 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ repos:
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.270
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.284
hooks:
- id: ruff
args: [--fix]
Expand All @@ -50,12 +50,12 @@ repos:
- id: sort-all
language_version: python3.8
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
rev: 1.15.0
hooks:
- id: blacken-docs
additional_dependencies: [black==22.1.0]
Expand All @@ -65,12 +65,12 @@ repos:
- id: python-check-mock-methods
- id: rst-backticks
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.9-for-vscode
rev: v3.0.1
hooks:
- id: prettier
stages: [commit]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.3.0
rev: v1.5.0
hooks:
- id: mypy
# https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-show-error-codes
Expand Down Expand Up @@ -109,7 +109,7 @@ repos:
# https://docs.openstack.org/bashate/latest/man/bashate.html#options
args: [-i, E006]
- repo: https://github.com/commitizen-tools/commitizen
rev: 3.2.2
rev: 3.6.0
hooks:
- id: commitizen
stages: [commit-msg]
4 changes: 1 addition & 3 deletions docs/autofix_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ def rst_table(header: tuple[str, ...], rows: list[tuple[str, ...]]) -> list[str]
def write_readme(file_types: set[FileType], divider: str) -> int:
"""Write the README."""
# TODO: chore: quickstart.rst has some parts of README.rst as a copy/paste/change
rows: list[tuple[str, ...]] = []
for file_type in sorted(file_types):
rows.append(file_type.row)
rows: list[tuple[str, ...]] = [file_type.row for file_type in sorted(file_types)]

lines = rst_table(("File type", "``nitpick check``", "``nitpick fix``"), rows)
return DocFile("../README.rst").write(lines, divider)
Expand Down
5 changes: 3 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
full list see the documentation:
http://www.sphinx-doc.org/en/master/config
"""
from __future__ import annotations

import os
from typing import Dict

# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
Expand Down Expand Up @@ -189,7 +190,7 @@

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

latex_elements: Dict[str, str] = {
latex_elements: dict[str, str] = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ ignore = [
"E402", # Module level import not at top of file
"E501", # Line too long
"FBT", # https://beta.ruff.rs/docs/rules/#flake8-boolean-trap-fbt
"FIX002", # Line contains TO-DO, consider resolving the issue
"TD002", # Missing author in TO DO
"TD003", # Missing issue link on the line following this TO DO
]
Expand Down
14 changes: 9 additions & 5 deletions src/nitpick/core.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""The Nitpick application."""
from __future__ import annotations

import os
from functools import lru_cache
from itertools import chain
from pathlib import Path
from typing import Iterator, List, Optional
from typing import TYPE_CHECKING, Iterator

import click
from loguru import logger
Expand All @@ -12,9 +14,11 @@
from nitpick.generic import filter_names, relative_to_current_dir
from nitpick.plugins.info import FileInfo
from nitpick.project import Project
from nitpick.typedefs import PathOrStr
from nitpick.violations import Fuss, ProjectViolations, Reporter

if TYPE_CHECKING:
from nitpick.typedefs import PathOrStr


class Nitpick:
"""The Nitpick API."""
Expand All @@ -32,14 +36,14 @@ def __init__(self) -> None:

@classmethod
@lru_cache
def singleton(cls) -> "Nitpick":
def singleton(cls) -> Nitpick:
"""Return a single instance of the class."""
Nitpick._allow_init = True
instance = cls()
Nitpick._allow_init = False
return instance

def init(self, project_root: Optional[PathOrStr] = None, offline: Optional[bool] = None) -> "Nitpick":
def init(self, project_root: PathOrStr | None = None, offline: bool | None = None) -> Nitpick:
"""Initialize attributes of the singleton."""
self.project = Project(project_root)

Expand Down Expand Up @@ -115,7 +119,7 @@ def enforce_style(self, *partial_names: str, autofix=True) -> Iterator[Fuss]:
for plugin_class in self.project.plugin_manager.hook.can_handle(info=info):
yield from plugin_class(info, config_dict, autofix).entry_point()

def configured_files(self, *partial_names: str) -> List[Path]:
def configured_files(self, *partial_names: str) -> list[Path]:
"""List of files configured in the Nitpick style. Filter only the selected partial names."""
return [Path(self.project.root) / key for key in filter_names(self.project.style_dict, *partial_names)]

Expand Down
4 changes: 2 additions & 2 deletions src/nitpick/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import abc
import fnmatch
from typing import TYPE_CHECKING, Iterator
from typing import TYPE_CHECKING, ClassVar, Iterator

from autorepr import autotext
from loguru import logger
Expand Down Expand Up @@ -43,7 +43,7 @@ class NitpickPlugin(metaclass=abc.ABCMeta): # pylint: disable=too-many-instance
validation_schema: Schema | None = None

#: Which ``identify`` tags this :py:class:`nitpick.plugins.base.NitpickPlugin` child recognises.
identify_tags: set[str] = set()
identify_tags: ClassVar = set()

skip_empty_suggestion = False

Expand Down
12 changes: 8 additions & 4 deletions src/nitpick/plugins/info.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
"""Info needed by the plugins."""
from __future__ import annotations

from dataclasses import dataclass, field
from typing import Set
from typing import TYPE_CHECKING

from identify import identify

from nitpick.constants import DOT
from nitpick.exceptions import Deprecation
from nitpick.project import Project

if TYPE_CHECKING:
from nitpick.project import Project


@dataclass
Expand All @@ -15,10 +19,10 @@ class FileInfo:

project: Project
path_from_root: str
tags: Set[str] = field(default_factory=set)
tags: set[str] = field(default_factory=set)

@classmethod
def create(cls, project: Project, path_from_root: str) -> "FileInfo":
def create(cls, project: Project, path_from_root: str) -> FileInfo:
"""Clean the file name and get its tags."""
if Deprecation.pre_commit_without_dash(path_from_root):
clean_path = DOT + path_from_root
Expand Down
4 changes: 2 additions & 2 deletions src/nitpick/plugins/ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from configparser import ConfigParser, DuplicateOptionError, Error, MissingSectionHeaderError, ParsingError
from io import StringIO
from typing import TYPE_CHECKING, Any, Iterator
from typing import TYPE_CHECKING, Any, ClassVar, Iterator

import dictdiffer
from configupdater import ConfigUpdater, Space
Expand Down Expand Up @@ -48,7 +48,7 @@ class IniPlugin(NitpickPlugin):
"""

fixable = True
identify_tags = {"ini", "editorconfig"}
identify_tags: ClassVar = {"ini", "editorconfig"}
violation_base_code = 320

updater: ConfigUpdater
Expand Down
6 changes: 3 additions & 3 deletions src/nitpick/plugins/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import json
from itertools import chain
from typing import TYPE_CHECKING, Iterator
from typing import TYPE_CHECKING, ClassVar, Iterator

from loguru import logger

Expand Down Expand Up @@ -38,7 +38,7 @@ class JsonPlugin(NitpickPlugin):
"""

validation_schema = JsonFileSchema
identify_tags = {"json"}
identify_tags: ClassVar = {"json"}
violation_base_code = 340
fixable = True

Expand Down Expand Up @@ -74,7 +74,7 @@ def expected_dict_from_contains_json(self):
for key, json_string in (self.expected_config.get(KEY_CONTAINS_JSON) or {}).items():
try:
expected_config[key] = json.loads(json_string)
except json.JSONDecodeError as err:
except json.JSONDecodeError as err: # noqa: PERF203
# This should not happen, because the style was already validated before.
# Maybe the NIP??? code was disabled by the user?
logger.error(f"{err} on {KEY_CONTAINS_JSON} while checking {self.file_path}")
Expand Down
8 changes: 4 additions & 4 deletions src/nitpick/plugins/text.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Text files."""
from __future__ import annotations

from typing import TYPE_CHECKING, Iterator
from typing import TYPE_CHECKING, ClassVar, Iterator

from marshmallow import Schema
from marshmallow.orderedset import OrderedSet
Expand All @@ -22,14 +22,14 @@
class TextItemSchema(Schema):
"""Validation schema for the object inside ``contains``."""

error_messages = {"unknown": help_message("Unknown configuration", TEXT_FILE_RTFD_PAGE)}
error_messages = {"unknown": help_message("Unknown configuration", TEXT_FILE_RTFD_PAGE)} # noqa: RUF012
line = fields.NonEmptyString()


class TextSchema(Schema):
"""Validation schema for the text file TOML configuration."""

error_messages = {"unknown": help_message("Unknown configuration", TEXT_FILE_RTFD_PAGE)}
error_messages = {"unknown": help_message("Unknown configuration", TEXT_FILE_RTFD_PAGE)} # noqa: RUF012
contains = fields.List(fields.Nested(TextItemSchema))


Expand All @@ -53,7 +53,7 @@ class TextPlugin(NitpickPlugin):
line = "def"
"""

identify_tags = {"text"}
identify_tags: ClassVar = {"text"}
validation_schema = TextSchema

#: All other files are also text files, and they already have a suggested content message
Expand Down
4 changes: 2 additions & 2 deletions src/nitpick/plugins/toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

from itertools import chain
from typing import TYPE_CHECKING, Iterator, cast
from typing import TYPE_CHECKING, ClassVar, Iterator, cast

from tomlkit import dumps, parse

Expand All @@ -29,7 +29,7 @@ class TomlPlugin(NitpickPlugin):
There are :ref:`many other examples here <library>`.
"""

identify_tags = {"toml"}
identify_tags: ClassVar = {"toml"}
violation_base_code = 310
fixable = True

Expand Down
4 changes: 2 additions & 2 deletions src/nitpick/plugins/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

from itertools import chain
from typing import TYPE_CHECKING, Iterator, cast
from typing import TYPE_CHECKING, ClassVar, Iterator, cast

from nitpick.blender import Comparison, YamlDoc, traverse_yaml_tree
from nitpick.config import SpecialConfig
Expand Down Expand Up @@ -47,7 +47,7 @@ class YamlPlugin(NitpickPlugin):
Nitpick will not validate hooks and missing keys as it did before; it's not the purpose of this package.
"""

identify_tags = {"yaml"}
identify_tags: ClassVar = {"yaml"}
violation_base_code = 360
fixable = True

Expand Down
2 changes: 1 addition & 1 deletion src/nitpick/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def find_main_python_file(root_dir: Path) -> Path:
class ToolNitpickSectionSchema(BaseNitpickSchema):
"""Validation schema for the ``[tool.nitpick]`` section on ``pyproject.toml``."""

error_messages = {"unknown": help_message("Unknown configuration", "configuration.html")}
error_messages = {"unknown": help_message("Unknown configuration", "configuration.html")} # noqa: RUF012

style = PolyField(deserialization_schema_selector=fields.string_or_list_field)
cache = fields.NonEmptyString()
Expand Down
18 changes: 11 additions & 7 deletions src/nitpick/schemas.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Marshmallow schemas."""
from typing import Dict
from __future__ import annotations

from marshmallow import Schema
from marshmallow_polyfield import PolyField
Expand All @@ -10,7 +10,7 @@
from nitpick.constants import READ_THE_DOCS_URL, SETUP_CFG


def flatten_marshmallow_errors(errors: Dict) -> str:
def flatten_marshmallow_errors(errors: dict) -> str:
"""Flatten Marshmallow errors to a string."""
formatted = []
for field, data in SortedDict(flatten_quotes(errors)).items():
Expand All @@ -32,29 +32,33 @@ def help_message(sentence: str, help_page: str) -> str:
class BaseNitpickSchema(Schema):
"""Base schema for all others, with default error messages."""

error_messages = {"unknown": help_message("Unknown configuration", "nitpick_section.html")}
error_messages = {"unknown": help_message("Unknown configuration", "nitpick_section.html")} # noqa: RUF012


class NitpickStylesSectionSchema(BaseNitpickSchema):
"""Validation schema for the ``[nitpick.styles]`` section on the style file."""

error_messages = {"unknown": help_message("Unknown configuration", "nitpick_section.html#nitpick-styles")}
error_messages = { # noqa: RUF012
"unknown": help_message("Unknown configuration", "nitpick_section.html#nitpick-styles")
}

include = PolyField(deserialization_schema_selector=fields.string_or_list_field)


class IniSchema(BaseNitpickSchema):
"""Validation schema for INI files."""

error_messages = {"unknown": help_message("Unknown configuration", "nitpick_section.html#comma-separated-values")}
error_messages = { # noqa: RUF012
"unknown": help_message("Unknown configuration", "nitpick_section.html#comma-separated-values")
}

comma_separated_values = fields.List(fields.String(validate=fields.validate_section_dot_field))


class NitpickFilesSectionSchema(BaseNitpickSchema):
"""Validation schema for the ``[nitpick.files]`` section on the style file."""

error_messages = {"unknown": help_message("Unknown file", "nitpick_section.html#nitpick-files")}
error_messages = {"unknown": help_message("Unknown file", "nitpick_section.html#nitpick-files")} # noqa: RUF012

absent = fields.Dict(fields.NonEmptyString, fields.String())
present = fields.Dict(fields.NonEmptyString, fields.String())
Expand All @@ -81,6 +85,6 @@ class NitpickSectionSchema(BaseNitpickSchema):
class BaseStyleSchema(Schema):
"""Base validation schema for style files. Dynamic fields will be added to it later."""

error_messages = {"unknown": help_message("Unknown file", "plugins.html")}
error_messages = {"unknown": help_message("Unknown file", "plugins.html")} # noqa: RUF012

nitpick = fields.Nested(NitpickSectionSchema)

0 comments on commit 24a1cc3

Please sign in to comment.