diff --git a/.github/workflows/continuousintegration.yml b/.github/workflows/continuousintegration.yml index 596e6eb..612af08 100644 --- a/.github/workflows/continuousintegration.yml +++ b/.github/workflows/continuousintegration.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.8, 3.9, "3.10", "3.11"] + python-version: [3.9, "3.10", "3.11"] steps: - uses: actions/checkout@v2 diff --git a/.readthedocs.yml b/.readthedocs.yml index d8d5c35..2668ce0 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -5,6 +5,9 @@ build: tools: python: "3.11" +sphinx: + configuration: docs/conf.py + python: install: - requirements: docs/requirements.txt diff --git a/ctaplot/io/dataset.py b/ctaplot/io/dataset.py index b0eea41..0511edf 100644 --- a/ctaplot/io/dataset.py +++ b/ctaplot/io/dataset.py @@ -1,7 +1,8 @@ -import pkg_resources import os import sys import numpy as np +from importlib.resources import files as importlib_files, as_file + __all__ = ['get'] @@ -98,11 +99,18 @@ def get(resource_name): try: resource_path = find_resource(resource_name) except FileNotFoundError: - if not pkg_resources.resource_exists(__name__, resource_name): + # Check if resource exists using importlib.resources + try: + resource_ref = importlib_files(__name__) / resource_name + if resource_ref.is_file(): + with as_file(resource_ref) as resource_path: + return str(resource_path) + else: + raise FileNotFoundError("Couldn't find resource: '{}'" + .format(resource_name)) + except (FileNotFoundError, AttributeError): raise FileNotFoundError("Couldn't find resource: '{}'" .format(resource_name)) - else: - resource_path = pkg_resources.resource_filename(__name__, resource_name) return resource_path @@ -120,8 +128,19 @@ def find_resource(resource_name): str - absolute path to the resource """ # If ctaplot is installed via python setup.py develop, data files stay in share - share_dir = os.path.join(pkg_resources.resource_filename('ctaplot', ''), '../share/') - gammaboard_dir = os.path.join(pkg_resources.resource_filename('ctaplot', ''), 'gammaboard/') + try: + # Get the ctaplot package directory using importlib.resources + ctaplot_ref = importlib_files('ctaplot') + with as_file(ctaplot_ref) as ctaplot_path: + share_dir = os.path.join(str(ctaplot_path), '../share/') + gammaboard_dir = os.path.join(str(ctaplot_path), 'gammaboard/') + except (ImportError, FileNotFoundError): + # Fallback if importlib.resources doesn't work + import ctaplot + ctaplot_path = os.path.dirname(ctaplot.__file__) + share_dir = os.path.join(ctaplot_path, '../share/') + gammaboard_dir = os.path.join(ctaplot_path, 'gammaboard/') + resources_dirs = [share_dir, gammaboard_dir] for res_dir in resources_dirs: for root, dirs, files in os.walk(res_dir): @@ -156,7 +175,7 @@ def load_any_resource(filename): try: data = np.loadtxt(get(filename), skiprows=sr, unpack=True) break - except: + except Exception: sr += 1 return data diff --git a/environment.yml b/environment.yml index e728b31..b2652b9 100644 --- a/environment.yml +++ b/environment.yml @@ -9,7 +9,7 @@ dependencies: - matplotlib - nbsphinx - numpy - - python >= 3.6 + - python >= 3.9 - pandas - pyyaml - pytables diff --git a/setup.cfg b/setup.cfg index 655f2b1..deec55a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,4 +9,4 @@ github_project = cta-observatory/cta-plot license = MIT [options] -python_requires = >=3.6 +python_requires = >=3.9 diff --git a/setup.py b/setup.py index e789330..0d919e6 100644 --- a/setup.py +++ b/setup.py @@ -45,6 +45,9 @@ def get_property(prop, project): classifiers=[ 'Intended Audience :: Science/Research', 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', 'Topic :: Scientific/Engineering :: Astronomy', ], data_files=[('ctaplot', dataset), ],