Skip to content
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

Miscellaneous packaging improvements #703

Merged
merged 19 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
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
10 changes: 10 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[flake8]
# Exceptions:
# - message_ix/core.py:716:5: C901 'Scenario.rename' is too complex (18)
# - message_ix/tools/add_year/__init__.py:86:1: C901 'add_year' is too complex (17)
# - message_ix/tools/add_year/__init__.py:533:1: C901 'interpolate_1d' is too complex (19)
# - message_ix/tools/add_year/__init__.py:687:1: C901 'interpolate_2d' is too complex (38)
# - message_ix/testing/__init__.py:91:1: C901 'make_austria' is too complex (18)
max-complexity = 14
# For black
max-line-length = 88
8 changes: 6 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ jobs:
lint:
uses: iiasa/actions/.github/workflows/lint.yaml@main
with:
max-complexity: 38
# If the "Latest version testable on GitHub Actions" in pytest.yaml
# is not the latest 3.x stable version, adjust here to match:
python-version: "3.10"
# For PRs that depend on an ixmp PR branch, adjust the URL below
type-hint-packages: >-
genno sphinx types-pkg_resources types-requests types-PyYAML
asyncssh
genno
pytest
sphinx
types-requests
types-PyYAML
git+https://github.com/iiasa/ixmp.git@main
54 changes: 18 additions & 36 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ on:
schedule:
- cron: "0 5 * * *"

# Cancel previous runs that have not completed
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

env:
GAMS_VERSION: 25.1.1
# See description in lint.yml
Expand Down Expand Up @@ -43,42 +48,19 @@ jobs:
name: ${{ matrix.os }}-py${{ matrix.python-version }}

steps:
- name: Cancel previous runs that have not completed
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Check out ixmp
uses: actions/checkout@v3
with:
repository: iiasa/ixmp
# For PRs that depend on an ixmp PR branch, uncomment the following 2
# lines and adjust to suit:
# repository: USERNAME/ixmp
# ref: issue/999
path: ixmp
fetch-depth: ${{ env.depth }}

- name: Check out message_ix
uses: actions/checkout@v3
with:
path: message_ix
fetch-depth: ${{ env.depth }}

- name: Fetch tags (for setuptools-scm)
run: |
(cd ixmp; git fetch --tags --depth=${{ env.depth }})
(cd message_ix; git fetch --tags --depth=${{ env.depth }})
shell: bash
run: git fetch --tags --depth=${{ env.depth }}

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: "**/setup.cfg"

- name: Upgrade pip, wheel, setuptools-scm
run: python -m pip install --upgrade pip wheel setuptools-scm
cache-dependency-path: "**/pyproject.toml"

- name: Set RETICULATE_PYTHON
# Use the environment variable set by the setup-python action, above.
Expand Down Expand Up @@ -108,13 +90,13 @@ jobs:
version: ${{ env.GAMS_VERSION }}
license: ${{ secrets.GAMS_LICENSE }}

- name: Install ixmp and dependencies
working-directory: ixmp
run: pip install .

- name: Install Python package and dependencies
working-directory: message_ix
run: pip install .[tests]
# By default, the below installs ixmp from the main branch. To run against
# other code, e.g. other branches for open PRs), temporarily edit as
# appropriate. DO NOT merge such changes to `main`.
run: |
pip install --upgrade "ixmp @ git+https://github.com/iiasa/ixmp.git@main"
glatterf42 marked this conversation as resolved.
Show resolved Hide resolved
pip install .[tests]

- name: Install R dependencies and tutorial requirements
run: |
Expand All @@ -131,18 +113,18 @@ jobs:
env:
# For test_cli.test_dl; see code in message_ix.cli.dl
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
working-directory: message_ix
# Work around iiasa/ixmp#411
run: |
pytest message_ix -m "not nightly" -rA --verbose --cov-report=xml --color=yes || ( [ $? -eq 127 -a "${{ runner.os }}" = "Windows" ] && echo "Spurious exit code 127 from pytest" && exit 0)
pytest message_ix \
-m "not nightly" \
-rA --verbose --color=yes --durations=20 \
--cov-report=xml \
--numprocesses=auto --dist=loadgroup || ( [ $? -eq 127 -a "${{ runner.os }}" = "Windows" ] && echo "Spurious exit code 127 from pytest" && exit 0)
shell: bash

