From 2d45f528599b29671eb0043bbc06bcb2b409a1a0 Mon Sep 17 00:00:00 2001 From: Paul Natsuo Kishimoto Date: Thu, 16 Jan 2025 10:41:10 +0100 Subject: [PATCH] Bump mypy, ruff versions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ruff v1.9.0 → v1.14.1. - Drop custom hook entry that uses PRE_COMMIT_MYPY_VENV. - Use config suggested at python/mypy#13916. - ruff v0.3.4 → v0.9.1 - Reformat 4 files. - Temporarily exclude *.ipynb files covered by new version. --- .pre-commit-config.yaml | 15 ++++----------- ixmp/backend/jdbc.py | 5 ++--- ixmp/cli.py | 7 +++---- ixmp/tests/backend/test_jdbc.py | 5 ++--- ixmp/tests/core/test_scenario.py | 8 ++++---- pyproject.toml | 9 +++++++-- 6 files changed, 22 insertions(+), 27 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 89b28ca82..8cb52c583 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,27 +1,20 @@ repos: -- repo: local +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.14.1 hooks: - id: mypy - name: mypy - always_run: true - require_serial: true pass_filenames: false - - language: python - entry: bash -c ". ${PRE_COMMIT_MYPY_VENV:-/dev/null}/bin/activate 2>/dev/null; mypy $0 $@" additional_dependencies: - - mypy >= 1.9.0 - genno - GitPython - nbclient - pandas-stubs - pytest - - sphinx + - Sphinx - werkzeug - xarray - args: ["."] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.4 + rev: v0.9.1 hooks: - id: ruff - id: ruff-format diff --git a/ixmp/backend/jdbc.py b/ixmp/backend/jdbc.py index 5c4e83ad8..ac8c864dc 100644 --- a/ixmp/backend/jdbc.py +++ b/ixmp/backend/jdbc.py @@ -170,7 +170,7 @@ def _domain_enum(domain): return domain_enum.valueOf(domain.upper()) except java.IllegalArgumentException: domains = ", ".join([d.name().lower() for d in domain_enum.values()]) - raise ValueError(f"No such domain: {domain}, " f"existing domains: {domains}") + raise ValueError(f"No such domain: {domain}, existing domains: {domains}") def _unwrap(v): @@ -886,8 +886,7 @@ def clone( # Raise exceptions for limitations of JDBCBackend if not isinstance(platform_dest._backend, self.__class__): raise NotImplementedError( # pragma: no cover - f"Clone between {self.__class__} and" - f"{platform_dest._backend.__class__}" + f"Clone between {self.__class__} and{platform_dest._backend.__class__}" ) elif platform_dest._backend is not self: package = s.__class__.__module__.split(".")[0] diff --git a/ixmp/cli.py b/ixmp/cli.py index d4649d28b..9fa61d28c 100644 --- a/ixmp/cli.py +++ b/ixmp/cli.py @@ -91,7 +91,7 @@ def report(context, config, key): if not context: raise click.UsageError( - "give either --url, --platform or --dbprops " "before command report" + "give either --url, --platform or --dbprops before command report" ) # Instantiate the Reporter with the Scenario loaded by main() @@ -227,8 +227,7 @@ def import_group(context): """ if not context or "scen" not in context: raise click.UsageError( - "give --url, or --platform, --model, and " - "--scenario, before command import" + "give --url, or --platform, --model, and --scenario, before command import" ) @@ -407,7 +406,7 @@ def list_scenarios(context, **kwargs): if not context: raise click.UsageError( - "give either --url, --platform or --dbprops " "before command list" + "give either --url, --platform or --dbprops before command list" ) print( diff --git a/ixmp/tests/backend/test_jdbc.py b/ixmp/tests/backend/test_jdbc.py index efc765c27..3642ee80c 100644 --- a/ixmp/tests/backend/test_jdbc.py +++ b/ixmp/tests/backend/test_jdbc.py @@ -373,8 +373,7 @@ def test_verbose_exception(test_mp, exception_verbose_true): exc_msg = exc_info.value.args[0] assert ( - "There exists no Scenario 'foo|bar' " - "(version: -1) in the database!" in exc_msg + "There exists no Scenario 'foo|bar' (version: -1) in the database!" in exc_msg ) assert "at.ac.iiasa.ixmp.database.DbDAO.getRunId" in exc_msg assert "at.ac.iiasa.ixmp.Platform.getScenario" in exc_msg @@ -595,7 +594,7 @@ def test_reload_cycle( mp = ixmp.Platform(**platform_args) # Load existing Scenario - s0 = ixmp.Scenario(mp, model="foo", scenario=f"bar {i-1}", version=1) + s0 = ixmp.Scenario(mp, model="foo", scenario=f"bar {i - 1}", version=1) memory_usage(f"pass {i} -- platform instantiated") diff --git a/ixmp/tests/core/test_scenario.py b/ixmp/tests/core/test_scenario.py index 3592280f0..f2b17b1ef 100644 --- a/ixmp/tests/core/test_scenario.py +++ b/ixmp/tests/core/test_scenario.py @@ -137,7 +137,7 @@ def test_init_set(self, scen): # Add set on a locked scenario with pytest.raises( RuntimeError, - match="This Scenario cannot be edited" ", do a checkout first!", + match="This Scenario cannot be edited, do a checkout first!", ): scen.init_set("foo") @@ -399,7 +399,7 @@ def test_excel_io(self, scen, scen_empty, tmp_path, caplog): # With init_items=False, can't be read into an empty Scenario. # Exception raised is the first index set, alphabetically - with pytest.raises(ValueError, match="no set 'i'; " "try init_items=True"): + with pytest.raises(ValueError, match="no set 'i'; try init_items=True"): scen_empty.read_excel(tmp_path) # File can be read with init_items=True @@ -441,7 +441,7 @@ def test_excel_io(self, scen, scen_empty, tmp_path, caplog): # Fails with add_units=False with pytest.raises( - ValueError, match="The unit 'pounds' does not exist" " in the database!" + ValueError, match="The unit 'pounds' does not exist in the database!" ): s.read_excel(tmp_path, init_items=True) @@ -623,7 +623,7 @@ def test_set(scen_empty) -> None: scen.add_set("i", ["i9", "extra"], ["i9 comment"]) # Missing element in the index set with pytest.raises( - ValueError, match="The index set 'i' does not have an " "element 'bar'!" + ValueError, match="The index set 'i' does not have an element 'bar'!" ): scen.add_set("foo", "bar") diff --git a/pyproject.toml b/pyproject.toml index ede4e147c..3c322b8f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,8 +82,9 @@ exclude_also = [ omit = ["ixmp/util/sphinx_linkcode_github.py"] [tool.mypy] -exclude = [ - "build/", +files = [ + "doc", + "ixmp", ] [[tool.mypy.overrides]] @@ -111,6 +112,10 @@ markers = [ ] tmp_path_retention_policy = "none" +[tool.ruff] +# TEMPORARY Exclude tutorial files +extend-exclude = ["*.ipynb"] + [tool.ruff.lint] select = ["C9", "E", "F", "I", "W"] # FIXME the following exceed this limit