Skip to content

Commit fccca8a

Browse files
authored
fix deprecation warning when test (#170)
* fix pkg_resources deprecation warning * use __name__ * daemon deprecation
1 parent ef29c6a commit fccca8a

File tree

6 files changed

+16
-19
lines changed

6 files changed

+16
-19
lines changed

src/diffpy/pdfgui/control/pdfguicontrol.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def run(self):
8989

9090
def startQueue(self):
9191
"""start queue manager"""
92-
self.queueManager.setDaemon(True)
92+
self.queueManager.daemon = True
9393
self.queueManager.start()
9494

9595
def checkQueue(self):

src/diffpy/pdfgui/gui/extendedplotframe.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,9 @@ def legendBoxProperties():
368368
return _lbp
369369
# figure out matplotlib version and appropriate names
370370
from matplotlib import __version__ as mplver
371-
from pkg_resources import parse_version
371+
from packaging.version import parse
372372

373-
if parse_version(mplver) >= parse_version("0.98.5"):
373+
if parse(mplver) >= parse("0.98.5"):
374374
_lbp = {
375375
"loc": "upper right",
376376
"numpoints": 3, # number of points in the legend line

src/diffpy/pdfgui/gui/pdfguiglobals.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
"""This module contains global parameters needed by PDFgui."""
1717

1818
import os.path
19-
20-
from pkg_resources import Requirement, resource_filename
19+
from importlib.resources import files
2120

2221
from diffpy.pdfgui.gui import debugoptions
2322

@@ -31,23 +30,23 @@
3130
isAltered = False
3231

3332
# Resolve APPDATADIR base path to application data files.
34-
_mydir = os.path.abspath(resource_filename(__name__, ""))
33+
_mydir = os.path.abspath(str(files(__name__)))
3534
_upbasedir = os.path.normpath(_mydir + "/../../..")
3635
_development_mode = os.path.basename(_upbasedir) == "src" and os.path.isfile(
37-
os.path.join(_upbasedir, "../setup.py")
36+
os.path.join(_upbasedir, "../pyproject.toml")
3837
)
3938

4039
# Requirement must have egg-info. Do not use in _development_mode.
41-
_req = Requirement.parse("diffpy.pdfgui")
40+
_req = "diffpy.pdfgui"
4241

4342
# pavol
4443
# APPDATADIR = (os.path.dirname(_upbasedir) if _development_mode
45-
# else resource_filename(_req, ""))
44+
# else str(files(_req)))
4645
# long
4746
if _development_mode:
4847
APPDATADIR = os.path.dirname(_mydir)
4948
else:
50-
APPDATADIR = os.path.join(resource_filename(_req, ""), "diffpy/pdfgui")
49+
APPDATADIR = str(files(_req))
5150

5251
APPDATADIR = os.path.abspath(APPDATADIR)
5352

src/diffpy/pdfgui/tests/__init__.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,12 @@ def testsuite(pattern=""):
3535
The TestSuite object containing the matching tests.
3636
"""
3737
import re
38+
from importlib.resources import files
3839
from itertools import chain
3940
from os.path import dirname
4041

41-
from pkg_resources import resource_filename
42-
4342
loader = unittest.defaultTestLoader
44-
thisdir = resource_filename(__name__, "")
43+
thisdir = str(files(__name__))
4544
depth = __name__.count(".") + 1
4645
topdir = thisdir
4746
for i in range(depth):

src/diffpy/pdfgui/tests/testutils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929

3030

3131
def datafile(filename):
32-
from pkg_resources import resource_filename
32+
from importlib.resources import files
3333

34-
rv = resource_filename(__name__, "testdata/" + filename)
34+
rv = str(files(__name__).joinpath("testdata", filename))
3535
return rv
3636

3737

src/diffpy/pdfgui/version.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@
2525
__all__ = ["__date__", "__git_commit__", "__timestamp__", "__version__"]
2626

2727
import os.path
28-
29-
from pkg_resources import resource_filename
28+
from importlib.resources import files
3029

3130
# obtain version information from the version.cfg file
3231
cp = dict(version="", date="", commit="", timestamp="0")
33-
fcfg = resource_filename(__name__, "version.cfg")
32+
fcfg = str(files(__name__).joinpath("version.cfg"))
3433
if not os.path.isfile(fcfg): # pragma: no cover
3534
from warnings import warn
3635

37-
warn('Package metadata not found, execute "./setup.py egg_info".')
36+
warn("Package metadata not found.")
3837
fcfg = os.devnull
3938
with open(fcfg) as fp:
4039
kwords = [[w.strip() for w in line.split(" = ", 1)] for line in fp if line[:1].isalpha() and " = " in line]

0 commit comments

Comments
 (0)