Skip to content

Commit

Permalink
Guard against adding deprecated legacy variables (#61)
Browse files Browse the repository at this point in the history
Co-authored-by: Philip Hackstock <[email protected]>
  • Loading branch information
danielhuppmann and phackstock authored Feb 15, 2024
1 parent 8976708 commit 4adcd19
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .github/workflows/legacy.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nomenclature-iamc >= 0.12
nomenclature-iamc >= 0.16
25 changes: 25 additions & 0 deletions tests/test_legacy.py
Original file line number Diff line number Diff line change
@@ -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)}"
)

0 comments on commit 4adcd19

Please sign in to comment.