Skip to content

Commit

Permalink
Ensure MESSAGE.enforce() runs for MESSAGE_MACRO (#613)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
khaeru authored May 25, 2022
1 parent 2ae918e commit 2f48772
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
4 changes: 2 additions & 2 deletions .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 * * *"
Expand Down
7 changes: 2 additions & 5 deletions message_ix/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"):
Expand Down Expand Up @@ -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"
Expand Down
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand All @@ -112,4 +118,4 @@ addopts = """
markers = [
"nightly: Slow-running nightly tests of particular scenarios.",
"rmessageix: test of the message_ix R interface.",
]
]

0 comments on commit 2f48772

Please sign in to comment.