From 8c9793b5cb155cb0febf6f570f6e8ae5fffc0397 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Feb 2023 21:31:17 +0000 Subject: [PATCH 1/5] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pygrep-hooks: v1.9.0 → v1.10.0](https://github.com/pre-commit/pygrep-hooks/compare/v1.9.0...v1.10.0) - [github.com/psf/black: 22.12.0 → 23.1.0](https://github.com/psf/black/compare/22.12.0...23.1.0) - [github.com/charliermarsh/ruff-pre-commit: v0.0.205 → v0.0.241](https://github.com/charliermarsh/ruff-pre-commit/compare/v0.0.205...v0.0.241) - [github.com/dosisod/refurb: v1.9.1 → v1.11.0](https://github.com/dosisod/refurb/compare/v1.9.1...v1.11.0) - [github.com/PyCQA/docformatter: v1.5.1 → v1.6.0.rc1](https://github.com/PyCQA/docformatter/compare/v1.5.1...v1.6.0.rc1) --- .pre-commit-config.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7a65eaf..e5ae4c4 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 # Use the ref you want to point at hooks: - id: python-check-blanket-noqa - id: python-check-mock-methods @@ -36,15 +36,15 @@ repos: - 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.241 hooks: - id: ruff - repo: https://github.com/dosisod/refurb - rev: v1.9.1 + rev: v1.11.0 hooks: - id: refurb args: [--ignore, FURB126] @@ -53,7 +53,7 @@ repos: hooks: - id: setup-cfg-fmt - repo: https://github.com/PyCQA/docformatter - rev: v1.5.1 + rev: v1.6.0.rc1 hooks: - id: docformatter args: [--in-place, --wrap-summaries, "88", --wrap-descriptions, "88", --blank] From 6859f2ca1994ce7b0338b7be3487f25941c0c6c1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Feb 2023 21:31:55 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pytask_environment/config.py | 4 ++-- tests/test_logging.py | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/pytask_environment/config.py b/src/pytask_environment/config.py index 85d517e..e83621e 100644 --- a/src/pytask_environment/config.py +++ b/src/pytask_environment/config.py @@ -17,7 +17,7 @@ def pytask_extend_command_line_interface(cli: click.Group) -> None: is_flag=True, default=None, help="Update the information on the environment stored in the database.", - ) + ), ) @@ -77,6 +77,6 @@ def _convert_truthy_or_falsy_to_bool(x: bool | str | None) -> bool: out = None else: raise ValueError( - f"Input {x!r} is neither truthy (True, true, 1) or falsy (False, false, 0)." + f"Input {x!r} is neither truthy (True, true, 1) or falsy (False, false, 0).", ) return out diff --git a/tests/test_logging.py b/tests/test_logging.py index a65afd4..84068fe 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -11,7 +11,7 @@ from pytask_environment.database import Environment -@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") @@ -33,13 +33,13 @@ 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() @pytest.mark.parametrize( - "config_file, content", + ("config_file", "content"), [("pytask.ini", "[pytask]"), ("pyproject.toml", "[tool.pytask.ini_options]")], ) def test_flow_when_python_version_has_changed( - monkeypatch, tmp_path, runner, config_file, content + monkeypatch, tmp_path, runner, config_file, content, ): """Test the whole use-case. @@ -97,9 +97,9 @@ def test_flow_when_python_version_has_changed( orm.delete(e for e in entity) -@pytest.mark.end_to_end +@pytest.mark.end_to_end() @pytest.mark.parametrize( - "config_file, content", + ("config_file", "content"), [ ("pytask.ini", "[pytask]\ncheck_python_version = {}"), ("pyproject.toml", "[tool.pytask.ini_options]\ncheck_python_version = {}"), @@ -107,7 +107,7 @@ def test_flow_when_python_version_has_changed( ) @pytest.mark.parametrize("check_python_version, expected", [("true", 1), ("false", 0)]) def test_python_version_changed( - monkeypatch, tmp_path, runner, config_file, content, check_python_version, expected + monkeypatch, tmp_path, runner, config_file, content, check_python_version, expected, ): fake_version = ( "2.7.8 | packaged by conda-forge | (default, Jul 31 2020, 01:53:57) " @@ -135,9 +135,9 @@ def test_python_version_changed( orm.delete(e for e in entity) -@pytest.mark.end_to_end +@pytest.mark.end_to_end() @pytest.mark.parametrize( - "config_file, content", + ("config_file", "content"), [ ("pytask.ini", "[pytask]\ncheck_environment = {}"), ("pyproject.toml", "[tool.pytask.ini_options]\ncheck_environment = {}"), @@ -145,7 +145,7 @@ def test_python_version_changed( ) @pytest.mark.parametrize("check_python_version, expected", [("true", 1), ("false", 0)]) def test_environment_changed( - monkeypatch, tmp_path, runner, config_file, content, check_python_version, expected + monkeypatch, tmp_path, runner, config_file, content, check_python_version, expected, ): tmp_path.joinpath(config_file).write_text(content.format(check_python_version)) source = "def task_dummy(): pass" From 6922b4d9faab00c70bc4ce762029e3a8b5a79835 Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Fri, 10 Feb 2023 17:14:00 +0100 Subject: [PATCH 3/5] revert changes. --- src/pytask_environment/config.py | 4 ++-- tests/test_logging.py | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/pytask_environment/config.py b/src/pytask_environment/config.py index e83621e..85d517e 100644 --- a/src/pytask_environment/config.py +++ b/src/pytask_environment/config.py @@ -17,7 +17,7 @@ def pytask_extend_command_line_interface(cli: click.Group) -> None: is_flag=True, default=None, help="Update the information on the environment stored in the database.", - ), + ) ) @@ -77,6 +77,6 @@ def _convert_truthy_or_falsy_to_bool(x: bool | str | None) -> bool: out = None else: raise ValueError( - f"Input {x!r} is neither truthy (True, true, 1) or falsy (False, false, 0).", + f"Input {x!r} is neither truthy (True, true, 1) or falsy (False, false, 0)." ) return out diff --git a/tests/test_logging.py b/tests/test_logging.py index 84068fe..a65afd4 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -11,7 +11,7 @@ from pytask_environment.database import Environment -@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") @@ -33,13 +33,13 @@ 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 @pytest.mark.parametrize( - ("config_file", "content"), + "config_file, content", [("pytask.ini", "[pytask]"), ("pyproject.toml", "[tool.pytask.ini_options]")], ) def test_flow_when_python_version_has_changed( - monkeypatch, tmp_path, runner, config_file, content, + monkeypatch, tmp_path, runner, config_file, content ): """Test the whole use-case. @@ -97,9 +97,9 @@ def test_flow_when_python_version_has_changed( orm.delete(e for e in entity) -@pytest.mark.end_to_end() +@pytest.mark.end_to_end @pytest.mark.parametrize( - ("config_file", "content"), + "config_file, content", [ ("pytask.ini", "[pytask]\ncheck_python_version = {}"), ("pyproject.toml", "[tool.pytask.ini_options]\ncheck_python_version = {}"), @@ -107,7 +107,7 @@ def test_flow_when_python_version_has_changed( ) @pytest.mark.parametrize("check_python_version, expected", [("true", 1), ("false", 0)]) def test_python_version_changed( - monkeypatch, tmp_path, runner, config_file, content, check_python_version, expected, + monkeypatch, tmp_path, runner, config_file, content, check_python_version, expected ): fake_version = ( "2.7.8 | packaged by conda-forge | (default, Jul 31 2020, 01:53:57) " @@ -135,9 +135,9 @@ def test_python_version_changed( orm.delete(e for e in entity) -@pytest.mark.end_to_end() +@pytest.mark.end_to_end @pytest.mark.parametrize( - ("config_file", "content"), + "config_file, content", [ ("pytask.ini", "[pytask]\ncheck_environment = {}"), ("pyproject.toml", "[tool.pytask.ini_options]\ncheck_environment = {}"), @@ -145,7 +145,7 @@ def test_python_version_changed( ) @pytest.mark.parametrize("check_python_version, expected", [("true", 1), ("false", 0)]) def test_environment_changed( - monkeypatch, tmp_path, runner, config_file, content, check_python_version, expected, + monkeypatch, tmp_path, runner, config_file, content, check_python_version, expected ): tmp_path.joinpath(config_file).write_text(content.format(check_python_version)) source = "def task_dummy(): pass" From 973b27713d8868dfca3f29029d2422d2e50e49ed Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Fri, 10 Feb 2023 17:22:00 +0100 Subject: [PATCH 4/5] Temp commit. --- .pre-commit-config.yaml | 30 +++++++++++++++++------------- pyproject.toml | 26 ++++++++++++++++++++++++-- tests/__init__.py | 0 tests/test_logging.py | 22 +++++++++++++--------- 4 files changed, 54 insertions(+), 24 deletions(-) create mode 100644 tests/__init__.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e5ae4c4..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.10.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,11 +25,6 @@ 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: @@ -40,11 +35,11 @@ repos: hooks: - id: black - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.241 + rev: v0.0.244 hooks: - id: ruff - repo: https://github.com/dosisod/refurb - rev: v1.11.0 + 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.6.0.rc1 - 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/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 a65afd4..bbac344 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -11,7 +11,7 @@ from pytask_environment.database import Environment -@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") @@ -33,9 +33,9 @@ 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() @pytest.mark.parametrize( - "config_file, content", + ("config_file", "content"), [("pytask.ini", "[pytask]"), ("pyproject.toml", "[tool.pytask.ini_options]")], ) def test_flow_when_python_version_has_changed( @@ -97,15 +97,17 @@ def test_flow_when_python_version_has_changed( orm.delete(e for e in entity) -@pytest.mark.end_to_end +@pytest.mark.end_to_end() @pytest.mark.parametrize( - "config_file, content", + ("config_file", "content"), [ ("pytask.ini", "[pytask]\ncheck_python_version = {}"), ("pyproject.toml", "[tool.pytask.ini_options]\ncheck_python_version = {}"), ], ) -@pytest.mark.parametrize("check_python_version, expected", [("true", 1), ("false", 0)]) +@pytest.mark.parametrize( + ("check_python_version", "expected"), [("true", 1), ("false", 0)] +) def test_python_version_changed( monkeypatch, tmp_path, runner, config_file, content, check_python_version, expected ): @@ -135,15 +137,17 @@ def test_python_version_changed( orm.delete(e for e in entity) -@pytest.mark.end_to_end +@pytest.mark.end_to_end() @pytest.mark.parametrize( - "config_file, content", + ("config_file", "content"), [ ("pytask.ini", "[pytask]\ncheck_environment = {}"), ("pyproject.toml", "[tool.pytask.ini_options]\ncheck_environment = {}"), ], ) -@pytest.mark.parametrize("check_python_version, expected", [("true", 1), ("false", 0)]) +@pytest.mark.parametrize( + ("check_python_version", "expected"), [("true", 1), ("false", 0)] +) def test_environment_changed( monkeypatch, tmp_path, runner, config_file, content, check_python_version, expected ): From 2825cec70334d32cedd1c1b2bb3a6af478313d7d Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Fri, 10 Feb 2023 17:35:14 +0100 Subject: [PATCH 5/5] Fix lints. --- src/pytask_environment/logging.py | 10 +++++----- tests/test_logging.py | 14 +++++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) 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/test_logging.py b/tests/test_logging.py index 8cd8122..6453b17 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.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 ):