Skip to content

Commit 7f94f8a

Browse files
authored
Merge pull request #288 from iiasa/fix/ci-checkout-ref
Check out correct ref in "pytest" CI workflow
2 parents 08dc7fc + 9d3064b commit 7f94f8a

23 files changed

+176
-61
lines changed

.github/workflows/pytest.yaml

+22-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Test
22

33
on:
4-
# Uncomment this entry only to debug the workflow
4+
# To debug the workflow, uncomment this entry AND comment pull_request_target
55
# pull_request:
66
# branches: [ main ]
77
pull_request_target:
@@ -26,7 +26,7 @@ env:
2626

2727
jobs:
2828
check:
29-
name: check permissions
29+
name: Check permissions, identify ref to test
3030
runs-on: ubuntu-latest
3131
steps:
3232
- if: >
@@ -39,7 +39,15 @@ jobs:
3939
echo "Pytest workflow will not run for branch in fork without label \`${{ env.label }}\`." >>$GITHUB_STEP_SUMMARY
4040
exit 1
4141
42+
- name: Identify ref to check out
43+
id: ref
44+
run: echo "ref=${{ github.event_name != 'pull_request_target' && github.ref || github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT
45+
46+
outputs:
47+
ref: ${{ steps.ref.outputs.ref }}
48+
4249
warm-lfs-cache:
50+
name: Warm Git LFS cache
4351
needs: check
4452

4553
strategy:
@@ -48,6 +56,8 @@ jobs:
4856
runs-on: ${{ matrix.os }}
4957
steps:
5058
- uses: francisbilham11/action-cached-lfs-checkout@v3
59+
with:
60+
ref: ${{ needs.check.outputs.ref }}
5161

5262
pytest:
5363
needs: warm-lfs-cache
@@ -64,8 +74,6 @@ jobs:
6474
# - Versions of ixmp and message_ix to test.
6575
# - Latest supported Python version for those or other dependencies.
6676
# Minimum version given in pyproject.toml + earlier version of Python
67-
- { upstream: v3.4.0, python: "3.11" } # 2022-01-27
68-
- { upstream: v3.5.0, python: "3.11" } # 2022-05-06
6977
- { upstream: v3.6.0, python: "3.11" } # 2022-08-18
7078
- { upstream: v3.7.0, python: "3.11" } # 2023-05-17
7179
- { upstream: v3.8.0, python: "3.12" } # 2024-01-12
@@ -77,14 +85,12 @@ jobs:
7785
exclude:
7886
# Specific version combinations that are invalid / not to be used
7987
# These versions of ixmp are not able locate the arm64 GAMS API binaries
80-
- { os: macos-latest, version: {upstream: v3.4.0 }}
81-
- { os: macos-latest, version: {upstream: v3.5.0 }}
82-
- { os: macos-latest, version: {upstream: v3.6.0 }}
83-
- { os: macos-latest, version: {upstream: v3.7.0 }}
84-
- { os: macos-latest, version: {upstream: v3.8.0 }}
85-
- { os: macos-latest, version: {upstream: v3.9.0 }}
88+
- { os: macos-latest, version: { upstream: v3.6.0 }}
89+
- { os: macos-latest, version: { upstream: v3.7.0 }}
90+
- { os: macos-latest, version: { upstream: v3.8.0 }}
91+
- { os: macos-latest, version: { upstream: v3.9.0 }}
8692
# Redundant with macos-latest
87-
- { os: macos-13, version: {upstream: main }}
93+
- { os: macos-13, version: { upstream: main }}
8894

8995
fail-fast: false
9096

@@ -100,6 +106,8 @@ jobs:
100106

101107
- name: Check out message-ix-models
102108
uses: francisbilham11/action-cached-lfs-checkout@v3
109+
with:
110+
ref: ${{ needs.check.outputs.ref }}
103111

104112
- name: Set up uv, Python
105113
uses: astral-sh/setup-uv@v5
@@ -171,11 +179,12 @@ jobs:
171179

172180
pre-commit:
173181
name: Code quality
174-
182+
needs: check
175183
runs-on: ubuntu-latest
176-
177184
steps:
178185
- uses: actions/checkout@v4
186+
with:
187+
ref: ${{ needs.check.output.ref }}
179188
- uses: astral-sh/setup-uv@v5
180189
with:
181190
cache-dependency-glob: "**/pyproject.toml"

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ See the `online documentation <https://docs.messageix.org/projects/models/>`_ fo
1010
License
1111
=======
1212

