diff --git a/.github/workflows/legacy.yml b/.github/workflows/legacy.yml new file mode 100644 index 00000000..7199e2e5 --- /dev/null +++ b/.github/workflows/legacy.yml @@ -0,0 +1,32 @@ +# This workflow validates that (new) variables are not referenced as deprecated legacy variables +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Guard against legacy variables + +on: + push: + branches: [ main ] + pull_request: + branches: [ '**' ] + +jobs: + legacy-validation: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python 3.11 + uses: actions/setup-python@v4 + with: + python-version: 3.11 + + - name: Install requirements + run: pip install -r requirements.txt + + - name: Install pytest + run: pip install pytest + + - name: Run the legacy validation + run: pytest tests/test_legacy.py diff --git a/requirements.txt b/requirements.txt index f68cfe94..e6b2055e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -nomenclature-iamc >= 0.12 +nomenclature-iamc >= 0.16 diff --git a/tests/test_legacy.py b/tests/test_legacy.py new file mode 100644 index 00000000..5c458e90 --- /dev/null +++ b/tests/test_legacy.py @@ -0,0 +1,25 @@ +from nomenclature import DataStructureDefinition + + +def test_legacy_variables(): + # Check that (new) variables are not referenced as deprecated legacy variables + dsd = DataStructureDefinition("definitions/", dimensions=["variable"]) + existing_variables = list(dsd.variable) + + legacy_variables = {} + for code, attrs in dsd.variable.items(): + for project in ["navigate", "engage"]: + if project in attrs.extra_attributes: + legacy_var = attrs.__getattr__(project) + if legacy_var in existing_variables: + legacy_variables[legacy_var] = code + + if legacy_variables: + error = [ + f"'{legacy_var}' -> '{code}'" + "\n" + for legacy_var, code in legacy_variables.items() + ] + + raise ValueError( + "Deprecated variables from legacy projects:\n" f"{''.join(error)}" + )