Skip to content

Commit

Permalink
Remove dependency of deprecated pkg_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
jnettels committed Oct 15, 2024
1 parent 3f659c4 commit e89ee23
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions annuity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Calculation of economic efficiency using the VDI 2067 annuity method."""
from pkg_resources import get_distribution, DistributionNotFound
from importlib.metadata import version, PackageNotFoundError

try:
dist_name = 'annuity'
# Try to get the version name from the installed package
__version__ = get_distribution(dist_name).version
except DistributionNotFound:
__version__ = version(dist_name)
except PackageNotFoundError:
try:
# If package is not installed, try to get version from git
from setuptools_scm import get_version
Expand Down
12 changes: 6 additions & 6 deletions annuity/annuity.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def main_database_example(pprint=True):
Main function that shows an example for loading the parts of the
energy system from a database.
"""
import pkg_resources # requires setuptools
import importlib.resources

# Define output format of logging function
logging.basicConfig(format='%(asctime)-15s %(message)s')
Expand All @@ -178,10 +178,10 @@ def main_database_example(pprint=True):
sys = System()

# For the 'noarch' conda build, the following files have to be accessed
# not from a regular file path, but as a pkg resources object
resource = pkg_resources.resource_stream(
'annuity', os.path.join('examples', 'cost_database.xlsx'))
with resource as path:
# not from a regular file path, but as a resources object
res_path = importlib.resources.files('annuity').joinpath(
os.path.join('examples', 'cost_database.xlsx'))
with importlib.resources.as_file(res_path) as path:
sys.load_cost_db(path=path)
# print(sys.cost_db)

Expand Down Expand Up @@ -571,7 +571,7 @@ def calc_annuities(self, T=30, q=1.07, r_K=1.03, r_B=1.02, r_I=1.03,
df_parts = self.list_parts()

# Create a Series of all annuities
self.A = pd.Series(dtype='object')
self.A = pd.Series(dtype='float')
if A_N_K_name is not None: # If None, skip output
self.A[A_N_K_name] = df_parts['A_N_K'].sum()
if A_N_B_name is not None: # If None, skip output
Expand Down
1 change: 0 additions & 1 deletion conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ build:
requirements:
build:
- python
- setuptools
- setuptools_scm
- pandas

Expand Down

0 comments on commit e89ee23

Please sign in to comment.