generated from iiasa/scse-workflow-template
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Guard against adding deprecated legacy variables (#61)
Co-authored-by: Philip Hackstock <[email protected]>
- Loading branch information
1 parent
8976708
commit 4adcd19
Showing
3 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
nomenclature-iamc >= 0.12 | ||
nomenclature-iamc >= 0.16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}" | ||
) |