Skip to content

Commit 05e81d8

Browse files
Change to hatchling based build pipeline (#53)
* Change to hatchling based build pipeline * use hatch-vcs * split tests * split tests * split tests * remove install current branch step * put test-subset on a single line * Add names * modify matrix * run codecov after all tests * Use deselect to ignore specific test functions * Only test a small subset on windows * Adjust run_tests.yml * more adjustments * python 3.13 compatability change * Don't track generated _version.py * Don't track generated _version.py
1 parent bfb148b commit 05e81d8

File tree

11 files changed

+135
-777
lines changed

11 files changed

+135
-777
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/release.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,26 @@ jobs:
1616
python-version: 3.12
1717
- name: Install release tooling
1818
run: |
19-
pip install twine wheel numpy setuptools versioneer
19+
pip install hatch numpy
2020
- name: Build package
2121
run: |
22-
python setup.py sdist bdist_wheel
22+
hatch build
2323
- name: Check version number match
2424
run: |
2525
echo "GITHUB_REF: ${GITHUB_REF}"
2626
# The GITHUB_REF should be something like "refs/tags/v1.2.3"
27-
# Make sure the package version is the same as the tag
28-
grep -Rq "^Version: ${GITHUB_REF:11}$" gEconpy.egg-info/PKG-INFO
27+
# Extract version from tag (remove 'v' prefix if present)
28+
TAG_VERSION=${GITHUB_REF:11}
29+
TAG_VERSION=${TAG_VERSION#v}
30+
# Get the version from the built package
31+
PACKAGE_VERSION=$(hatch version)
32+
echo "Tag version: $TAG_VERSION"
33+
echo "Package version: $PACKAGE_VERSION"
34+
# Check if versions match
35+
if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then
36+
echo "Version mismatch: Tag version ($TAG_VERSION) does not match package version ($PACKAGE_VERSION)"
37+
exit 1
38+
fi
2939
- uses: actions/upload-artifact@v4
3040
with:
3141
name: bdist

.github/workflows/run_tests.yml

Lines changed: 94 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,51 @@ concurrency:
1515

1616

1717
jobs:
18-
unittest:
18+
test:
1919
strategy:
2020
fail-fast: false
2121
matrix:
22-
os: [ubuntu-latest, windows-latest]
23-
python-version: ["3.11", "3.12"]
24-
exclude:
25-
- os: ubuntu-latest
26-
python-version: "3.11"
27-
- os: windows-latest
22+
include:
23+
- subset-name: "Model Steady State Tests"
24+
os: ubuntu-latest
2825
python-version: "3.12"
29-
test-subset:
30-
- |
31-
tests/
32-
26+
test-subset: "tests/test_model.py::test_numerical_steady_state tests/test_model.py::test_steady_state tests/test_model.py::test_partially_analytical_steady_state"
27+
- subset-name: "Model Tests"
28+
os: ubuntu-latest
29+
python-version: "3.12"
30+
test-subset: "tests/test_model.py --deselect tests/test_model.py::test_numerical_steady_state --deselect tests/test_model.py::test_steady_state --deselect tests/test_model.py::test_partially_analytical_steady_state"
31+
- subset-name: "Steady State Tests"
32+
os: ubuntu-latest
33+
python-version: "3.12"
34+
test-subset: "tests/test_steady_state.py"
35+
- subset-name: "Perturbation Tests"
36+
os: ubuntu-latest
37+
python-version: "3.12"
38+
test-subset: "tests/test_perturbation.py"
39+
- subset-name: "Other Tests"
40+
os: ubuntu-latest
41+
python-version: "3.12"
42+
test-subset: "tests/ --ignore tests/test_model.py --ignore tests/test_steady_state.py --ignore tests/test_perturbation.py"
43+
- subset-name: "Windows Test Model"
44+
os: windows-latest
45+
python-version: "3.13"
46+
test-subset: "tests/test_model.py --deselect tests/test_model.py::test_numerical_steady_state --deselect tests/test_model.py::test_steady_state --deselect tests/test_model.py::test_partially_analytical_steady_state --deselect tests/test_model.py::test_all_backends_agree_on_functions --deselect tests/test_model.py::test_scipy_wrapped_functions_agree"
47+
- subset-name: "Windows Other Tests"
48+
os: windows-latest
49+
python-version: "3.13"
50+
test-subset: "tests/ --ignore tests/test_model.py --ignore tests/test_steady_state.py --ignore tests/test_perturbation.py"
51+
name: ${{ matrix.subset-name }} (${{ matrix.os }} Python ${{ matrix.python-version }})
3352
runs-on: ${{ matrix.os }}
3453

3554
env:
3655
TEST_SUBSET: ${{ matrix.test-subset }}
3756

3857
defaults:
3958
run:
40-
shell: bash -l {0}
59+
shell: bash -leo pipefail {0}
4160

4261
steps:
43-
- uses: actions/checkout@v3
62+
- uses: actions/checkout@v4
4463

4564
- uses: mamba-org/setup-micromamba@v2
4665
with:
@@ -53,18 +72,71 @@ jobs:
5372

5473
- name: Install current branch
5574
run: |
56-
conda activate geconpy-test
5775
pip install -e .
5876
python --version
5977
78+
- name: Create matrix id
79+
id: matrix-id
80+
env:
81+
MATRIX_CONTEXT: ${{ toJson(matrix) }}
82+
run: |
83+
echo $MATRIX_CONTEXT
84+
export MATRIX_ID=`echo $MATRIX_CONTEXT | sha256sum | cut -c 1-32`
85+
echo $MATRIX_ID
86+
echo "id=$MATRIX_ID" >> $GITHUB_OUTPUT
87+
6088
- name: Run tests
6189
run: |
62-
python -m pytest -vv --cache-clear --cov=gEconpy --cov-report=xml --no-cov-on-fail --cov-report term $TEST_SUBSET
63-
- name: Upload coverage to Codecov
64-
uses: codecov/codecov-action@v3
90+
python -m pytest -vv --cache-clear --cov=gEconpy --cov-report=xml:coverage/coverage-${MATRIX_ID}.xml --no-cov-on-fail --cov-report term $TEST_SUBSET
91+
env:
92+
MATRIX_ID: ${{ steps.matrix-id.outputs.id }}
93+
94+
- name: Upload coverage file
95+
uses: actions/upload-artifact@v4
6596
with:
66-
token: ${{ secrets.CODECOV_TOKEN }} # use token for more robust uploads
67-
env_vars: TEST_SUBSET
68-
name: ${{ matrix.os }}
69-
fail_ci_if_error: false
70-
verbose: true
97+
name: coverage-${{ steps.matrix-id.outputs.id }}
98+
path: coverage/coverage-${{ steps.matrix-id.outputs.id }}.xml
99+
100+
101+
all-checks:
102+
if: ${{ always() }}
103+
runs-on: ubuntu-latest
104+
name: "All tests"
105+
needs: [test]
106+
steps:
107+
- name: Check build matrix status
108+
if: ${{ needs.test.result != 'success' }}
109+
run: exit 1
110+
111+
upload-coverage:
112+
runs-on: ubuntu-latest
113+
name: "Upload coverage"
114+
needs: [all-checks]
115+
if: ${{ needs.all-checks.result == 'success' }}
116+
steps:
117+
- uses: actions/checkout@v4
118+
with:
119+
persist-credentials: false
120+
121+
- name: Set up Python
122+
uses: actions/setup-python@v5
123+
with:
124+
python-version: "3.13"
125+
126+
- name: Install dependencies
127+
run: |
128+
python -m pip install -U coverage>=5.1 coveralls
129+
130+
- name: Download coverage file
131+
uses: actions/download-artifact@v4
132+
with:
133+
pattern: coverage-*
134+
path: coverage
135+
merge-multiple: true
136+
137+
- name: Upload coverage to Codecov
138+
uses: codecov/codecov-action@v5
139+
with:
140+
directory: ./coverage/
141+
fail_ci_if_error: true
142+
token: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ pip-wheel-metadata/
3535
share/python-wheels/
3636
generated/
3737

38+
# Generated by hatch-vcs, and should not be tracked.
39+
gEconpy/_version.py
40+
3841
*.egg-info/
3942
.installed.cfg
4043
*.egg

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repos:
1212
- id: trailing-whitespace
1313

1414
- repo: https://github.com/astral-sh/ruff-pre-commit
15-
rev: v0.9.10
15+
rev: v0.12.4
1616
hooks:
1717
- id: ruff
1818
args: [ --fix, --unsafe-fixes, --exit-non-zero-on-fix ]

gEconpy/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
solvers,
1010
utilities,
1111
)
12-
from gEconpy._version import get_versions
1312
from gEconpy.dynare_convert import make_mod_file
1413
from gEconpy.model.build import model_from_gcn, statespace_from_gcn
1514
from gEconpy.model.model import (
@@ -26,6 +25,7 @@
2625
from gEconpy.model.statespace import data_from_prior
2726
from gEconpy.model.steady_state import print_steady_state
2827
from gEconpy.parser.html import print_gcn_file
28+
from importlib.metadata import version
2929

3030
_log = logging.getLogger(__name__)
3131

@@ -36,7 +36,7 @@
3636
_log.addHandler(handler)
3737

3838

39-
__version__ = get_versions()["version"]
39+
__version__ = version("gEconpy")
4040

4141
__all__ = [
4242
"autocorrelation_matrix",

0 commit comments

Comments
 (0)