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

Guard against adding deprecated legacy variables #61

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
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
danielhuppmann marked this conversation as resolved.
Show resolved Hide resolved

- 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)}"
)
Loading