Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/continuousintegration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ build:
tools:
python: "3.11"

sphinx:
configuration: docs/conf.py

python:
install:
- requirements: docs/requirements.txt
Expand Down
33 changes: 26 additions & 7 deletions ctaplot/io/dataset.py
Original file line number Diff line number Diff line change
@@ -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']

Expand Down Expand Up @@ -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


Expand All @@ -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):
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- matplotlib
- nbsphinx
- numpy
- python >= 3.6
- python >= 3.9
- pandas
- pyyaml
- pytables
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ github_project = cta-observatory/cta-plot
license = MIT

[options]
python_requires = >=3.6
python_requires = >=3.9
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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), ],
Expand Down