Skip to content

Commit

Permalink
Merge pull request #126 from oemof/revert-101-fix/#100-pgk_resources-…
Browse files Browse the repository at this point in the history
…depriciation

Revert "Replace all appearences of pkg_resources except one"
  • Loading branch information
nailend committed Aug 30, 2023
2 parents bd8b2f6 + 603c06a commit ee8eada
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10"]
python-version: [ '3.8', '3.9', '3.10' ]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def read(*names, **kwargs):
"Operating System :: Microsoft :: Windows",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: Implementation :: CPython",
Expand All @@ -63,7 +64,6 @@ def read(*names, **kwargs):
keywords=[
# eg: 'keyword1', 'keyword2', 'keyword3',
],
python_requires=">=3.9, <3.11",
install_requires=[
"datapackage==1.5.1",
"tableschema==1.7.4", # newer versions (v1.8.0 and up) fail!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,4 @@
}
}
]
}
}
7 changes: 3 additions & 4 deletions src/oemof/tabular/examples/scripting/compute.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
"""
import importlib.resources
import os

import pkg_resources as pkg
from oemof.solph import EnergySystem, Model, processing

# DONT REMOVE THIS LINE!
Expand All @@ -23,9 +23,8 @@
print("Running compute example with datapackage {}".format(example))

# path to directory with datapackage to load
datapackage_dir = os.path.join(
importlib.resources.files("oemof.tabular"),
"examples/datapackages/{}".format(example),
datapackage_dir = pkg.resource_filename(
"oemof.tabular", "examples/datapackages/{}".format(example)
)

# create path for results (we use the datapackage_dir to store results)
Expand Down
60 changes: 42 additions & 18 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import importlib
import importlib.resources
import os
import pathlib
import re
from difflib import unified_diff

import pkg_resources as pkg
from oemof.network.energy_system import EnergySystem as ES
from oemof.solph import helpers

Expand Down Expand Up @@ -50,14 +50,18 @@ def test_example_datapackage_readability():
"""The example datapackages can be read and loaded."""

systems = []
datapackage_dir = os.path.join(
importlib.resources.files("oemof.tabular"), "examples/datapackages"
)
for example in os.listdir(datapackage_dir):
for example in pkg.resource_listdir(
"oemof.tabular", "examples/datapackages"
):
print("Runnig reading datapackage example {} ...".format(example))
systems.append(
ES.from_datapackage(
os.path.join(datapackage_dir, example, "datapackage.json"),
pkg.resource_filename(
"oemof.tabular",
"examples/datapackages/{}/datapackage.json".format(
example
),
),
typemap=TYPEMAP,
)
)
Expand All @@ -70,26 +74,46 @@ def test_scripting_examples():
""" """

exclude = ["plotting.py", "__pycache__"]
examples_dir = os.path.join(
importlib.resources.files("oemof.tabular"), "examples/scripting"
)
for example in os.listdir(examples_dir):
for example in pkg.resource_listdir("oemof.tabular", "examples/scripting"):
if not example.endswith(".ipynb") and example not in exclude:
print("Running scripting example {} ...".format(example))
exec(open(os.path.join(examples_dir, example)).read())
exec(
open(
pkg.resource_filename(
"oemof.tabular",
"examples/scripting/{}".format(example),
)
).read()
)


def test_examples_datapackages_scripts_infer():
""" """
script = "infer.py"

module_path = pathlib.Path(oemof.tabular.__file__).parent
example_path = module_path / "examples" / "datapackages"

for datapackage_path in example_path.iterdir():
example_datapackage = datapackage_path.name
script_path = datapackage_path / "scripts" / script

for example_datapackage in pkg.resource_listdir(
"oemof.tabular", "examples/datapackages/"
):
script_path = (
ROOT_DIR
/ "src"
/ "oemof"
/ "tabular"
/ "examples"
/ "datapackages"
/ example_datapackage
/ "scripts"
/ script
)
datapackage_path = (
ROOT_DIR
/ "src"
/ "oemof"
/ "tabular"
/ "examples"
/ "datapackages"
/ example_datapackage
)
if script_path.exists():
print(
"Running infer script for {} ...".format(example_datapackage)
Expand Down

0 comments on commit ee8eada

Please sign in to comment.