Skip to content

Commit 61aff1c

Browse files
committed
Bump mypy, ruff versions
- mypy v1.13.0 → v1.14.0 - Drop custom hook entry that uses PRE_COMMIT_MYPY_VENV. - Use config suggested at python/mypy#13916. - ruff v0.7.4 → v0.9.1 - Reformat 7 files.
1 parent 09ac95b commit 61aff1c

File tree

8 files changed

+24
-32
lines changed

8 files changed

+24
-32
lines changed

.pre-commit-config.yaml

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
repos:
2-
- repo: local
2+
- repo: https://github.com/pre-commit/mirrors-mypy
3+
rev: v1.14.1
34
hooks:
45
- id: mypy
5-
name: mypy
6-
always_run: true
7-
require_serial: true
86
pass_filenames: false
9-
10-
language: python
11-
entry: bash -c ". ${PRE_COMMIT_MYPY_VENV:-/dev/null}/bin/activate 2>/dev/null; mypy $0 $@; python -m pip list"
127
additional_dependencies:
13-
- mypy >= 1.13.0
8+
- "ixmp @ git+https://github.com/iiasa/ixmp.git@main"
9+
- "message-ix @ git+https://github.com/iiasa/message_ix.git@main"
1410
- plotnine
1511
- pytest
1612
- sdmx1
1713
- types-PyYAML
1814
- types-tqdm
19-
- "ixmp @ git+https://github.com/iiasa/ixmp.git@main"
20-
- "message-ix @ git+https://github.com/iiasa/message_ix.git@main"
21-
args: ["."]
2215
- repo: https://github.com/astral-sh/ruff-pre-commit
23-
rev: v0.7.4
16+
rev: v0.9.1
2417
hooks:
2518
- id: ruff
2619
- id: ruff-format

