Skip to content

Commit

Permalink
replace pkg_resources.parse_version by packaging.version.Version
Browse files Browse the repository at this point in the history
  • Loading branch information
t20100 committed Jul 19, 2023
1 parent 34e82a3 commit 9cd14d0
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/silx/gui/hdf5/test/test_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import os
import tempfile
import numpy
from pkg_resources import parse_version
from packaging.version import Version
from contextlib import contextmanager
from silx.gui import qt
from silx.gui.utils.testutils import TestCaseQt
Expand All @@ -45,7 +45,7 @@
import pytest


h5py2_9 = parse_version(h5py.version.version) >= parse_version('2.9.0')
h5py2_9 = Version(h5py.version.version) >= Version('2.9.0')


@pytest.fixture(scope="class")
Expand Down
16 changes: 8 additions & 8 deletions src/silx/gui/plot/backends/BackendMatplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from typing import Tuple, Union
import numpy

from pkg_resources import parse_version as _parse_version
from packaging.version import Version


_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -494,7 +494,7 @@ def __init__(self, plot, parent=None):
# when getting the limits at the expense of a replot
self._dirtyLimits = True
self._axesDisplayed = True
self._matplotlibVersion = _parse_version(matplotlib.__version__)
self._matplotlibVersion = Version(matplotlib.__version__)

self.fig = Figure()
self.fig.set_facecolor("w")
Expand Down Expand Up @@ -527,7 +527,7 @@ def __init__(self, plot, parent=None):
self.ax2.set_autoscaley_on(True)

# this works but the figure color is left
if self._matplotlibVersion < _parse_version('2'):
if self._matplotlibVersion < Version('2'):
self.ax.set_axis_bgcolor('none')
else:
self.ax.set_facecolor('none')
Expand Down Expand Up @@ -1175,7 +1175,7 @@ def setXAxisLogarithmic(self, flag):
# Workaround for matplotlib 2.1.0 when one tries to set an axis
# to log scale with both limits <= 0
# In this case a draw with positive limits is needed first
if flag and self._matplotlibVersion >= _parse_version('2.1.0'):
if flag and self._matplotlibVersion >= Version('2.1.0'):
xlim = self.ax.get_xlim()
if xlim[0] <= 0 and xlim[1] <= 0:
self.ax.set_xlim(1, 10)
Expand All @@ -1187,7 +1187,7 @@ def setXAxisLogarithmic(self, flag):
def setYAxisLogarithmic(self, flag):
# Workaround for matplotlib 2.0 issue with negative bounds
# before switching to log scale
if flag and self._matplotlibVersion >= _parse_version('2.0.0'):
if flag and self._matplotlibVersion >= Version('2.0.0'):
redraw = False
for axis, dataRangeIndex in ((self.ax, 1), (self.ax2, 2)):
ylim = axis.get_ylim()
Expand Down Expand Up @@ -1300,7 +1300,7 @@ def _synchronizeBackgroundColors(self):

if self.ax.get_frame_on():
self.fig.patch.set_facecolor(backgroundColor)
if self._matplotlibVersion < _parse_version('2'):
if self._matplotlibVersion < Version('2'):
self.ax.set_axis_bgcolor(dataBackgroundColor)
else:
self.ax.set_facecolor(dataBackgroundColor)
Expand Down Expand Up @@ -1501,7 +1501,7 @@ def draw(self):

# Starting with mpl 2.1.0, toggling autoscale raises a ValueError
# in some situations. See #1081, #1136, #1163,
if self._matplotlibVersion >= _parse_version("2.0.0"):
if self._matplotlibVersion >= Version("2.0.0"):
try:
FigureCanvasQTAgg.draw(self)
except ValueError as err:
Expand Down Expand Up @@ -1557,7 +1557,7 @@ def replot(self):
self.draw()

# Workaround issue of rendering overlays with some matplotlib versions
if (_parse_version('1.5') <= self._matplotlibVersion < _parse_version('2.1') and
if (Version('1.5') <= self._matplotlibVersion < Version('2.1') and
not hasattr(self, '_firstReplot')):
self._firstReplot = False
if self._hasOverlays():
Expand Down
1 change: 0 additions & 1 deletion src/silx/gui/utils/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@


import io
from pkg_resources import parse_version
import matplotlib
import numpy

Expand Down
6 changes: 3 additions & 3 deletions src/silx/math/fft/basefft.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#
# ###########################################################################*/
import numpy as np
from pkg_resources import parse_version
from packaging.version import Version


def check_version(package, required_version):
Expand All @@ -37,8 +37,8 @@ def check_version(package, required_version):
ver = getattr(package, "version")
except Exception:
return False
req_v = parse_version(required_version)
ver_v = parse_version(ver)
req_v = Version(required_version)
ver_v = Version(ver)
return ver_v >= req_v


Expand Down
4 changes: 2 additions & 2 deletions src/silx/math/fft/npfft.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# ###########################################################################*/
import numpy as np
import warnings
from pkg_resources import parse_version
from packaging.version import Version

from .basefft import BaseFFT

Expand Down Expand Up @@ -76,7 +76,7 @@ def set_fft_norm(self):
self.numpy_args_ifft = {"norm": "ortho"}

elif self.normalize == "none": # no normalisation on both fft & ifft
if parse_version(np.version.version) < parse_version("1.20"):
if Version(np.version.version) < Version("1.20"):
# "backward" & "forward" keywords were introduced in 1.20 and we support numpy >= 1.8
warnings.warn(
"Numpy version %s does not allow to non-normalization. Effective normalization will be 'rescale'"
Expand Down
4 changes: 2 additions & 2 deletions src/silx/math/fft/test/test_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import logging
import numpy as np
import unittest
from pkg_resources import parse_version
from packaging.version import Version
import pytest
from tempfile import TemporaryDirectory
try:
Expand Down Expand Up @@ -282,7 +282,7 @@ def test_norms_fftw(self):
return self._test_norms_with_backend("fftw")

@unittest.skipIf(
parse_version(np.version.version) <= parse_version("1.19.5"),
Version(np.version.version) <= Version("1.19.5"),
"normalization does not work for numpy <= 1.19.5"
)
def test_norms_numpy(self):
Expand Down
6 changes: 3 additions & 3 deletions src/silx/utils/test/test_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import logging
import numpy
import pkg_resources
from packaging.version import Version
from silx.utils import number
from silx.utils import testutils

Expand Down Expand Up @@ -115,7 +115,7 @@ def testMantissa80(self):
self.skipIfFloat80NotSupported()
dtype = number.min_numerical_convertible_type("1000000000.00001013")

if pkg_resources.parse_version(numpy.version.version) <= pkg_resources.parse_version("1.10.4"):
if Version(numpy.version.version) <= Version("1.10.4"):
# numpy 1.8.2 -> Debian 8
# Checking a float128 precision with numpy 1.8.2 using abs(diff) is not working.
# It looks like the difference is done using float64 (diff == 0.0)
Expand Down Expand Up @@ -148,7 +148,7 @@ def skipIfFloat80NotSupported(self):

def testLosePrecisionUsingFloat80(self):
self.skipIfFloat80NotSupported()
if pkg_resources.parse_version(numpy.version.version) <= pkg_resources.parse_version("1.10.4"):
if Version(numpy.version.version) <= Version("1.10.4"):
self.skipTest("numpy > 1.10.4 expected")
# value does not fit even in a 128 bits mantissa
value = "1.0340282366920938463463374607431768211456"
Expand Down

0 comments on commit 9cd14d0

Please sign in to comment.