Deprecate unused/unnecessary modules (#1576)

* Deprecate ordereddict module

* Import OrderedDict from collections module instead of pgcollections

* Deprecate pgcollections module

* Deprecate lru_cache module

A simpler recipe exists from the standard library using OrderedDict.

* Deprecate pil_fix module

* Python 3.7 compatibility fix

* Avoid or suppress deprecation warnings in tests
This commit is contained in:
lidstrom83 2021-02-15 09:52:06 -08:00 committed by GitHub
parent 5210c55e67
commit 6519734932
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 77 additions and 29 deletions

View File

@ -6,7 +6,7 @@ import subprocess
from argparse import Namespace
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore, QT_LIB
from pyqtgraph.pgcollections import OrderedDict
from collections import OrderedDict
from .utils import examples
path = os.path.abspath(os.path.dirname(__file__))

View File

@ -11,7 +11,7 @@ as it can be converted to/from a string using repr and eval.
import re, os, sys, datetime
import numpy
from .pgcollections import OrderedDict
from collections import OrderedDict
from . import units
from .python2_3 import asUnicode, basestring
from .Qt import QtCore

View File

@ -2,7 +2,7 @@
import pytest
import pyqtgraph as pg
from pyqtgraph.ordereddict import OrderedDict
from collections import OrderedDict
pg.mkQApp()
import pyqtgraph.dockarea as da

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from ..Qt import QtCore, QtGui, QT_LIB
from .Node import *
from ..pgcollections import OrderedDict
from collections import OrderedDict
from ..widgets.TreeWidget import *
from .. import FileDialog, DataTreeWidget

View File

@ -3,7 +3,7 @@ from ..Qt import QtCore, QtGui, QtWidgets
from ..graphicsItems.GraphicsObject import GraphicsObject
from .. import functions as fn
from .Terminal import *
from ..pgcollections import OrderedDict
from collections import OrderedDict
from ..debug import *
import numpy as np
import warnings

View File

@ -1,4 +1,4 @@
from ..pgcollections import OrderedDict
from collections import OrderedDict
from .Node import Node
def isNodeClass(cls):

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from ...pgcollections import OrderedDict
from collections import OrderedDict
import os, types
from ...debug import printExc
from ..NodeLibrary import NodeLibrary, isNodeClass

View File

@ -21,7 +21,7 @@ from . import debug, reload
from .Qt import QtGui, QtCore, QT_LIB, QtVersion
from . import Qt
from .metaarray import MetaArray
from .pgcollections import OrderedDict
from collections import OrderedDict
from .python2_3 import asUnicode, basestring
Colors = {

View File

@ -4,7 +4,7 @@ import time
from datetime import datetime, timedelta
from .AxisItem import AxisItem
from ..pgcollections import OrderedDict
from collections import OrderedDict
__all__ = ['DateAxisItem']

View File

@ -7,7 +7,7 @@ from .. import functions as fn
from .GraphicsObject import GraphicsObject
from .GraphicsWidget import GraphicsWidget
from ..widgets.SpinBox import SpinBox
from ..pgcollections import OrderedDict
from collections import OrderedDict
from ..colormap import ColorMap
translate = QtCore.QCoreApplication.translate

View File

@ -1,4 +1,5 @@
import warnings
from collections import OrderedDict
from functools import reduce
from ..Qt import QtGui, QtCore, isQObjectAlive
from ..GraphicsScene import GraphicsScene
@ -6,7 +7,29 @@ from ..Point import Point
from .. import functions as fn
import weakref
import operator
from ..util.lru_cache import LRUCache
# Recipe from https://docs.python.org/3.8/library/collections.html#collections.OrderedDict
# slightly adapted for Python 3.7 compatibility
class LRU(OrderedDict):
'Limit size, evicting the least recently looked-up key when full'
def __init__(self, maxsize=128, *args, **kwds):
self.maxsize = maxsize
super().__init__(*args, **kwds)
def __getitem__(self, key):
value = super().__getitem__(key)
self.move_to_end(key)
return value
def __setitem__(self, key, value):
if key in self:
self.move_to_end(key)
super().__setitem__(key, value)
if len(self) > self.maxsize:
oldest = next(iter(self))
del self[oldest]
class GraphicsItem(object):
@ -20,7 +43,7 @@ class GraphicsItem(object):
The GraphicsView system places a lot of emphasis on the notion that the graphics within the scene should be device independent--you should be able to take the same graphics and display them on screens of different resolutions, printers, export to SVG, etc. This is nice in principle, but causes me a lot of headache in practice. It means that I have to circumvent all the device-independent expectations any time I want to operate in pixel coordinates rather than arbitrary scene coordinates. A lot of the code in GraphicsItem is devoted to this task--keeping track of view widgets and device transforms, computing the size and shape of a pixel in local item coordinates, etc. Note that in item coordinates, a pixel does not have to be square or even rectangular, so just asking how to increase a bounding rect by 2px can be a rather complex task.
"""
_pixelVectorGlobalCache = LRUCache(100, 70)
_pixelVectorGlobalCache = LRU(100)
def __init__(self, register=None):
if not hasattr(self, '_qtBaseClass'):

View File

@ -14,7 +14,7 @@ from .. import functions as fn
from .GraphicsItem import GraphicsItem
from .GraphicsObject import GraphicsObject
from .. import getConfigOption
from ..pgcollections import OrderedDict
from collections import OrderedDict
from .. import debug
from ..python2_3 import basestring

View File

@ -20,6 +20,12 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
import warnings
warnings.warn(
"OrderedDict is in the standard library for supported versions of Python. Will be removed in 0.13",
DeprecationWarning, stacklevel=2
)
import sys
if sys.version[0] > '2':
from collections import OrderedDict

View File

@ -2,7 +2,7 @@
from .. import functions as fn
from ..Qt import QtGui, QtCore
import os, weakref, re
from ..pgcollections import OrderedDict
from collections import OrderedDict
from ..python2_3 import asUnicode, basestring
from .ParameterItem import ParameterItem
import warnings

View File

@ -1,4 +1,4 @@
from ..pgcollections import OrderedDict
from collections import OrderedDict
import numpy as np
import copy

View File

@ -8,7 +8,7 @@ from ..widgets.ColorButton import ColorButton
from ..colormap import ColorMap
from .. import icons as icons
from .. import functions as fn
from ..pgcollections import OrderedDict
from collections import OrderedDict
class WidgetParameterItem(ParameterItem):

View File

@ -10,15 +10,17 @@ Includes:
- ThreadsafeDict, ThreadsafeList - Self-mutexed data structures
"""
import warnings
warnings.warn(
"None of these are used in pyqtgraph. Will be removed in 0.13",
DeprecationWarning, stacklevel=2
)
import threading
import sys
import copy
try:
from collections import OrderedDict
except ImportError:
# fallback: try to use the ordereddict backport when using python 2.6
from ordereddict import OrderedDict
from collections import OrderedDict
try:
from collections.abc import Sequence

View File

@ -1,3 +1,9 @@
import warnings
warnings.warn(
"No longer used in pyqtgraph. Will be removed in 0.13",
DeprecationWarning, stacklevel=2
)
import operator
import sys
import itertools

View File

@ -5,6 +5,12 @@ This works by patching objects in the PIL namespace; no files are
modified.
"""
import warnings
warnings.warn(
"Not used in pyqtgraph. Will be removed in 0.13",
DeprecationWarning, stacklevel=2
)
from PIL import Image
if Image.VERSION == '1.1.7':

View File

@ -1,4 +1,9 @@
from pyqtgraph.util.lru_cache import LRUCache
import warnings
with warnings.catch_warnings():
warnings.simplefilter('ignore')
from pyqtgraph.util.lru_cache import LRUCache
def testLRU():
lru = LRUCache(2, 1)

View File

@ -1,7 +1,7 @@
from ..Qt import QtGui, QtCore
from .. import parametertree as ptree
import numpy as np
from ..pgcollections import OrderedDict
from collections import OrderedDict
from .. import functions as fn
__all__ = ['ColorMapWidget']

View File

@ -1,7 +1,7 @@
import sys
from ..Qt import QtGui, QtCore
from ..SignalProxy import SignalProxy
from ..pgcollections import OrderedDict
from collections import OrderedDict
from ..python2_3 import asUnicode, basestring

View File

@ -1,7 +1,7 @@
from ..Qt import QtGui, QtCore
from .. import parametertree as ptree
import numpy as np
from ..pgcollections import OrderedDict
from collections import OrderedDict
from .. import functions as fn
from ..python2_3 import basestring

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from ..Qt import QtGui, QtCore
from ..pgcollections import OrderedDict
from collections import OrderedDict
from .TableWidget import TableWidget
from ..python2_3 import asUnicode
import types, traceback

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from ..Qt import QtGui, QtCore
from ..pgcollections import OrderedDict
from collections import OrderedDict
from .DataTreeWidget import DataTreeWidget
from .. import functions as fn
import types, traceback

View File

@ -7,7 +7,7 @@ from .. import functions as fn
from .. import getConfigOption
from ..graphicsItems.TextItem import TextItem
import numpy as np
from ..pgcollections import OrderedDict
from collections import OrderedDict
__all__ = ['ScatterPlotWidget']

View File

@ -1,6 +1,6 @@
import pyqtgraph as pg
import numpy as np
from pyqtgraph.pgcollections import OrderedDict
from collections import OrderedDict
app = pg.mkQApp()