Skip to content

Commit

Permalink
changed importlib.resources import to help with black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
azaidi06 committed Dec 13, 2024
1 parent f921d2a commit 48b596e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions idaes/apps/grid_integration/examples/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
# for full copyright and license information.
#################################################################################

from importlib import resources
from importlib.resources import as_file, files
from pathlib import Path
import os

import pandas as pd


with resources.as_file(resources.files("idaes.tests.prescient.5bus").joinpath("__init__.py")) as pkg_file:
with as_file(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")
Expand Down
10 changes: 3 additions & 7 deletions idaes/apps/grid_integration/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# for full copyright and license information.
#################################################################################

from importlib import resources
from importlib.resources import as_file, file
from numbers import Number
from pathlib import Path
from typing import Dict, Union
Expand Down Expand Up @@ -51,11 +51,7 @@ def data_path(self) -> Path:
# where importlib.resources.path() requires the resource to be a file
# directories are not supported and will raise an error if attempted

### old version
# with resources.path("idaes.tests.prescient.5bus", "__init__.py") as pkg_file:
# return Path(pkg_file).parent

with resources.as_file(resources.files("idaes.tests.prescient.5bus").joinpath("__init__.py")) as pkg_file:
with as_file(files("idaes.tests.prescient.5bus").joinpath("__init__.py")) as pkg_file:
prescient_5bus = Path(pkg_file).parent


Expand All @@ -77,7 +73,7 @@ def self_scheduler_output_dir(self, tmp_path: Path) -> Path:

@pytest.fixture
def self_scheduler_plugin_path(self) -> Path:
with resources.as_file(resources.files("idaes.apps.grid_integration.tests").joinpath("self_scheduler_integration_test_plugin.py")) as p:
with as_file(files("idaes.apps.grid_integration.tests").joinpath("self_scheduler_integration_test_plugin.py")) as p:
return Path(p)

@pytest.mark.unit
Expand Down
4 changes: 2 additions & 2 deletions idaes/tests/prescient/test_prescient.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# for full copyright and license information.
#################################################################################

from importlib import resources
from importlib.resources import files, as_file
from numbers import Number
from pathlib import Path
from typing import Dict, Union
Expand All @@ -33,7 +33,7 @@ def data_path(self) -> Path:
# 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.as_file(resources.files("idaes.tests.prescient.5bus").joinpath("__init__.py")) as pkg_file:
with as_file(files("idaes.tests.prescient.5bus").joinpath("__init__.py")) as pkg_file:
prescient_5bus = Path(pkg_file).parent

@pytest.mark.unit
Expand Down

0 comments on commit 48b596e

Please sign in to comment.