Skip to content

Commit

Permalink
Bump mypy, ruff versions
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
khaeru committed Jan 20, 2025
1 parent 3fa1191 commit 2d45f52
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 27 deletions.
15 changes: 4 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 2 additions & 3 deletions ixmp/backend/jdbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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]
Expand Down
7 changes: 3 additions & 4 deletions ixmp/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"
)


Expand Down Expand Up @@ -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(
Expand Down
5 changes: 2 additions & 3 deletions ixmp/tests/backend/test_jdbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down
8 changes: 4 additions & 4 deletions ixmp/tests/core/test_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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")

Expand Down
9 changes: 7 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ exclude_also = [
omit = ["ixmp/util/sphinx_linkcode_github.py"]

[tool.mypy]
exclude = [
"build/",
files = [
"doc",
"ixmp",
]

[[tool.mypy.overrides]]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2d45f52

Please sign in to comment.