Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#510)
Browse files Browse the repository at this point in the history
updates:
- [github.com/pre-commit/pre-commit-hooks: v4.3.0 → v4.4.0](pre-commit/pre-commit-hooks@v4.3.0...v4.4.0)
- [github.com/asottile/pyupgrade: v3.0.0 → v3.3.1](asottile/pyupgrade@v3.0.0...v3.3.1)
- [github.com/PyCQA/autoflake: v1.7.1 → v2.0.2](PyCQA/autoflake@v1.7.1...v2.0.2)
- [github.com/psf/black: 22.10.0 → 23.1.0](psf/black@22.10.0...23.1.0)
- [github.com/asottile/blacken-docs: v1.12.1 → 1.13.0](adamchainz/blacken-docs@v1.12.1...1.13.0)
- [github.com/PyCQA/isort: 5.10.1 → 5.12.0](PyCQA/isort@5.10.1...5.12.0)
- [github.com/pre-commit/pygrep-hooks: v1.9.0 → v1.10.0](pre-commit/pygrep-hooks@v1.9.0...v1.10.0)
- [github.com/pre-commit/mirrors-prettier: v3.0.0-alpha.1 → v3.0.0-alpha.6](pre-commit/mirrors-prettier@v3.0.0-alpha.1...v3.0.0-alpha.6)
- [github.com/PyCQA/flake8: 5.0.4 → 6.0.0](PyCQA/flake8@5.0.4...6.0.0)
- [github.com/pre-commit/mirrors-mypy: v0.982 → v1.1.1](pre-commit/mirrors-mypy@v0.982...v1.1.1)
- [github.com/PyCQA/bandit: 1.7.4 → 1.7.5](PyCQA/bandit@1.7.4...1.7.5)
- [github.com/shellcheck-py/shellcheck-py: v0.8.0.4 → v0.9.0.2](shellcheck-py/shellcheck-py@v0.8.0.4...v0.9.0.2)
- [github.com/commitizen-tools/commitizen: v2.35.0 → v2.42.1](commitizen-tools/commitizen@v2.35.0...v2.42.1)

* chore: update hooks and fix code
* ci: remove safety check (already done by https://github.com/andreoliwa/nitpick/security/dependabot)

---------

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 Mar 24, 2023
1 parent f0f5b87 commit dbc5eca
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 53 deletions.
28 changes: 15 additions & 13 deletions .pre-commit-config.yaml
Expand Up @@ -34,13 +34,13 @@ repos:
types: [python, toml]
stages: [commit]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v3.0.0
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py37-plus]
Expand All @@ -50,7 +50,7 @@ repos:
- id: sort-all
language_version: python3.8
- repo: https://github.com/PyCQA/autoflake
rev: v1.7.1
rev: v2.0.2
hooks:
- id: autoflake
args:
Expand All @@ -64,34 +64,36 @@ repos:
compat.py,
]
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 23.1.0
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/asottile/blacken-docs
rev: v1.12.1
rev: 1.13.0
hooks:
- id: blacken-docs
additional_dependencies: [black==22.1.0]
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
# To avoid ERROR: Package 'isort' requires a different Python: 3.7.12 not in '>=3.8.0'
language_version: python3.8
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-mock-methods
- id: python-no-eval
- id: python-no-log-warn
- id: rst-backticks
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.1
rev: v3.0.0-alpha.6
hooks:
- id: prettier
stages: [commit]
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
language_version: python3.8
Expand All @@ -110,7 +112,7 @@ repos:
yesqa,
]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.982
rev: v1.1.1
hooks:
- id: mypy
# https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-show-error-codes
Expand Down Expand Up @@ -139,13 +141,13 @@ repos:
types: [python]
exclude: tests/
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
rev: 1.7.5
hooks:
- id: bandit
args: [--ini, setup.cfg]
exclude: tests/
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.8.0.4
rev: v0.9.0.2
hooks:
- id: shellcheck
- repo: https://github.com/openstack/bashate
Expand All @@ -155,7 +157,7 @@ repos:
# https://docs.openstack.org/bashate/latest/man/bashate.html#options
args: [-i, E006]
- repo: https://github.com/commitizen-tools/commitizen
rev: v2.35.0
rev: v2.42.1
hooks:
- id: commitizen
stages: [commit-msg]
4 changes: 2 additions & 2 deletions .tool-versions
@@ -1,2 +1,2 @@
poetry 1.1.14
pre-commit 2.17.0
poetry 1.4.1
pre-commit 3.2.0
4 changes: 2 additions & 2 deletions docs/autofix_docs.py
Expand Up @@ -13,7 +13,7 @@
from pathlib import Path
from subprocess import check_output # nosec
from textwrap import dedent, indent
from typing import Dict, List, Set, Tuple, Union
from typing import Optional, Dict, List, Set, Tuple, Union

