Skip to content

Commit 08fead2

Browse files
Remove all __future__ imports, PY2 checks and version checks
The version checks are not needed since packaging tools handle dependencies.
1 parent a07911a commit 08fead2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+32
-289
lines changed

labscript_utils/__init__.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os
1616
import traceback
1717
from pathlib import Path
18+
import importlib
1819

1920
from .versions import get_version, NoVersionInfo
2021
__version__ = get_version(__name__, import_path=Path(__file__).parent.parent)
@@ -48,11 +49,8 @@ def import_or_reload(modulename):
4849
"""
4950
# see if the proposed module is already loaded
5051
# if so, we will need to re-run the code contained in it
51-
import importlib
52-
if not PY2:
53-
reload = importlib.reload
5452
if modulename in sys.modules.keys():
55-
reload(sys.modules[modulename])
53+
importlib.reload(sys.modules[modulename])
5654
return sys.modules[modulename]
5755
module = importlib.import_module(modulename)
5856
return module
@@ -105,14 +103,8 @@ def dedent(s):
105103
import labscript_utils.double_import_denier
106104
labscript_utils.double_import_denier.enable()
107105

108-
try:
109-
# If zprocess is new enough, disable the 'quick edit' feature of Windows' cmd.exe,
110-
# which causes console applicatons to freeze if their console windows are merely
111-
# clicked on. This causes all kinds of headaches, so we disable it in all labscript
112-
# programs:
113-
import zprocess
114-
if hasattr(zprocess, 'disable_quick_edit'):
115-
# Feature is present in zprocess > 2.10.0, but if not present we just ignore.
116-
zprocess.disable_quick_edit()
117-
except ImportError:
118-
pass
106+
# Disable the 'quick edit' feature of Windows' cmd.exe, which causes console applicatons
107+
# to freeze if their console windows are merely clicked on. This causes all kinds of
108+
# headaches, so we disable it in all labscript programs:
109+
import zprocess
110+
zprocess.disable_quick_edit()

labscript_utils/camera_server.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,14 @@
1010
# for the full license. #
1111
# #
1212
#####################################################################
13-
from __future__ import division, unicode_literals, print_function, absolute_import
14-
from labscript_utils import PY2
15-
if PY2:
16-
str = unicode
17-
1813
import sys
1914
import time
2015
import zprocess
21-
from labscript_utils import check_version
2216
import labscript_utils.shared_drive
2317
# importing this wraps zlock calls around HDF file openings and closings:
2418
import labscript_utils.h5_lock
2519
import h5py
2620
import numpy as np
27-
check_version('zprocess', '1.3.3', '3.0')
2821

2922
# This file implements the protocol for a camera server, that is, a program
3023
# that BLACS can interface with to control cameras. It contains a class that

labscript_utils/connections.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# #
1212
#####################################################################
1313

14-
from __future__ import division, unicode_literals, print_function, absolute_import
1514
import labscript_utils.h5_lock, h5py
1615
import labscript_utils.properties
1716
import logging
@@ -22,9 +21,6 @@
2221
from labscript_utils.dict_diff import dict_diff
2322
import sys
2423
from zprocess import raise_exception_in_thread
25-
from labscript_utils import PY2
26-
if PY2:
27-
str = unicode
2824

2925
def _ensure_str(s):
3026
"""convert bytestrings and numpy strings to python strings"""

labscript_utils/excepthook/__init__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# #
1212
#####################################################################
1313

14-
from __future__ import division, unicode_literals, print_function, absolute_import
1514
import sys
1615
import os
1716
import threading
@@ -97,9 +96,6 @@ def set_logger(logger):
9796
# part of the Python standard library. I'll make it a dependency for
9897
# packaging, but this is an extra check at runtime so that if something
9998
# goes wrong with that we get an error at import rather than later:
100-
if sys.version_info[0] == 2:
101-
import Tkinter
102-
else:
103-
import tkinter
99+
import tkinter
104100
sys.excepthook = tkhandler
105101
install_thread_excepthook()

labscript_utils/excepthook/tk_exception.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@
1414
import sys
1515
import os
1616

17-
if sys.version < '3':
18-
import Tkinter as tkinter
19-
import Tkconstants as constants
20-
else:
21-
import tkinter
22-
import tkinter.constants as constants
17+
import tkinter
18+
import tkinter.constants as constants
2319

2420
error_im_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'error.gif')
2521

labscript_utils/filewatcher.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,8 @@
1010
# for the full license. #
1111
# #
1212
#####################################################################
13-
from __future__ import division, unicode_literals, print_function, absolute_import
14-
from labscript_utils import PY2
15-
if PY2:
16-
str = unicode
17-
from inspect import getargspec as getfullargspec
18-
from Queue import Queue, Empty
19-
else:
20-
from inspect import getfullargspec
21-
from queue import Queue, Empty
22-
13+
from inspect import getfullargspec
14+
from queue import Queue, Empty
2315
import threading
2416
import os
2517
import hashlib
@@ -145,7 +137,7 @@ def _modified_info_of_file(self, name):
145137
# Otherwise use last modified time for modified_info
146138
elif os.path.isdir(name):
147139
# Modified info of a directory is a hash of its entries:
148-
entries = os.listdir(name if PY2 else os.fsencode(name))
140+
entries = os.listdir(os.fsencode(name))
149141
return hashlib.md5(b'\0'.join(entries)).hexdigest()
150142
else:
151143
return os.path.getmtime(name)

labscript_utils/h5_lock.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,12 @@
1010
# for the full license. #
1111
# #
1212
#####################################################################
13-
from __future__ import division, unicode_literals, print_function, absolute_import
14-
1513
import sys
1614
import os
17-
import traceback
1815

1916
from labscript_utils.ls_zprocess import Lock, connect_to_zlock_server, kill_lock
20-
21-
from labscript_utils import check_version, dedent
22-
17+
from labscript_utils import dedent
2318
from labscript_utils.shared_drive import path_to_agnostic
24-
from labscript_utils import PY2
25-
if PY2:
26-
str = unicode
2719

2820
if 'h5py' in sys.modules:
2921
import labscript_utils.double_import_denier
@@ -43,9 +35,6 @@
4335
raise ImportError('h5_lock must be imported prior to importing h5py')
4436

4537
import h5py
46-
# This module used to contain a monkeypatch to work around an issue now fixed in h5py.
47-
# Depend on the fix since we no longer have the monkeypatch.
48-
check_version('h5py', '2.9', '3')
4938

5039
_File = h5py.File
5140
class File(_File):

labscript_utils/impprof.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
# for the full license. #
1111
# #
1212
#####################################################################
13-
from __future__ import division, unicode_literals, print_function, absolute_import
14-
1513
import time
1614

1715
class _ProfilingImporter(object):

labscript_utils/labconfig.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
# for the full license. #
1111
# #
1212
#####################################################################
13-
from __future__ import division, unicode_literals, print_function, absolute_import
14-
1513
import sys
1614
import os
1715
import socket

labscript_utils/ls_zprocess.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,11 @@
1010
# for the full license. #
1111
# #
1212
#####################################################################
13-
from __future__ import division, unicode_literals, print_function, absolute_import
14-
from labscript_utils import PY2
15-
if PY2:
16-
str = unicode
17-
1813
import sys
1914
from socket import gethostbyname
2015
from distutils.version import LooseVersion
2116
import zmq
2217

23-
from labscript_utils import check_version
24-
check_version('zprocess', '2.18.0', '3.0.0')
25-
2618
import zprocess
2719
import zprocess.process_tree
2820
from zprocess.security import SecureContext

labscript_utils/memprof.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
# for the full license. #
1111
# #
1212
#####################################################################
13-
from __future__ import division, unicode_literals, print_function, absolute_import
14-
from labscript_utils import PY2
15-
if PY2:
16-
str = unicode
17-
1813
import gc
1914

2015
class MemoryProfiler(object):

labscript_utils/modulewatcher.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
# for the full license. #
1111
# #
1212
#####################################################################
13-
from __future__ import division, unicode_literals, print_function, absolute_import
14-
1513
import sys
1614
import threading
1715
import time

labscript_utils/properties.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
from __future__ import division, unicode_literals, print_function, absolute_import
2-
from labscript_utils import PY2
3-
if PY2:
4-
str = unicode
51
import sys
62
import json
73
from base64 import b64encode, b64decode
8-
if PY2:
9-
from collections import Iterable, Mapping
10-
else:
11-
from collections.abc import Iterable, Mapping
4+
from collections.abc import Iterable, Mapping
125
import numpy as np
136

147

@@ -21,9 +14,6 @@
2114
"unit_conversion_parameters"
2215
}
2316

24-
if PY2:
25-
str = unicode
26-
2717

2818
def _check_dicts(o):
2919
if isinstance(o, Mapping):
@@ -77,8 +67,7 @@ def _default(o):
7767

7868
def serialise(value):
7969
_check_dicts(value)
80-
if not PY2:
81-
value = _encode_bytestrings(value)
70+
value = _encode_bytestrings(value)
8271
json_string = json.dumps(value, default=_default)
8372
return JSON_IDENTIFIER + json_string
8473

labscript_utils/qtwidgets/InputPlotWindow.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import division, unicode_literals, print_function, absolute_import
21
from zprocess import Process
32
import pyqtgraph as pg
43
import numpy as np
@@ -7,9 +6,6 @@
76
import zmq
87
from labscript_utils.labconfig import LabConfig
98
import threading
10-
from labscript_utils import PY2
11-
if PY2:
12-
memoryview = buffer
139

1410
# maximum amount of datapoints to be plotted at once
1511
MAX_DATA = 1000

labscript_utils/qtwidgets/__init__.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,4 @@
99
# BSD License. See the license.txt file in the root of the project #
1010
# for the full license. #
1111
# #
12-
#####################################################################
13-
from __future__ import division, unicode_literals, print_function, absolute_import
14-
15-
try:
16-
from labscript_utils import check_version
17-
except ImportError:
18-
raise ImportError('Require labscript_utils > 2.1.0')
19-
20-
check_version('qtutils', '2.1.0', '3.0.0')
12+
#####################################################################

labscript_utils/qtwidgets/analogoutput.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
# for the full license. #
1111
# #
1212
#####################################################################
13-
from __future__ import division, unicode_literals, print_function, absolute_import
14-
from labscript_utils import PY2
15-
if PY2:
16-
str = unicode
17-
1813
import sys
1914

2015
from qtutils.qt.QtCore import *
@@ -275,4 +270,4 @@ def unlock(self,notify_ao=True):
275270

276271

277272
sys.exit(qapplication.exec_())
278-
273+

labscript_utils/qtwidgets/ddsoutput.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
# for the full license. #
1111
# #
1212
#####################################################################
13-
from __future__ import division, unicode_literals, print_function, absolute_import
14-
1513
import sys
1614

1715
from qtutils.qt.QtCore import *
@@ -132,4 +130,4 @@ def show_sub_widget(self,subchnl):
132130

133131

134132
sys.exit(qapplication.exec_())
135-
133+

labscript_utils/qtwidgets/digitaloutput.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
# for the full license. #
1111
# #
1212
#####################################################################
13-
from __future__ import division, unicode_literals, print_function, absolute_import
14-
1513
import sys
1614

1715
from qtutils.qt.QtCore import *
@@ -119,4 +117,4 @@ def state(self,state):
119117

120118

121119
sys.exit(qapplication.exec_())
122-
120+

labscript_utils/qtwidgets/dragdroptab.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
# #
1212
#####################################################################
1313

14-
from __future__ import division, unicode_literals, print_function, absolute_import
15-
from labscript_utils import PY2
16-
if PY2:
17-
str = unicode
18-
1914
import weakref
2015
from collections import namedtuple, defaultdict
2116

labscript_utils/qtwidgets/elide_label.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import division, unicode_literals, print_function, absolute_import
21
import sys
32

43
from qtutils.qt.QtCore import *

labscript_utils/qtwidgets/enumoutput.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
# for the full license. #
1111
# #
1212
#####################################################################
13-
from __future__ import division, unicode_literals, print_function, absolute_import
14-
from labscript_utils import PY2
15-
if PY2:
16-
str = unicode
17-
1813
import sys
1914

2015
from qtutils.qt.QtCore import *

labscript_utils/qtwidgets/fingertab.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44
# This [trivial fingertab gist](https://gist.github.com/LegoStormtroopr/5075267) is released
55
# as Public Domain, but boy would it beswell if you could credit me, or tweet me
66
# [@LegoStormtoopr](http://www.twitter.com/legostormtroopr) to say thanks!
7-
from __future__ import division, unicode_literals, print_function, absolute_import
8-
from labscript_utils import PY2
9-
if PY2:
10-
str = unicode
117

12-
import sys
138
from qtutils.qt import QtCore, QtGui, QtWidgets
149

1510

labscript_utils/qtwidgets/headerview_with_widgets.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import division, unicode_literals, print_function, absolute_import
21
from qtutils.qt import QtCore, QtGui, QtWidgets
32

43

0 commit comments

Comments
 (0)