13-
Copyright © 2020–2024 IIASA Energy, Climate, and Environment (ECE) program
13+
Copyright © 2020–2025 IIASA Energy, Climate, and Environment (ECE) program
1414

1515
Licensed under the Apache License, version 2.0.
1616

doc/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# -- Project information ---------------------------------------------------------------
1414

1515
project = "message-ix-models"
16-
copyright = "2020–2024, IIASA Energy, Climate, and Environment (ECE) Program"
16+
copyright = "2020–%Y, IIASA Energy, Climate, and Environment (ECE) Program"
1717
author = "IIASA Energy, Climate, and Environment (ECE) Program"
1818

1919

doc/whatsnew.rst

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ What's new
44
Next release
55
============
66

7+
- Support for :mod:`ixmp` and :mod:`message_ix` versions 3.4.x and 3.5.x is dropped in accordance with the :ref:`policy-upstream-versions` (:pull:`288`).
8+
The minimum version of both packages is 3.6.0.
79
- Update :class:`.IEA_EWEB` to support :py:`transform="B"` / :func:`.transform_B` (:issue:`230`, :pull:`259`).
810
- Update :doc:`/transport/index` (:pull:`259`).
911

message_ix_models/model/transport/config.py

+3
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,15 @@ def from_context(
341341
# Handle arguments
342342
options = options or dict()
343343

344+
log.debug(f".transport.Config.from_context: {context.model.regions = }")
344345
try:
345346
# Identify the node codelist used in `scenario`
346347
regions = identify_nodes(scenario) if scenario else context.model.regions
347348
except (AttributeError, ValueError):
348349
pass
349350
else:
351+
if scenario:
352+
log.debug(f".transport.Config.from_context: {scenario.set('node') = }")
350353
if context.model.regions != regions:
351354
log.info(
352355
f"Override Context.model.regions={context.model.regions!r} with "

message_ix_models/model/transport/ldv.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def prepare_tech_econ(
299299

300300
# Create base quantity for "output" parameter
301301
nty = tuple("nty")
302-
c.add(k.output[0] * nty, wildcard(1.0, "", nty))
302+
c.add(k.output[0] * nty, wildcard(1.0, "Gv km", nty))
303303
for i, coords in enumerate(["n::ex world", "t::LDV", "y::model"]):
304304
c.add(
305305
k.output[i + 1] * nty,

message_ix_models/model/transport/testing.py

+27-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import logging
44
import platform
5-
from collections.abc import Callable, Mapping
5+
from collections.abc import Callable, Hashable, Mapping
66
from contextlib import nullcontext
77
from pathlib import Path
88
from typing import TYPE_CHECKING, Optional, Union
@@ -14,7 +14,7 @@
1414
from message_ix_models import Context, ScenarioInfo
1515
from message_ix_models.report.sim import add_simulated_solution
1616
from message_ix_models.testing import GHA, bare_res
17-
from message_ix_models.util import silence_log
17+
from message_ix_models.util import identify_nodes, silence_log
1818
from message_ix_models.util.graphviz import HAS_GRAPHVIZ
1919

2020
from . import Config, build
@@ -28,12 +28,12 @@
2828

2929
# Common marks for transport code. Do not reuse keys that are less than the highest key
3030
# appearing in the dict.
31-
MARK: dict[int, pytest.MarkDecorator] = {
31+
MARK: dict[Hashable, pytest.MarkDecorator] = {
3232
0: pytest.mark.xfail(
33-
reason="Missing R14 input data/assumptions", raises=FileNotFoundError
33+
reason="Missing R14 input data/config", raises=FileNotFoundError
3434
),
3535
1: pytest.mark.skip(
36-
reason="Currently only possible with regions=R12 input data/assumptions",
36+
reason="Currently only possible with regions=R12 input data/config",
3737
),
3838
3: pytest.mark.xfail(raises=ValueError, reason="Missing ISR/mer-to-ppp.csv"),
3939
4: pytest.mark.xfail(reason="Currently unsupported"),
@@ -42,10 +42,14 @@
4242
condition=GHA and platform.system() == "Darwin" and not HAS_GRAPHVIZ,
4343
reason="Graphviz missing on macos-13 GitHub Actions runners",
4444
),
45-
8: pytest.mark.xfail(
45+
"gh-281": pytest.mark.xfail(
4646
raises=ModelError,
4747
reason="Temporary, for https://github.com/iiasa/message-ix-models/pull/281",
4848
),
49+
9: pytest.mark.xfail(reason="Missing R14 input data/config"),
50+
"gh-288": pytest.mark.xfail(
51+
reason="Temporary, for https://github.com/iiasa/message-ix-models/pull/288",
52+
),
4953
}
5054

5155
make_mark: dict[int, Callable[..., pytest.MarkDecorator]] = {
@@ -115,7 +119,7 @@ def built_transport(
115119
model_name = res.model.replace("-GLOBIOM", "-Transport")
116120

117121
try:
118-
scenario = Scenario(context.get_platform(), model_name, "baseline")
122+
scenario = Scenario(res.platform, model_name, "baseline")
119123
except ValueError:
120124
log.info(f"Create '{model_name}/baseline' for testing")
121125

@@ -138,7 +142,20 @@ def built_transport(
138142
scenario.solve(solve_options=dict(lpmethod=4))
139143

140144
log.info(f"Clone to '{model_name}/{request.node.name}'")
141-
return scenario.clone(scenario=request.node.name, keep_solution=solved)
145+
result = scenario.clone(scenario=request.node.name, keep_solution=solved)
146+
147+
if (
148+
GHA
149+
and platform.system() == "Darwin"
150+
and identify_nodes(result) != context.model.regions
151+
):
152+
pytest.xfail(
153+
reason="Known issue on GitHub Actions macOS runners: result has nodes "
154+
f"{identify_nodes(result) = !r} != {identify_nodes(res) = !r} == "
155+
f"{context.model.regions = !r}"
156+
)
157+
158+
return result
142159

143160

144161
def simulated_solution(request, context) -> Reporter:
@@ -190,4 +207,6 @@ def simulated_solution(request, context) -> Reporter:
190207
with silence_log("genno", logging.CRITICAL):
191208
message_ix_models.report.prepare_reporter(context, reporter=rep)
192209

210+
log.debug(f"simulated_solution: {context.regions = }")
211+
193212
return rep

message_ix_models/project/ssp/cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ def transport_cmd(context: "Context", method, path_in: Path, path_out: Optional[
6969

7070
if path_out_user != path_out:
7171
print(f"Convert CSV output to {path_out_user}")
72-
pd.read_csv(path_out).to_excel(path_out_user)
72+
pd.read_csv(path_out).to_excel(path_out_user, index=False)

message_ix_models/report/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ def prepare_reporter(
281281
"""
282282
log.info("Prepare reporter")
283283

284+
log.debug(f".report.prepare_reporter: {context.regions = }")
285+
284286
if reporter:
285287
# Existing `Reporter` provided
286288
rep = reporter

message_ix_models/testing/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ def bare_res(request, context: Context, solved: bool = False) -> message_ix.Scen
202202
from message_ix_models.model import bare
203203

204204
# Model name: standard "MESSAGEix-GLOBIOM R12 YB" plus a suffix
205+
log.info(f"bare_res: {context.model.regions = }")
205206
model_name = bare.name(context, unique=True)
206207

207208
mp = context.get_platform()
@@ -213,6 +214,8 @@ def bare_res(request, context: Context, solved: bool = False) -> message_ix.Scen
213214
context.scenario_info.update(model=model_name, scenario="baseline")
214215
base = bare.create_res(context)
215216

217+
log.info(f"bare_res: {base.set('node') = }")
218+
216219
if solved and not base.has_solution():
217220
log.info("Solve")
218221
base.solve(solve_options=dict(lpmethod=4), quiet=True)

message_ix_models/tests/model/transport/test_build.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_make_spec(regions_arg, regions_exp, years):
9191
param("R11", "B", False, "IKARUS", False, marks=[mark.slow, MARK[1]]),
9292
param("R11", "B", False, "IKARUS", True, marks=[mark.slow, MARK[1]]),
9393
# R12, B
94-
param("R12", "B", False, "IKARUS", True, marks=MARK[8]),
94+
param("R12", "B", False, "IKARUS", True, marks=MARK["gh-281"]),
9595
# R14, A
9696
param(
9797
"R14",
@@ -276,33 +276,33 @@ def test_build_existing(tmp_path, test_context, url, solve=False):
276276
@pytest.mark.parametrize(
277277
"build_kw",
278278
(
279-
dict(regions="R11", years="A", options=dict()),
280-
dict(regions="R11", years="B", options=dict()),
279+
dict(regions="R11", years="A"),
280+
dict(regions="R11", years="B"),
281281
dict(regions="R11", years="B", options=dict(futures_scenario="A---")),
282282
dict(regions="R11", years="B", options=dict(futures_scenario="debug")),
283-
dict(regions="R12", years="B", options=dict()),
283+
dict(regions="R12", years="B"),
284284
dict(regions="R12", years="B", options=dict(navigate_scenario="act+ele+tec")),
285-
dict(regions="R14", years="B", options=dict()),
286-
param(dict(regions="ISR", years="A", options=dict()), marks=MARK[3]),
285+
param(dict(regions="R14", years="B"), marks=MARK[9]),
286+
param(dict(regions="ISR", years="A"), marks=MARK[3]),
287287
),
288288
)
289289
def test_debug(
290290
test_context,
291291
tmp_path,
292292
build_kw,
293293
N_node,
294-
verbosity: Literal[0, 1, 2, 3] = 2, # NB Increase this to show more verbose output
294+
verbosity: Literal[0, 1, 2, 3] = 0, # NB Increase this to show more verbose output
295295
):
296296
"""Debug particular calculations in the transport build process."""
297297
# Get a Computer prepared to build the model with the given options
298298
c, info = configure_build(test_context, tmp_path=tmp_path, **build_kw)
299299

300300
# Construct a list of common checks
301301
verbose: dict[int, list["Check"]] = {
302-
0: [],
303-
1: [Log(7)],
304-
2: [Log(None)],
305-
3: [Dump(tmp_path)],
302+
0: [], # Don't log anything.
303+
1: [Log()], # Log 7 lines at the start/end of each quantity.
304+
2: [Log(None)], # Log *all* data. This is produces GHA logs >1 GiB.
305+
3: [Dump(tmp_path)], # Dump all data to a file.
306306
}
307307
common = [Size({"n": N_node}), NoneMissing()] + verbose[verbosity]
308308

message_ix_models/tests/model/transport/test_data.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pytest
33
from iam_units import registry
44

5-
from message_ix_models.model.transport import build, testing
5+
from message_ix_models.model.transport import build, non_ldv, testing
66
from message_ix_models.model.transport.CHN_IND import get_chn_ind_data, get_chn_ind_pop
77
from message_ix_models.model.transport.roadmap import get_roadmap_data
88
from message_ix_models.model.transport.testing import MARK, assert_units, make_mark
@@ -73,7 +73,7 @@ def test_get_non_ldv_data(test_context, regions, years="B"):
7373
c, _ = testing.configure_build(ctx, regions=regions, years=years)
7474

7575
# Code runs
76-
data = c.get("transport nonldv::ixmp")
76+
data = c.get(f"transport{non_ldv.Pi}")
7777

7878
# Data are provided for the these parameters
7979
exp_pars = {
@@ -189,7 +189,13 @@ def test_get_chn_ind_pop():
189189
@build.get_computer.minimum_version
190190
@pytest.mark.parametrize("years", ["A", "B"])
191191
@pytest.mark.parametrize(
192-
"regions", [pytest.param("ISR", marks=MARK[3]), "R11", "R12", "R14"]
192+
"regions",
193+
[
194+
pytest.param("ISR", marks=MARK[3]),
195+
"R11",
196+
"R12",
197+
pytest.param("R14", marks=MARK[9]),
198+
],
193199
)
194200
@pytest.mark.parametrize("options", [{}, dict(navigate_scenario=T35_POLICY.ELE)])
195201
def test_navigate_ele(test_context, regions, years, options):

message_ix_models/tests/model/transport/test_ikarus.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
[
1818
("R11", 11),
1919
("R12", 12),
20-
("R14", 14),
20+
pytest.param("R14", 14, marks=testing.MARK[9]),
2121
pytest.param("ISR", 1, marks=testing.MARK[3]),
2222
],
2323
)

0 commit comments

Comments
 (0)