diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7a65eaf..4ffa2f3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,7 @@ repos: args: [--branch, main] - id: trailing-whitespace - repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.9.0 # Use the ref you want to point at + rev: v1.10.0 hooks: - id: python-check-blanket-noqa - id: python-check-mock-methods @@ -25,26 +25,21 @@ repos: - id: python-no-log-warn - id: python-use-type-annotations - id: text-unicode-replacement-char -- repo: https://github.com/asottile/pyupgrade - rev: v3.3.1 - hooks: - - id: pyupgrade - args: [--py37-plus] - repo: https://github.com/asottile/reorder_python_imports rev: v3.9.0 hooks: - id: reorder-python-imports args: [--py37-plus, --add-import, 'from __future__ import annotations'] - repo: https://github.com/psf/black - rev: 22.12.0 + rev: 23.1.0 hooks: - id: black - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.205 + rev: v0.0.244 hooks: - id: ruff - repo: https://github.com/dosisod/refurb - rev: v1.9.1 + rev: v1.12.0 hooks: - id: refurb args: [--ignore, FURB126] @@ -52,11 +47,6 @@ repos: rev: v2.2.0 hooks: - id: setup-cfg-fmt -- repo: https://github.com/PyCQA/docformatter - rev: v1.5.1 - hooks: - - id: docformatter - args: [--in-place, --wrap-summaries, "88", --wrap-descriptions, "88", --blank] - repo: https://github.com/econchick/interrogate rev: 1.5.0 hooks: @@ -77,6 +67,20 @@ repos: - id: codespell args: [-L als, -L unparseable] additional_dependencies: ["tomli"] +- repo: https://github.com/pre-commit/mirrors-mypy + rev: 'v1.0.0' + hooks: + - id: mypy + args: [ + --no-strict-optional, + --ignore-missing-imports, + ] + additional_dependencies: [ + attrs>=21.3.0, + click, + types-setuptools + ] + pass_filenames: false - repo: https://github.com/mgedmin/check-manifest rev: "0.49" hooks: diff --git a/pyproject.toml b/pyproject.toml index 6e139a3..f5cf754 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,11 +7,29 @@ build-backend = "setuptools.build_meta" write_to = "src/pytask_environment/_version.py" +[tool.mypy] +files = ["src", "tests"] +check_untyped_defs = true +disallow_any_generics = true +disallow_incomplete_defs = true +disallow_untyped_defs = true +no_implicit_optional = true +warn_redundant_casts = true +warn_unused_ignores = true + + +[[tool.mypy.overrides]] +module = "tests.*" +disallow_untyped_defs = false +ignore_errors = true + + [tool.codespell] ignore-words-list = "falsy" [tool.ruff] +target-version = "py37" select = ["ALL"] fix = true extend-ignore = [ @@ -37,9 +55,13 @@ extend-ignore = [ "EM", # flake8-errmsg "ANN401", # flake8-annotate typing.Any "PD", # pandas-vet - "UP", # pyupgrade is too aggressive for py<3.10 + "COM812", # trailing comma missing, but black takes care of that + "D401", # imperative mood for first line. too many false-positives. + # Temporarily ignored. + "TCH002", ] [tool.ruff.per-file-ignores] -"tests/*" = ["D", "ANN"] +"tests/*" = ["D", "ANN", "PLR0913"] +"__init__.py" = ["D104"] diff --git a/src/pytask_environment/logging.py b/src/pytask_environment/logging.py index ad4cf8c..0736440 100644 --- a/src/pytask_environment/logging.py +++ b/src/pytask_environment/logging.py @@ -68,16 +68,16 @@ def pytask_log_session_header(session: Session) -> None: pass else: console.print() - raise Exception(msg + "\n\n" + _ERROR_MSG) from None + raise Exception(msg + "\n\n" + _ERROR_MSG) from None # noqa: TRY002 @orm.db_session -def retrieve_package(name: str) -> str: +def retrieve_package(name: str) -> str | None: """Return booleans indicating whether the version or path of a package changed.""" try: - package = Environment[name] + package = Environment[name] # type: ignore[type-arg, valid-type] except orm.ObjectNotFound: - package = None + package = None # type: ignore[misc] return package @@ -85,7 +85,7 @@ def retrieve_package(name: str) -> str: def create_or_update_state(name: str, version: str, path: str) -> None: """Create or update a state.""" try: - package_in_db = Environment[name] + package_in_db = Environment[name] # type: ignore[type-arg, valid-type] except orm.ObjectNotFound: Environment(name=name, version=version, path=path) else: diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_logging.py b/tests/test_logging.py index b8a5aef..6453b17 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -16,7 +16,7 @@ from _pytask.database_utils import db -@pytest.mark.end_to_end +@pytest.mark.end_to_end() def test_existence_of_python_executable_in_db(tmp_path, runner): """Test that the Python executable is stored in the database.""" task_path = tmp_path.joinpath("task_dummy.py") @@ -38,7 +38,7 @@ def test_existence_of_python_executable_in_db(tmp_path, runner): orm.delete(e for e in entity) -@pytest.mark.end_to_end +@pytest.mark.end_to_end() def test_flow_when_python_version_has_changed(monkeypatch, tmp_path, runner): """Test the whole use-case. @@ -96,8 +96,10 @@ def test_flow_when_python_version_has_changed(monkeypatch, tmp_path, runner): orm.delete(e for e in entity) -@pytest.mark.end_to_end -@pytest.mark.parametrize("check_python_version, expected", [("true", 1), ("false", 0)]) +@pytest.mark.end_to_end() +@pytest.mark.parametrize( + ("check_python_version", "expected"), [("true", 1), ("false", 0)] +) def test_python_version_changed( monkeypatch, tmp_path, runner, check_python_version, expected ): @@ -129,8 +131,10 @@ def test_python_version_changed( orm.delete(e for e in entity) -@pytest.mark.end_to_end -@pytest.mark.parametrize("check_python_version, expected", [("true", 1), ("false", 0)]) +@pytest.mark.end_to_end() +@pytest.mark.parametrize( + ("check_python_version", "expected"), [("true", 1), ("false", 0)] +) def test_environment_changed( monkeypatch, tmp_path, runner, check_python_version, expected ):