Merge pull request #1943 from ntjess/rm-py2-codepaths

Remove python 2 code paths
This commit is contained in:
Ogi Moore 2021-08-02 10:19:29 -07:00 committed by GitHub
commit fb2e684f45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 54 additions and 106 deletions

View File

@ -129,9 +129,6 @@ def renamePyc(startDir):
os.rename(fileName, name2) os.rename(fileName, name2)
path = os.path.split(__file__)[0] path = os.path.split(__file__)[0]
if __version__ is None and not hasattr(sys, 'frozen') and sys.version_info[0] == 2: ## If we are frozen, there's a good chance we don't have the original .py files anymore.
renamePyc(path)
## Import almost everything to make it available from a single namespace ## Import almost everything to make it available from a single namespace
## don't import the more complex systems--canvas, parametertree, flowchart, dockarea ## don't import the more complex systems--canvas, parametertree, flowchart, dockarea

View File

@ -240,14 +240,11 @@ class EvalNode(Node):
fn = "def fn(**args):\n" fn = "def fn(**args):\n"
run = "\noutput=fn(**args)\n" run = "\noutput=fn(**args)\n"
text = fn + "\n".join([" "+l for l in self.text.toPlainText().split('\n')]) + run text = fn + "\n".join([" "+l for l in self.text.toPlainText().split('\n')]) + run
if sys.version_info.major == 2: ldict = locals()
exec(text) exec(text, globals(), ldict)
elif sys.version_info.major == 3: output = ldict['output']
ldict = locals()
exec(text, globals(), ldict)
output = ldict['output']
except: except:
print("Error processing node: %s" % self.name()) print(f"Error processing node: {self.name()}")
raise raise
return output return output

View File

@ -843,36 +843,31 @@ class AxisItem(GraphicsWidget):
def logTickStrings(self, values, scale, spacing): def logTickStrings(self, values, scale, spacing):
estrings = ["%0.1g"%x for x in 10 ** np.array(values).astype(float) * np.array(scale)] estrings = ["%0.1g"%x for x in 10 ** np.array(values).astype(float) * np.array(scale)]
convdict = {"0": "",
if sys.version_info < (3, 0): "1": "¹",
# python 2 does not support unicode strings like that "2": "²",
return estrings "3": "³",
else: # python 3+ "4": "",
convdict = {"0": "", "5": "",
"1": "¹", "6": "",
"2": "²", "7": "",
"3": "³", "8": "",
"4": "", "9": "",
"5": "", }
"6": "", dstrings = []
"7": "", for e in estrings:
"8": "", if e.count("e"):
"9": "", v, p = e.split("e")
} sign = "" if p[0] == "-" else ""
dstrings = [] pot = "".join([convdict[pp] for pp in p[1:].lstrip("0")])
for e in estrings: if v == "1":
if e.count("e"): v = ""
v, p = e.split("e")
sign = "" if p[0] == "-" else ""
pot = "".join([convdict[pp] for pp in p[1:].lstrip("0")])
if v == "1":
v = ""
else:
v = v + "·"
dstrings.append(v + "10" + sign + pot)
else: else:
dstrings.append(e) v = v + "·"
return dstrings dstrings.append(v + "10" + sign + pot)
else:
dstrings.append(e)
return dstrings
def generateDrawSpecs(self, p): def generateDrawSpecs(self, p):
""" """

View File

@ -9,12 +9,8 @@ Distributed under MIT/X11 license. See license.txt for more information.
import sys import sys
import warnings import warnings
if sys.version_info[0] < 3: from time import perf_counter as clock
from time import clock from time import time as system_time
from time import time as system_time
else:
from time import perf_counter as clock
from time import time as system_time
START_TIME = None START_TIME = None
time = None time = None

View File

@ -30,9 +30,6 @@ except ImportError:
orig_reload = reload orig_reload = reload
py3 = sys.version_info >= (3,)
def reloadAll(prefix=None, debug=False): def reloadAll(prefix=None, debug=False):
"""Automatically reload all modules whose __file__ begins with *prefix*. """Automatically reload all modules whose __file__ begins with *prefix*.
@ -239,7 +236,7 @@ def updateClass(old, new, debug):
## but it fixes a few specific cases (pyqt signals, for one) ## but it fixes a few specific cases (pyqt signals, for one)
for attr in dir(old): for attr in dir(old):
oa = getattr(old, attr) oa = getattr(old, attr)
if (py3 and inspect.isfunction(oa)) or inspect.ismethod(oa): if inspect.isfunction(oa) or inspect.ismethod(oa):
# note python2 has unbound methods, whereas python3 just uses plain functions # note python2 has unbound methods, whereas python3 just uses plain functions
try: try:
na = getattr(new, attr) na = getattr(new, attr)

View File

@ -9,8 +9,6 @@ import sys
import itertools import itertools
_IS_PY3 = sys.version_info[0] == 3
class LRUCache(object): class LRUCache(object):
''' '''
This LRU cache should be reasonable for short collections (until around 100 items), as it does a This LRU cache should be reasonable for short collections (until around 100 items), as it does a
@ -37,10 +35,7 @@ class LRUCache(object):
self.resizeTo = resizeTo self.resizeTo = resizeTo
self._counter = 0 self._counter = 0
self._dict = {} self._dict = {}
if _IS_PY3: self._nextTime = itertools.count(0).__next__
self._nextTime = itertools.count(0).__next__
else:
self._nextTime = itertools.count(0).next
def __getitem__(self, key): def __getitem__(self, key):
item = self._dict[key] item = self._dict[key]
@ -74,54 +69,25 @@ class LRUCache(object):
def clear(self): def clear(self):
self._dict.clear() self._dict.clear()
if _IS_PY3: def values(self):
def values(self): return [i[1] for i in self._dict.values()]
return [i[1] for i in self._dict.values()]
def keys(self): def keys(self):
return [x[0] for x in self._dict.values()] return [x[0] for x in self._dict.values()]
def _resizeTo(self): def _resizeTo(self):
ordered = sorted(self._dict.values(), key=operator.itemgetter(2))[:self.resizeTo] ordered = sorted(self._dict.values(), key=operator.itemgetter(2))[:self.resizeTo]
for i in ordered: for i in ordered:
del self._dict[i[0]] del self._dict[i[0]]
def items(self, accessTime=False): def items(self, accessTime=False):
''' '''
:param bool accessTime: :param bool accessTime:
If True sorts the returned items by the internal access time. If True sorts the returned items by the internal access time.
''' '''
if accessTime: if accessTime:
for x in sorted(self._dict.values(), key=operator.itemgetter(2)): for x in sorted(self._dict.values(), key=operator.itemgetter(2)):
yield x[0], x[1] yield x[0], x[1]
else: else:
for x in self._dict.items(): for x in self._dict.items():
yield x[0], x[1] yield x[0], x[1]
else:
def values(self):
return [i[1] for i in self._dict.values()]
def keys(self):
return [x[0] for x in self._dict.values()]
def _resizeTo(self):
ordered = sorted(self._dict.values(), key=operator.itemgetter(2))[:self.resizeTo]
for i in ordered:
del self._dict[i[0]]
def items(self, accessTime=False):
'''
============= ======================================================
**Arguments**
accessTime (bool) If True sorts the returned items by the
internal access time.
============= ======================================================
'''
if accessTime:
for x in sorted(self._dict.values(), key=operator.itemgetter(2)):
yield x[0], x[1]
else:
for x in self._dict.items():
yield x[0], x[1]