- name: Test documentation build using Sphinx
if: ${{ startsWith(matrix.os, 'ubuntu') }}
working-directory: message_ix
run: make --directory=doc html

- name: Upload test coverage to Codecov.io
uses: codecov/codecov-action@v3
with:
directory: message_ix
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ prof/
# Editors and IDEs
# JetBrains IDEs incl. PyCharm
/**/.idea

# RStudio
.Rproj.user
.vscode
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Other forms of documentation:

## License

Copyright © 2018–2022 IIASA Energy, Climate, and Environment (ECE) Program
Copyright © 2018–2023 IIASA Energy, Climate, and Environment (ECE) Program

The MESSAGEix framework is licensed under the Apache License, Version 2.0 (the "License"); you may not use the files in this repository except in compliance with the License. You may obtain a copy of the License in [`LICENSE`](LICENSE) or at <http://www.apache.org/licenses/LICENSE-2.0>.

Expand Down
11 changes: 7 additions & 4 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.

from pathlib import Path
try:
from importlib.metadata import version
except ImportError: # Python 3.7
from importlib_metadata import version

from pkg_resources import get_distribution
from pathlib import Path

# -- Project information -----------------------------------------------------

project = "MESSAGEix"
copyright = "2018–2022, IIASA Energy, Climate, and Environment (ECE) Program"
copyright = "2018–2023, IIASA Energy, Climate, and Environment (ECE) Program"
author = "MESSAGEix Developers"

# The major project version, used as the replacement for |version|.
version = get_distribution("message_ix").version
version = version("message_ix")
# The full project version, used as the replacement for |release| and e.g. in
# the HTML templates.
release = version
Expand Down
10 changes: 7 additions & 3 deletions message_ix/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import logging
from pathlib import Path

try:
from importlib.metadata import PackageNotFoundError, version
except ImportError: # Python 3.7
from importlib_metadata import PackageNotFoundError, version # type: ignore

from ixmp import ModelError, config
from ixmp.model import MODELS
from pkg_resources import DistributionNotFound, get_distribution

from .core import Scenario
from .models import MACRO, MESSAGE, MESSAGE_MACRO
Expand All @@ -23,8 +27,8 @@
]

try:
__version__ = get_distribution(__name__).version
except DistributionNotFound:
__version__ = version(__name__)
except PackageNotFoundError: # pragma: no cover
# Package is not installed
__version__ = "999"

Expand Down
3 changes: 2 additions & 1 deletion message_ix/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,8 @@ def add_macro(self, data, scenario=None, check_convergence=True, **kwargs):
calibrate(clone, check_convergence=check_convergence, **kwargs)
return clone

def rename(self, name, mapping, keep=False):
# FIXME reduce complexity from 18 to <=14
def rename(self, name, mapping, keep=False): # noqa: C901
"""Rename an element in a set

Parameters
Expand Down
3 changes: 2 additions & 1 deletion message_ix/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def _to_df(columns, table):
)


def make_austria(mp, solve=False, quiet=True):
# FIXME reduce complexity from 18 to <=14
def make_austria(mp, solve=False, quiet=True): # noqa: C901
"""Return an :class:`message_ix.Scenario` for the Austrian energy system.

This is the same model used in the ``austria.ipynb`` tutorial.
Expand Down
4 changes: 2 additions & 2 deletions message_ix/tests/test_macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ def test_calc_valid_years(westeros_solved):
data = pd.read_excel(W_DATA_PATH, sheet_name=None, engine="openpyxl")
# Adding an arbitrary year
arbitrary_yr = 2021
gdp_extra_yr = data["gdp_calibrate"].iloc[0, :].copy()
gdp_extra_yr = data["gdp_calibrate"].copy()
gdp_extra_yr["year"] = arbitrary_yr
data["gdp_calibrate"] = data["gdp_calibrate"].append(gdp_extra_yr)
data["gdp_calibrate"] = pd.concat([data["gdp_calibrate"], gdp_extra_yr])
# Check the arbitrary year is not in config
assert arbitrary_yr not in data["config"]["year"]
# But it is in gdp_calibrate
Expand Down
Loading