import attr
import click
Expand Down Expand Up @@ -145,7 +145,7 @@ def __init__(self, filename: str) -> None:
self.divider_end = RST_DIVIDER_END
self.divider_from_here = RST_DIVIDER_FROM_HERE

def write(self, lines: List[str], divider: str = None) -> int:
def write(self, lines: List[str], divider: Optional[str] = None) -> int:
"""Write content to the file."""
old_content = self.file.read_text()
if divider:
Expand Down
2 changes: 1 addition & 1 deletion docs/ideas/lab.py
Expand Up @@ -40,7 +40,7 @@ def convert(path_from_root: str):
return toml_doc.reformatted


def main():
def main() -> None:
"""Play around."""
for path in sorted(Path("docs/ideas/yaml").glob("*.toml")):
click.secho(str(path), fg="green")
Expand Down
12 changes: 7 additions & 5 deletions src/nitpick/blender.py
Expand Up @@ -66,7 +66,7 @@ def compare_lists_with_dictdiffer(
return changed_dict


def search_json(json_data: ElementData, jmespath_expression: ParsedResult | str, default: Any = None) -> Any:
def search_json(json_data: ElementData, jmespath_expression: ParsedResult | str, default: Any | None = None) -> Any:
"""Search a dictionary or list using a JMESPath expression. Return a default value if not found.
>>> data = {"root": {"app": [1, 2], "test": "something"}}
Expand Down Expand Up @@ -433,7 +433,9 @@ class BaseDoc(metaclass=abc.ABCMeta):

__repr__ = autorepr(["path"])

def __init__(self, *, path: PathOrStr = None, string: str = None, obj: JsonDict = None) -> None:
def __init__(
self, *, path: PathOrStr | None = None, string: str | None = None, obj: JsonDict | None = None
) -> None:
self.path = path
self._string = string
self._object = obj
Expand Down Expand Up @@ -486,9 +488,9 @@ class TomlDoc(BaseDoc):
def __init__(
self,
*,
path: PathOrStr = None,
string: str = None,
obj: JsonDict = None,
path: PathOrStr | None = None,
string: str | None = None,
obj: JsonDict | None = None,
use_tomlkit=False,
) -> None:
super().__init__(path=path, string=string, obj=obj)
Expand Down
2 changes: 1 addition & 1 deletion src/nitpick/cli.py
Expand Up @@ -50,7 +50,7 @@
help=OptionEnum.OFFLINE.value,
)
@click.version_option()
def nitpick_cli(project: Path = None, offline=False): # pylint: disable=unused-argument
def nitpick_cli(project: Path | None = None, offline=False): # pylint: disable=unused-argument
"""Enforce the same settings across multiple language-independent projects."""


Expand Down
11 changes: 4 additions & 7 deletions src/nitpick/core.py
Expand Up @@ -3,7 +3,7 @@
from functools import lru_cache
from itertools import chain
from pathlib import Path
from typing import TYPE_CHECKING, Iterator, List, Type
from typing import Iterator, List, Optional

import click
from loguru import logger
Expand All @@ -15,9 +15,6 @@
from nitpick.typedefs import PathOrStr
from nitpick.violations import Fuss, ProjectViolations, Reporter

if TYPE_CHECKING:
from nitpick.plugins import NitpickPlugin


class Nitpick:
"""The Nitpick API."""
Expand All @@ -26,7 +23,7 @@ class Nitpick:

project: Project

def __init__(self):
def __init__(self) -> None:
if not self._allow_init:
raise TypeError("This class cannot be instantiated directly. Use Nitpick.singleton().init(...) instead")

Expand All @@ -41,7 +38,7 @@ def singleton(cls) -> "Nitpick":
Nitpick._allow_init = False
return instance

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

Expand Down Expand Up @@ -114,7 +111,7 @@ def enforce_style(self, *partial_names: str, autofix=True) -> Iterator[Fuss]:
# 2.
info = FileInfo.create(self.project, config_key)
# pylint: disable=no-member
for plugin_class in self.project.plugin_manager.hook.can_handle(info=info): # type: Type[NitpickPlugin]
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]:
Expand Down
6 changes: 5 additions & 1 deletion src/nitpick/exceptions.py
Expand Up @@ -28,7 +28,9 @@ def pre_commit_without_dash(path_from_root: str) -> bool:
"""The pre-commit config should start with a dot on the config file."""
if path_from_root == PRE_COMMIT_CONFIG_YAML[1:]:
warnings.warn(
f'The section name for dotfiles should start with a dot: [".{path_from_root}"]', DeprecationWarning
f'The section name for dotfiles should start with a dot: [".{path_from_root}"]',
DeprecationWarning,
stacklevel=2,
)
return True

Expand All @@ -43,6 +45,7 @@ def jsonfile_section(style_errors: Dict[str, Any]) -> bool:
warnings.warn(
"The [nitpick.JSONFile] section is not needed anymore; just declare your JSON files directly",
DeprecationWarning,
stacklevel=2,
)
return True
return False
Expand All @@ -59,6 +62,7 @@ def pre_commit_repos_with_yaml_key() -> bool:
f"The {KEY_REPOS}.{KEY_YAML} key is not supported anymore."
" Check the documentation and please update your YAML styles",
DeprecationWarning,
stacklevel=2,
)
return True

Expand Down
2 changes: 1 addition & 1 deletion src/nitpick/generic.py
Expand Up @@ -16,7 +16,7 @@
from nitpick.typedefs import PathOrStr


def version_to_tuple(version: str = None) -> tuple[int, ...]:
def version_to_tuple(version: str | None = None) -> tuple[int, ...]:
"""Transform a version number into a tuple of integers, for comparison.
>>> version_to_tuple("")
Expand Down
2 changes: 1 addition & 1 deletion src/nitpick/plugins/__init__.py
Expand Up @@ -24,7 +24,7 @@


@hookspec
def plugin_class() -> type[NitpickPlugin]:
def plugin_class() -> type[NitpickPlugin]: # type: ignore[empty-body]
"""Return your plugin class here (it should inherit from :py:class:`nitpick.plugins.base.NitpickPlugin`)."""


Expand Down
4 changes: 2 additions & 2 deletions src/nitpick/plugins/base.py
Expand Up @@ -116,7 +116,7 @@ def _enforce_file_configuration(self):
if fuss:
yield fuss

def post_init(self):
def post_init(self): # noqa: B027
"""Hook for plugin initialization after the instance was created.
The name mimics ``__post_init__()`` on dataclasses, without the magic double underscores:
Expand Down Expand Up @@ -147,7 +147,7 @@ def enforce_rules(self) -> Iterator[Fuss]:
def initial_contents(self) -> str:
"""Suggested initial content when the file doesn't exist."""

def write_initial_contents(self, doc_class: type[BaseDoc], expected_dict: dict = None) -> str:
def write_initial_contents(self, doc_class: type[BaseDoc], expected_dict: dict | None = None) -> str:
"""Helper to write initial contents based on a format."""
if not expected_dict:
expected_dict = self.expected_config
Expand Down
2 changes: 1 addition & 1 deletion src/nitpick/project.py
Expand Up @@ -110,7 +110,7 @@ class Project:
_plugin_manager: PluginManager
_confirmed_root: Path

def __init__(self, root: PathOrStr = None) -> None:
def __init__(self, root: PathOrStr | None = None) -> None:
self._chosen_root = root

self.style_dict: JsonDict = {}
Expand Down
2 changes: 1 addition & 1 deletion src/nitpick/violations.py
Expand Up @@ -107,7 +107,7 @@ class Reporter: # pylint: disable=too-few-public-methods
manual: int = 0
fixed: int = 0

def __init__(self, info: FileInfo = None, violation_base_code: int = 0) -> None:
def __init__(self, info: FileInfo | None = None, violation_base_code: int = 0) -> None:
self.info: FileInfo | None = info
self.violation_base_code = violation_base_code

Expand Down
2 changes: 1 addition & 1 deletion tasks.py
Expand Up @@ -283,7 +283,7 @@ def lab(c, convert_file_name="", lab_help=False):
- https://github.com/junegunn/fzf
- https://github.com/sharkdp/fd
"""
extra_args: List[str] = []
extra_args = []
if lab_help:
extra_args.append("--help")
if convert_file_name:
Expand Down
22 changes: 12 additions & 10 deletions tests/helpers.py
Expand Up @@ -85,7 +85,7 @@ def __init__(self, tmp_path: Path, **kwargs) -> None:
if kwargs.get("setup_py", True):
self.save_file("setup.py", "x = 1")

def create_symlink(self, link_name: str, target_dir: Path, target_file: str = None) -> ProjectMock:
def create_symlink(self, link_name: str, target_dir: Path, target_file: str | None = None) -> ProjectMock:
"""Create a symlink to a target file.
:param link_name: Link file name.
Expand Down Expand Up @@ -189,7 +189,7 @@ def read_multiple_files(self, filenames: Iterable[PathOrStr]) -> dict[PathOrStr,
"""Read multiple files and return a hash with filename (key) and contents (value)."""
return {filename: self.read_file(filename) for filename in filenames}

def save_file(self, filename: PathOrStr, file_contents: PathOrStr, lint: bool = None) -> ProjectMock:
def save_file(self, filename: PathOrStr, file_contents: PathOrStr, lint: bool | None = None) -> ProjectMock:
"""Save a file in the root dir with the desired contents and a new line at the end.
Create the parent dirs if the file name contains a slash.
Expand Down Expand Up @@ -251,7 +251,7 @@ def pre_commit(self, file_contents: PathOrStr) -> ProjectMock:
"""Save .pre-commit-config.yaml."""
return self.save_file(PRE_COMMIT_CONFIG_YAML, from_path_or_str(file_contents))

def raise_assertion_error(self, expected_error: str, assertion_message: str = None):
def raise_assertion_error(self, expected_error: str, assertion_message: str | None = None):
"""Show detailed errors in case of an assertion failure."""
if expected_error:
print(f"Expected error:\n<<<{expected_error}>>>")
Expand All @@ -268,15 +268,15 @@ def raise_assertion_error(self, expected_error: str, assertion_message: str = No
print("\nProject root:", self.root_dir)
raise AssertionError(assertion_message or expected_error)

def _assert_error_count(self, expected_error: str, expected_count: int = None) -> ProjectMock:
def _assert_error_count(self, expected_error: str, expected_count: int | None = None) -> ProjectMock:
"""Assert the error count is correct."""
if expected_count is not None:
actual = len(self._flake8_errors_as_string)
if expected_count != actual:
self.raise_assertion_error(expected_error, f"Expected {expected_count} errors, got {actual}")
return self

def assert_errors_contain(self, raw_error: str, expected_count: int = None) -> ProjectMock:
def assert_errors_contain(self, raw_error: str, expected_count: int | None = None) -> ProjectMock:
"""Assert the error is in the error set."""
expected_error = dedent(raw_error).strip()
if expected_error not in self._flake8_errors_as_string:
Expand Down Expand Up @@ -333,7 +333,9 @@ def assert_violations(self, *expected_violations: Fuss, disclaimer="") -> Projec
compare(expected=manual, actual=Reporter.manual)
return self

def _simulate_cli(self, command: str, expected_str_or_lines: StrOrList = None, *args: str, exit_code: int = None):
def _simulate_cli(
self, command: str, expected_str_or_lines: StrOrList | None = None, *args: str, exit_code: int | None = None
):
"""Simulate the CLI by invoking a click command.
1. If the command raised an exception that was not a common "system exit",
Expand All @@ -358,11 +360,11 @@ def _simulate_cli(self, command: str, expected_str_or_lines: StrOrList = None, *

def cli_run(
self,
expected_str_or_lines: StrOrList = None,
expected_str_or_lines: StrOrList | None = None,
autofix=False,
violations=0,
exception_class=None,
exit_code: int = None,
exit_code: int | None = None,
) -> ProjectMock:
"""Assert the expected CLI output for the chosen command."""
if exit_code is None:
Expand Down Expand Up @@ -393,13 +395,13 @@ def cli_run(
compare(actual=actual, expected=expected)
return self

def cli_ls(self, str_or_lines: StrOrList, *, exit_code: int = None) -> ProjectMock:
def cli_ls(self, str_or_lines: StrOrList, *, exit_code: int | None = None) -> ProjectMock:
"""Run the ls command and assert the output."""
result, actual, expected = self._simulate_cli("ls", str_or_lines, exit_code=exit_code)
compare(actual=actual, expected=expected, prefix=f"Result: {result}")
return self

def cli_init(self, str_or_lines: StrOrList, *args, exit_code: int = None) -> ProjectMock:
def cli_init(self, str_or_lines: StrOrList, *args, exit_code: int | None = None) -> ProjectMock:
"""Run the init command and assert the output."""
result, actual, expected = self._simulate_cli("init", str_or_lines, *args, exit_code=exit_code)
compare(actual=actual, expected=expected, prefix=f"Result: {result}")
Expand Down

0 comments on commit dbc5eca

Please sign in to comment.