message_ix_models/model/material/material_demand/material_demand_calc.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def read_timer_pop(
100100
datapath: str | Path, material: Literal["cement", "steel", "aluminum"]
101101
):
102102
df_population = pd.read_excel(
103-
f'{datapath}/{material_data[material]["dir"]}{material_data[material]["file"]}',
103+
f"{datapath}/{material_data[material]['dir']}{material_data[material]['file']}",
104104
sheet_name="Timer_POP",
105105
skiprows=[0, 1, 2, 30],
106106
nrows=26,
@@ -119,7 +119,7 @@ def read_timer_gdp(
119119
):
120120
# Read GDP per capita data
121121
df_gdp = pd.read_excel(
122-
f'{datapath}/{material_data[material]["dir"]}{material_data[material]["file"]}',
122+
f"{datapath}/{material_data[material]['dir']}{material_data[material]['file']}",
123123
sheet_name="Timer_GDPCAP",
124124
skiprows=[0, 1, 2, 30],
125125
nrows=26,
@@ -195,7 +195,7 @@ def read_hist_mat_demand(material: Literal["cement", "steel", "aluminum"]):
195195
if material == "aluminum":
196196
df_raw_cons = (
197197
pd.read_excel(
198-
f'{datapath}/{material_data[material]["dir"]}{material_data[material]["file"]}',
198+
f"{datapath}/{material_data[material]['dir']}{material_data[material]['file']}",
199199
sheet_name="final_table",
200200
nrows=378,
201201
)
@@ -213,7 +213,7 @@ def read_hist_mat_demand(material: Literal["cement", "steel", "aluminum"]):
213213
)
214214
elif material == "steel":
215215
df_raw_cons = pd.read_excel(
216-
f'{datapath}/{material_data[material]["dir"]}{material_data[material]["file"]}',
216+
f"{datapath}/{material_data[material]['dir']}{material_data[material]['file']}",
217217
sheet_name="Consumption regions",
218218
nrows=26,
219219
)
@@ -246,7 +246,7 @@ def read_hist_mat_demand(material: Literal["cement", "steel", "aluminum"]):
246246
)
247247
elif material == "cement":
248248
df_raw_cons = pd.read_excel(
249-
f'{datapath}/{material_data[material]["dir"]}{material_data[material]["file"]}',
249+
f"{datapath}/{material_data[material]['dir']}{material_data[material]['file']}",
250250
sheet_name="Regions",
251251
skiprows=122,
252252
nrows=26,
@@ -358,7 +358,7 @@ def derive_demand(
358358

359359
# get base year demand of material
360360
df_base_demand = read_base_demand(
361-
f'{datapath}/{material_data[material]["dir"]}/demand_{material}.yaml'
361+
f"{datapath}/{material_data[material]['dir']}/demand_{material}.yaml"
362362
)
363363

364364
# get historical data (material consumption, pop, gdp)

message_ix_models/model/transport/report.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def misc(c: "Computer") -> None:
281281
c.add("distance:nl:non-ldv", "distance_nonldv", "config")
282282

283283
# Demand per capita
284-
c.add("demand::capita", "div" "demand:n-c-y", "population:n-y")
284+
c.add("demand::capita", "divdemand:n-c-y", "population:n-y")
285285

286286
# Adjustment factor for LDV calibration: fuel economy ratio
287287
k_num = Key("in:nl-t-ya-c:transport+units") / "c" # As in CONVERT_IAMC
@@ -379,7 +379,7 @@ def callback(rep: Reporter, context: Context) -> None:
379379
],
380380
)
381381

382-
log.info(f"Added {len(rep.graph)-N_keys} keys")
382+
log.info(f"Added {len(rep.graph) - N_keys} keys")
383383
# TODO Write an SVG visualization of reporting calculations
384384

385385

message_ix_models/model/water/build.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ def cat_tec_cooling(context: Context) -> tuple[pd.DataFrame, list[str]]:
7777
regions_df = df["node_loc"].unique().tolist()
7878

7979
# Assertion check for valid data
80-
assert (
81-
len(parent_tech_sc) > 0
82-
), "No matching parent technologies found in the scenario."
80+
assert len(parent_tech_sc) > 0, (
81+
"No matching parent technologies found in the scenario."
82+
)
8383
assert len(regions_df) > 0, "No unique nodes (regions) found in the scenario."
8484

8585
# not filter cooling_tec with only parent_tech matching parent_tech_sc

message_ix_models/model/water/cli.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,7 @@ def cooling(context, regions, rcps, rels):
252252
context.REL = rels
253253

254254
log.info(
255-
f"SSP assumption is {context.ssp}. "
256-
f"RCP is {context.RCP}. REL is {context.REL}."
255+
f"SSP assumption is {context.ssp}. RCP is {context.RCP}. REL is {context.REL}."
257256
)
258257

259258
from .build import main as build

message_ix_models/model/water/report.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1103,9 +1103,9 @@ def report(sc: Scenario, reg: str, sdgs: bool = False) -> None:
11031103

11041104
pop_check = sc.timeseries(variable="Population")
11051105
pop_check = pop_check[pop_check.year >= 2020]
1106-
assert (
1107-
not pop_check.empty
1108-
), "The Population data does not exist or timeseries() has no future values"
1106+
assert not pop_check.empty, (
1107+
"The Population data does not exist or timeseries() has no future values"
1108+
)
11091109

11101110
pop_drink_tot = pd.DataFrame()
11111111
pop_sani_tot = pd.DataFrame()

message_ix_models/tests/model/test_disutility.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,9 @@ def test_get_data(scenario, spec):
239239

240240
# Test that the code will not encounter #45 / iiasa/ixmp#425
241241
for name, df in data.items():
242-
assert (
243-
"" not in df["unit"].unique()
244-
), f"{repr(name)} data has dimensionless units"
242+
assert "" not in df["unit"].unique(), (
243+
f"{repr(name)} data has dimensionless units"
244+
)
245245

246246

247247
def test_get_spec(groups, techs, template):

message_ix_models/util/sdmx.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def read(urn: str, base_dir: Optional["PathLike"] = None):
165165

166166
if len(paths) > 1:
167167
log.info(
168-
f"Match {paths[0].relative_to(base_dir)} for {urn!r}; {len(paths) -1 } "
168+
f"Match {paths[0].relative_to(base_dir)} for {urn!r}; {len(paths) - 1} "
169169
"other result(s)"
170170
)
171171

0 commit comments

Comments
 (0)