Skip to content

Update code quality configuration #555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 20, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Bump mypy, ruff versions
- 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
commit 2d45f528599b29671eb0043bbc06bcb2b409a1a0
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
5 changes: 2 additions & 3 deletions ixmp/backend/jdbc.py
Original file line number Diff line number Diff line change
@@ -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]
7 changes: 3 additions & 4 deletions ixmp/cli.py
Original file line number Diff line number Diff line change
@@ -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(
5 changes: 2 additions & 3 deletions ixmp/tests/backend/test_jdbc.py
Original file line number Diff line number Diff line change
@@ -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")

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

9 changes: 7 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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