From 2f487722845d38b06a9d3f1737e019deae2916eb Mon Sep 17 00:00:00 2001 From: Paul Natsuo Kishimoto Date: Wed, 25 May 2022 18:39:27 +0200 Subject: [PATCH] Ensure MESSAGE.enforce() runs for MESSAGE_MACRO (#613) * TEMPORARY Enable "nightly" CI workflow for PR * Make MESSAGE_MACRO a child class of MESSAGE This ensures its .enforce() method is used on .run() * Work around iiasa/ixmp#449 * Add mypy option --show-error-codes in "lint" CI workflow --- .github/workflows/lint.yaml | 2 +- .github/workflows/nightly.yaml | 4 ++-- message_ix/models.py | 7 ++----- pyproject.toml | 8 +++++++- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 2173e38a2..02c2a0709 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -67,4 +67,4 @@ jobs: # Also install type stubs and full packages that provide type hints run: | pip install mypy genno sphinx types-pkg_resources types-requests types-PyYAML - mypy . + mypy --show-error-codes . diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml index c3f239c1a..983fc0d9f 100644 --- a/.github/workflows/nightly.yaml +++ b/.github/workflows/nightly.yaml @@ -4,8 +4,8 @@ name: Test MESSAGEix-GLOBIOM scenarios on: # Uncomment these two lines for debugging, but leave them commented on 'main' - # pull_request: - # branches: [ main ] + pull_request: + branches: [ main ] schedule: # 05:00 UTC = 06:00 CET = 07:00 CEST - cron: "0 5 * * *" diff --git a/message_ix/models.py b/message_ix/models.py index fff4ffb4d..1bdc91470 100644 --- a/message_ix/models.py +++ b/message_ix/models.py @@ -335,9 +335,8 @@ def initialize(cls, scenario): @staticmethod def enforce(scenario): """Enforce data consistency in `scenario`.""" - # Implemented in MESSAGE sub-class, below + # No-op; implemented in MESSAGE sub-class, below # TODO make this an optional method of the ixmp.model.base.Model abstract class - pass def __init__(self, name=None, **model_options): # Update the default options with any user-provided options @@ -410,8 +409,6 @@ def enforce(scenario): if existing.equals(expected): continue # Contents are as expected; do nothing - # else: - # scenario.add_set(set_name, expected) # Not consistent; empty and then re-populate the set with scenario.transact(f"Enforce consistency of {set_name} and {par_name}"): @@ -452,7 +449,7 @@ def initialize(cls, scenario, with_data=False): cls.initialize_items(scenario, items) -class MESSAGE_MACRO(MACRO): +class MESSAGE_MACRO(MESSAGE, MACRO): """Model class for MESSAGE_MACRO.""" name = "MESSAGE-MACRO" diff --git a/pyproject.toml b/pyproject.toml index fde24a7d1..bb051ba1c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -103,6 +103,12 @@ module = [ ] ignore_missing_imports = true +# Workaround for iiasa/ixmp#449 +# TODO remove once fixed upstream +[[tool.mypy.overrides]] +module = ["ixmp.core.scenario"] +ignore_errors = true + [tool.pytest.ini_options] # Disable faulthandler plugin on Windows to prevent spurious console noise addopts = """ @@ -112,4 +118,4 @@ addopts = """ markers = [ "nightly: Slow-running nightly tests of particular scenarios.", "rmessageix: test of the message_ix R interface.", -] \ No newline at end of file +]