From e89ee237ed4467e115fa3221af12762df896cb1e Mon Sep 17 00:00:00 2001 From: Joris Nettelstroth Date: Tue, 15 Oct 2024 22:44:25 +0200 Subject: [PATCH] Remove dependency of deprecated pkg_resources --- annuity/__init__.py | 6 +++--- annuity/annuity.py | 12 ++++++------ conda.recipe/meta.yaml | 1 - 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/annuity/__init__.py b/annuity/__init__.py index 44956e9..70eaf52 100644 --- a/annuity/__init__.py +++ b/annuity/__init__.py @@ -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 diff --git a/annuity/annuity.py b/annuity/annuity.py index d4d186f..9092401 100644 --- a/annuity/annuity.py +++ b/annuity/annuity.py @@ -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') @@ -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) @@ -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 diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml index 2f8283c..6217bce 100644 --- a/conda.recipe/meta.yaml +++ b/conda.recipe/meta.yaml @@ -19,7 +19,6 @@ build: requirements: build: - python - - setuptools - setuptools_scm - pandas