Skip to content

Commit 7e98edb

Browse files
author
David Turner
committed
Hopefully fixed pkg_resources deprecation warning by using importlib, which is what is currently implemented in main.
Signed-off-by: David Turner <djturner@umbc.edu>
1 parent de97f71 commit 7e98edb

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

xga/utils.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This code is part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (djturner@umbc.edu) 5/5/26, 12:43 PM. Copyright (c) The Contributors.
2+
# Last modified by David J Turner (djturner@umbc.edu) 5/5/26, 2:16 PM. Copyright (c) The Contributors.
33

4+
import importlib
45
import json
56
import os
67
import re
@@ -14,7 +15,6 @@
1415

1516
import numpy as np
1617
import pandas as pd
17-
import pkg_resources
1818
from astropy.constants import m_p, m_e
1919
from astropy.cosmology import LambdaCDM
2020
from astropy.io import fits
@@ -245,7 +245,7 @@ def _get_xspec_info() -> Tuple[Union[Version, None], List[str], List[str]]:
245245
else:
246246
try:
247247
# null_script.xcm does absolutely nothing, it's just a way to get the version out
248-
null_path = pkg_resources.resource_filename(__name__, "xspec_scripts/null_script.xcm")
248+
null_path = importlib.resources.files(__name__) / "xspec_scripts/null_script.xcm"
249249
xspec_out, xspec_err = Popen("xspec - {}".format(null_path), stdout=PIPE, stderr=PIPE,
250250
shell=True).communicate()
251251
# Got to parse the stdout to get the XSPEC version
@@ -876,21 +876,24 @@ def check_telescope_choices(telescope: Union[str, List[str]]) -> List[str]:
876876
# reading the information in on demand would be overkill for this
877877

878878
# Here we read in files that list the errors and warnings in SAS
879-
errors = pd.read_csv(pkg_resources.resource_filename(__name__, "files/sas_errors.csv"), header="infer")
880-
warnings = pd.read_csv(pkg_resources.resource_filename(__name__, "files/sas_warnings.csv"), header="infer")
879+
errors = pd.read_csv(importlib.resources.files(__name__) / "files/sas_errors.csv", header="infer")
880+
warnings = pd.read_csv(importlib.resources.files(__name__) / "files/sas_warnings.csv", header="infer")
881881
# Just the names of the errors in two handy constants
882882
SASERROR_LIST = errors["ErrName"].values
883883
SASWARNING_LIST = warnings["WarnName"].values
884884

885885
# XSPEC file extraction (and base fit) scripts
886-
XGA_EXTRACT = pkg_resources.resource_filename(__name__, "xspec_scripts/xga_extract.tcl")
887-
BASE_XSPEC_SCRIPT = pkg_resources.resource_filename(__name__, "xspec_scripts/general_xspec_fit.xcm")
888-
COUNTRATE_CONV_SCRIPT = pkg_resources.resource_filename(__name__, "xspec_scripts/cr_conv_calc.xcm")
886+
XGA_EXTRACT = importlib.resources.files(__name__) / "xspec_scripts/xga_extract.tcl"
887+
BASE_XSPEC_SCRIPT = importlib.resources.files(__name__) / "xspec_scripts/general_xspec_fit.xcm"
888+
COUNTRATE_CONV_SCRIPT = importlib.resources.files(__name__) / "xspec_scripts/cr_conv_calc.xcm"
889+
889890
# Useful jsons of all XSPEC models, their required parameters, and those parameter's units
890-
with open(pkg_resources.resource_filename(__name__, "files/xspec_model_pars.json5"), 'r') as filey:
891+
with open(importlib.resources.files(__name__) / "files/xspec_model_pars.json5", 'r') as filey:
891892
MODEL_PARS = json.load(filey)
892-
with open(pkg_resources.resource_filename(__name__, "files/xspec_model_units.json5"), 'r') as filey:
893+
894+
with open(importlib.resources.files(__name__) / "files/xspec_model_units.json5", 'r') as filey:
893895
MODEL_UNITS = json.load(filey)
896+
894897
# --------------------------------------------------------------------------
895898

896899

0 commit comments

Comments
 (0)