From d4fc4abd595d506a14bd3814b235f235c9b0af06 Mon Sep 17 00:00:00 2001 From: Chad Baker Date: Mon, 23 Oct 2023 13:26:08 -0600 Subject: [PATCH 1/8] more descriptive test ids --- applications/demos/test_demos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/demos/test_demos.py b/applications/demos/test_demos.py index 4f1a4b8d..f59b83f8 100644 --- a/applications/demos/test_demos.py +++ b/applications/demos/test_demos.py @@ -5,7 +5,7 @@ demo_paths = list(Path(__file__).parent.glob("*demo*.py")) -@pytest.mark.parametrize("demo_path", demo_paths, ids=[str(dp) for dp in demo_paths]) +@pytest.mark.parametrize("demo_path", demo_paths, ids=[dp.name for dp in demo_paths]) def test_demo(demo_path: Path): os.environ['SHOW_PLOTS'] = "false" rslt = subprocess.run( From afee67ab175f55982592c740085506f51b0324f8 Mon Sep 17 00:00:00 2001 From: Chad Baker Date: Mon, 23 Oct 2023 15:36:16 -0600 Subject: [PATCH 2/8] added `__version__` variable --- python/altrios/__init__.py | 12 ++++++------ python/altrios/utilities.py | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/python/altrios/__init__.py b/python/altrios/__init__.py index 37771b38..f265b06a 100644 --- a/python/altrios/__init__.py +++ b/python/altrios/__init__.py @@ -1,18 +1,18 @@ -from pathlib import Path +from pkg_resources import get_distribution +__version__ = get_distribution("altrios").version +from pathlib import Path import numpy as np -from altrios.loaders.powertrain_components import _res_from_excel - +import logging +from altrios.loaders.powertrain_components import _res_from_excel from altrios.utilities import set_param_from_path # noqa: F401 from altrios.utilities import download_demo_files # noqa: F401 from altrios import utilities as utils - -import logging - # make everything in altrios_core_py available here from altrios.altrios_core_py import * + # Set up logging logging.basicConfig( format="%(asctime)s.%(msecs)03d | %(filename)s#%(lineno)s | %(levelname)s: %(message)s", diff --git a/python/altrios/utilities.py b/python/altrios/utilities.py index 0015c428..e3d078bc 100644 --- a/python/altrios/utilities.py +++ b/python/altrios/utilities.py @@ -11,6 +11,7 @@ import datetime import requests import os +from altrios import __version__ from altrios.altrios_core_py import ( From 7a83271c0855cc965823740da4cf0e2ba23ccac4 Mon Sep 17 00:00:00 2001 From: Chad Baker Date: Mon, 23 Oct 2023 15:36:31 -0600 Subject: [PATCH 3/8] updated url to be version specific --- python/altrios/utilities.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/python/altrios/utilities.py b/python/altrios/utilities.py index e3d078bc..18b4a02f 100644 --- a/python/altrios/utilities.py +++ b/python/altrios/utilities.py @@ -272,9 +272,14 @@ def enable_logging(): def download_demo_files(): """ Downloads demo files from github repo into local directory. + + # Warning: running this function will overwrite existing files so make sure any files with + changes you'd like to keep are renamed. """ - api_url = "https://api.github.com/repos/NREL/altrios/contents/applications/demos" + v = f"v{__version__}" + + api_url = f"https://api.github.com/repos/NREL/altrios/contents/applications/demos?reg={v}" response = requests.get(api_url) if response.status_code == 200: From c2850171a83c1a76b7241115292bda68ab413462 Mon Sep 17 00:00:00 2001 From: Chad Baker Date: Tue, 24 Oct 2023 11:29:25 -0600 Subject: [PATCH 4/8] removed `test_demos.py` from testing itself --- applications/demos/test_demos.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/applications/demos/test_demos.py b/applications/demos/test_demos.py index f59b83f8..865132fc 100644 --- a/applications/demos/test_demos.py +++ b/applications/demos/test_demos.py @@ -4,8 +4,12 @@ import pytest -demo_paths = list(Path(__file__).parent.glob("*demo*.py")) -@pytest.mark.parametrize("demo_path", demo_paths, ids=[dp.name for dp in demo_paths]) +def demo_paths(): + demo_paths = list(Path(__file__).parent.glob("*demo*.py")) + demo_paths.remove(Path(__file__).resolve()) + return demo_paths + +@pytest.mark.parametrize("demo_path", demo_paths(), ids=[str(dp) for dp in demo_paths()]) def test_demo(demo_path: Path): os.environ['SHOW_PLOTS'] = "false" rslt = subprocess.run( From 81fa7ac1e0151cd20eceef0b2438f751f4f3a63e Mon Sep 17 00:00:00 2001 From: Chad Baker Date: Tue, 24 Oct 2023 11:30:11 -0600 Subject: [PATCH 5/8] `download_demo_files` works with versions and has specific test --- python/altrios/utilities.py | 17 ++++++++++++++--- tests/test_utilities.py | 14 ++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/python/altrios/utilities.py b/python/altrios/utilities.py index 18b4a02f..50bfbf22 100644 --- a/python/altrios/utilities.py +++ b/python/altrios/utilities.py @@ -269,11 +269,15 @@ def enable_logging(): set_log_level(logging.WARNING) -def download_demo_files(): +def download_demo_files(demo_path: Path=Path("demos")): """ Downloads demo files from github repo into local directory. - # Warning: running this function will overwrite existing files so make sure any files with + # Arguments + demo_path: path (relative or absolute in ) + + # Warning + Running this function will overwrite existing files so make sure any files with changes you'd like to keep are renamed. """ @@ -290,12 +294,19 @@ def download_demo_files(): file_url = item["download_url"] file_name = item["name"] - demo_path = Path("demos") demo_path.mkdir(exist_ok=True) with open(demo_path / file_name, "wb") as file: file_content = requests.get(file_url).content file.write(file_content) + + with open(demo_path / file_name, "r+") as file: + file_content = file.readlines() + prepend_str = f"# %% Downloaded from ALTRIOS version '{v}'. Guaranteed compatibility with this version only.\n" + prepend = [prepend_str] + file_content = prepend + file_content + file.seek(0) + file.writelines(file_content) print(f"Saved {file_name} to {str(demo_path / file_name)}") else: diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 1f500204..f5de37c5 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -1,8 +1,11 @@ +import tempfile import unittest +from pathlib import Path from .mock_resources import * from altrios.utilities import set_param_from_path +import altrios as alt class TestUtilities(unittest.TestCase): @@ -16,3 +19,14 @@ def test_set_param(self): c = set_param_from_path(c, "state.pwr_fuel_watts", -100) self.assertEqual(c.state.pwr_fuel_watts, -100) + + def test_download_demo_files(self): + v = f"v{alt.__version__}" + prepend_str = f"# %% Downloaded from ALTRIOS version '{v}'. Guaranteed compatibility with this version only.\n" + with tempfile.TemporaryDirectory() as tmpdir: + tf_path = Path(tmpdir) + alt.download_demo_files(tf_path) + with open(next(tf_path.glob("*demo*.py")), 'r') as file: + lines = file.readlines() + assert prepend_str in lines[0] + assert len(lines) > 3 From a1dfcf03d5f5ea97b5ca492c32bd92b00146c966 Mon Sep 17 00:00:00 2001 From: Chad Baker Date: Tue, 24 Oct 2023 11:35:14 -0600 Subject: [PATCH 6/8] added documentation and github badges --- README.md | 4 +++- rust/altrios-core/README.md | 5 +++++ rust/altrios-core/altrios-proc-macros/README.md | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f57b3bd7..4750bd68 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,9 @@ ![Altrios Logo](https://raw.githubusercontent.com/NREL/altrios/main/.github/images/ALTRIOS-logo-web.jpg) -[![Tests](https://github.com/NREL/altrios/actions/workflows/tests.yaml/badge.svg)](https://github.com/NREL/altrios/actions/workflows/tests.yaml) [![wheels](https://github.com/NREL/altrios/actions/workflows/wheels.yaml/badge.svg)](https://github.com/NREL/altrios/actions/workflows/wheels.yaml?event=release) ![Release](https://img.shields.io/badge/release-v0.1.0-blue) ![Python](https://img.shields.io/badge/python-3.9%20%7C%203.10-blue) +[![Tests](https://github.com/NREL/altrios/actions/workflows/tests.yaml/badge.svg)](https://github.com/NREL/altrios/actions/workflows/tests.yaml) [![wheels](https://github.com/NREL/altrios/actions/workflows/wheels.yaml/badge.svg)](https://github.com/NREL/altrios/actions/workflows/wheels.yaml?event=release) ![Release](https://img.shields.io/badge/release-v0.1.0-blue) ![Python](https://img.shields.io/badge/python-3.9%20%7C%203.10-blue) [![Documentation](https://img.shields.io/badge/documentation-custom-blue.svg)](https://nrel.github.io/altrios/) [![GitHub](https://img.shields.io/badge/GitHub-altrios-blue.svg)](https://github.com/NREL/altrios) + + ![Model Framework Schematic](https://raw.githubusercontent.com/NREL/altrios/main/.github/images/ALTRIOS_schematic_Alfred_Hicks.png) diff --git a/rust/altrios-core/README.md b/rust/altrios-core/README.md index 8766bfd2..3c5e72e4 100644 --- a/rust/altrios-core/README.md +++ b/rust/altrios-core/README.md @@ -1,5 +1,10 @@ # altrios-core +![Altrios Logo](https://raw.githubusercontent.com/NREL/altrios/main/.github/images/ALTRIOS-logo-web.jpg) + +[![Tests](https://github.com/NREL/altrios/actions/workflows/tests.yaml/badge.svg)](https://github.com/NREL/altrios/actions/workflows/tests.yaml) [![wheels](https://github.com/NREL/altrios/actions/workflows/wheels.yaml/badge.svg)](https://github.com/NREL/altrios/actions/workflows/wheels.yaml?event=release) ![Release](https://img.shields.io/badge/release-v0.1.0-blue) ![Python](https://img.shields.io/badge/python-3.9%20%7C%203.10-blue) [![Documentation](https://img.shields.io/badge/documentation-custom-blue.svg)](https://nrel.github.io/altrios/) [![GitHub](https://img.shields.io/badge/GitHub-altrios-blue.svg)](https://github.com/NREL/altrios) + + This crate is primarily intended to be used as a backend for the [ALTRIOS PyPI package](https://pypi.org/project/altrios/), but it can also function as a dependency for other crates. ## Developers diff --git a/rust/altrios-core/altrios-proc-macros/README.md b/rust/altrios-core/altrios-proc-macros/README.md index 26c3ff3f..c690ec1b 100644 --- a/rust/altrios-core/altrios-proc-macros/README.md +++ b/rust/altrios-core/altrios-proc-macros/README.md @@ -1,5 +1,10 @@ # altrios-proc-macros +![Altrios Logo](https://raw.githubusercontent.com/NREL/altrios/main/.github/images/ALTRIOS-logo-web.jpg) + +[![Tests](https://github.com/NREL/altrios/actions/workflows/tests.yaml/badge.svg)](https://github.com/NREL/altrios/actions/workflows/tests.yaml) [![wheels](https://github.com/NREL/altrios/actions/workflows/wheels.yaml/badge.svg)](https://github.com/NREL/altrios/actions/workflows/wheels.yaml?event=release) ![Release](https://img.shields.io/badge/release-v0.1.0-blue) ![Python](https://img.shields.io/badge/python-3.9%20%7C%203.10-blue) [![Documentation](https://img.shields.io/badge/documentation-custom-blue.svg)](https://nrel.github.io/altrios/) [![GitHub](https://img.shields.io/badge/GitHub-altrios-blue.svg)](https://github.com/NREL/altrios) + + This crate contains procedural macros used in [altrios-core](https://crates.io/crates/altrios-core). ## Developers From 79ca8d9fdae2ec88689dee31e6a59d069af738e2 Mon Sep 17 00:00:00 2001 From: Chad Baker Date: Tue, 24 Oct 2023 11:39:55 -0600 Subject: [PATCH 7/8] incremented patch to allow for publication of readme updates --- rust/Cargo.lock | 4 ++-- rust/altrios-core/Cargo.toml | 4 ++-- rust/altrios-core/altrios-proc-macros/Cargo.toml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index f20c5c0f..a7f281d9 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -46,7 +46,7 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" [[package]] name = "altrios-core" -version = "0.1.1" +version = "0.1.2" dependencies = [ "altrios-proc-macros", "anyhow", @@ -88,7 +88,7 @@ dependencies = [ [[package]] name = "altrios-proc-macros" -version = "0.1.1" +version = "0.1.2" dependencies = [ "proc-macro-error", "proc-macro2", diff --git a/rust/altrios-core/Cargo.toml b/rust/altrios-core/Cargo.toml index 64e8eb77..0c71159f 100644 --- a/rust/altrios-core/Cargo.toml +++ b/rust/altrios-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "altrios-core" -version = "0.1.1" +version = "0.1.2" edition = "2021" license = "BSD-3-Clause" authors = ["NREL/MTES/CIMS/MBAP Group"] @@ -17,7 +17,7 @@ serde_json = "1.0" uom = { workspace = true } paste = "1.0.7" easy-ext = "1.0.0" -altrios-proc-macros = { version = "0.1.1", path = "altrios-proc-macros" } +altrios-proc-macros = { version = "0.1.2", path = "altrios-proc-macros" } argmin = "0.5.1" enum_dispatch = "0.3.8" rayon = "1.5.3" diff --git a/rust/altrios-core/altrios-proc-macros/Cargo.toml b/rust/altrios-core/altrios-proc-macros/Cargo.toml index 83ce2e11..b3001ce5 100644 --- a/rust/altrios-core/altrios-proc-macros/Cargo.toml +++ b/rust/altrios-core/altrios-proc-macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "altrios-proc-macros" -version = "0.1.1" +version = "0.1.2" edition = "2021" license = "BSD-3-Clause" authors = ["NREL/MTES/CIMS/MBAP Group"] From 1e1949c7212b622260cce63fe290b8ce54053b1d Mon Sep 17 00:00:00 2001 From: Chad Baker Date: Tue, 24 Oct 2023 11:41:11 -0600 Subject: [PATCH 8/8] --amend --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index fcd720d1..a9001626 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "altrios" -version = "0.1.2" +version = "0.1.3" authors = [ { name = "ALTRIOS Team", email = "altrios@nrel.gov" }, { name = "Chad Baker, Lead Developer" },