diff --git a/idaes/apps/grid_integration/examples/utils.py b/idaes/apps/grid_integration/examples/utils.py index 9aeb8f1fba..28c9bd46f4 100644 --- a/idaes/apps/grid_integration/examples/utils.py +++ b/idaes/apps/grid_integration/examples/utils.py @@ -18,7 +18,9 @@ import pandas as pd -with resources.path("idaes.tests.prescient.5bus", "__init__.py") as pkg_file: +with resources.as_file( + resources.files("idaes.tests.prescient.5bus").joinpath("__init__.py") +) as pkg_file: prescient_5bus = Path(pkg_file).parent # rts_gmlc_generator_dataframe = pd.read_csv("gen.csv") diff --git a/idaes/apps/grid_integration/tests/test_integration.py b/idaes/apps/grid_integration/tests/test_integration.py index 808d50c5fa..9ca7ab34a6 100644 --- a/idaes/apps/grid_integration/tests/test_integration.py +++ b/idaes/apps/grid_integration/tests/test_integration.py @@ -47,11 +47,12 @@ class TestDoubleLoopIntegration: @pytest.fixture def data_path(self) -> Path: # NOTE here we want the path to the entire 5bus directory - # we need to specify __init__.py as a workaround for Python 3.9, - # where importlib.resources.path() requires the resource to be a file - # directories are not supported and will raise an error if attempted - with resources.path("idaes.tests.prescient.5bus", "__init__.py") as pkg_file: - return Path(pkg_file).parent + # we need to specify __init__.py and then use `pathlib.Path.parent` since + # `importlib.resources.as_path()` only supports directories on Python 3.12+ + with resources.as_file( + resources.files("idaes.tests.prescient.5bus").joinpath("__init__.py") + ) as pkg_file: + return pkg_file.parent @pytest.mark.unit def test_data_path_available(self, data_path: Path): @@ -71,9 +72,10 @@ def self_scheduler_output_dir(self, tmp_path: Path) -> Path: @pytest.fixture def self_scheduler_plugin_path(self) -> Path: - with resources.path( - "idaes.apps.grid_integration.tests", - "self_scheduler_integration_test_plugin.py", + with resources.as_file( + resources.files("idaes.apps.grid_integration.tests").joinpath( + "self_scheduler_integration_test_plugin.py" + ) ) as p: return Path(p) diff --git a/idaes/tests/prescient/test_prescient.py b/idaes/tests/prescient/test_prescient.py index 881ecc717c..2197688597 100644 --- a/idaes/tests/prescient/test_prescient.py +++ b/idaes/tests/prescient/test_prescient.py @@ -30,11 +30,12 @@ class Test5Bus: @pytest.fixture def data_path(self) -> Path: # NOTE here we want the path to the entire 5bus directory - # we need to specify __init__.py as a workaround for Python 3.9, - # where importlib.resources.path() requires the resource to be a file - # directories are not supported and will raise an error if attempted - with resources.path("idaes.tests.prescient.5bus", "__init__.py") as pkg_file: - return Path(pkg_file).parent + # we need to specify __init__.py and then use `pathlib.Path.parent` since + # `importlib.resources.as_path()` only supports directories on Python 3.12+ + with resources.as_file( + resources.files("idaes.tests.prescient.5bus").joinpath("__init__.py") + ) as pkg_file: + return pkg_file.parent @pytest.mark.unit def test_data_path_available(self, data_path: Path):