Skip to content

Commit 18beeb9

Browse files
committed
Merge pull request #5373 from jenshnielsen/python26removal
CLN: Remove various Python 2.6 related workarounds
2 parents 79bb387 + dc7debc commit 18beeb9

File tree

7 files changed

+20
-88
lines changed

7 files changed

+20
-88
lines changed

examples/misc/multiprocess.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
# Demo of using multiprocessing for generating data in one process and plotting
22
# in another.
33
# Written by Robert Cimrman
4-
# Requires >= Python 2.6 for the multiprocessing module or having the
5-
# standalone processing module installed
64

75
from __future__ import print_function
86
import time
9-
try:
10-
from multiprocessing import Process, Pipe
11-
except ImportError:
12-
from processing import Process, Pipe
7+
from multiprocessing import Process, Pipe
138
import numpy as np
149

1510
import matplotlib

lib/matplotlib/__init__.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,11 @@ def _forward_ilshift(self, other):
197197

198198

199199
major, minor1, minor2, s, tmp = sys.version_info
200-
_python26 = (major == 2 and minor1 >= 6) or major >= 3
200+
_python27 = (major == 2 and minor1 >= 7)
201+
_python34 = (major == 3 and minor1 >= 4)
201202

202-
if not _python26:
203-
raise ImportError('matplotlib requires Python 2.6 or later')
203+
if not (_python27 or _python34):
204+
raise ImportError('matplotlib requires Python 2.7 or 3.4 or later')
204205

205206

206207
if not compare_versions(numpy.__version__, __version__numpy__):

lib/matplotlib/backends/backend_pgf.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -235,31 +235,14 @@ def get_latex_manager():
235235
LatexManagerFactory.previous_instance = new_inst
236236
return new_inst
237237

238-
class WeakSet(object):
239-
# TODO: Poor man's weakref.WeakSet.
240-
# Remove this once python 2.6 support is dropped from matplotlib.
241-
242-
def __init__(self):
243-
self.weak_key_dict = weakref.WeakKeyDictionary()
244-
245-
def add(self, item):
246-
self.weak_key_dict[item] = None
247-
248-
def discard(self, item):
249-
if item in self.weak_key_dict:
250-
del self.weak_key_dict[item]
251-
252-
def __iter__(self):
253-
return six.iterkeys(self.weak_key_dict)
254-
255238

256239
class LatexManager(object):
257240
"""
258241
The LatexManager opens an instance of the LaTeX application for
259242
determining the metrics of text elements. The LaTeX environment can be
260243
modified by setting fonts and/or a custem preamble in the rc parameters.
261244
"""
262-
_unclean_instances = WeakSet()
245+
_unclean_instances = weakref.WeakSet()
263246

264247
@staticmethod
265248
def _build_latex_header():

lib/matplotlib/cbook.py

+1-14
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,7 @@ def deprecate(func, message=message, name=name, alternative=alternative,
191191
import textwrap
192192

193193
if isinstance(func, classmethod):
194-
try:
195-
func = func.__func__
196-
except AttributeError:
197-
# classmethods in Python2.6 and below lack the __func__
198-
# attribute so we need to hack around to get it
199-
method = func.__get__(None, object)
200-
if hasattr(method, '__func__'):
201-
func = method.__func__
202-
elif hasattr(method, 'im_func'):
203-
func = method.im_func
204-
else:
205-
# Nothing we can do really... just return the original
206-
# classmethod
207-
return func
194+
func = func.__func__
208195
is_classmethod = True
209196
else:
210197
is_classmethod = False

lib/matplotlib/tests/test_labeled_data_unpacking.py

+4-11
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,10 @@
77
# 3.2+ versions
88
from nose.tools import assert_regex, assert_not_regex
99
except ImportError:
10-
try:
11-
# 2.7 versions
12-
from nose.tools import assert_regexp_matches, assert_not_regexp_matches
13-
assert_regex = assert_regexp_matches
14-
assert_not_regex = assert_not_regexp_matches
15-
except ImportError:
16-
# 2.6 versions
17-
def noop(txt, regex):
18-
raise SkipTest("No assert for regex matching in py2.6")
19-
assert_regex = noop
20-
assert_not_regex = noop
10+
# 2.7 versions
11+
from nose.tools import assert_regexp_matches, assert_not_regexp_matches
12+
assert_regex = assert_regexp_matches
13+
assert_not_regex = assert_not_regexp_matches
2114

2215
from ..testing import assert_produces_warning
2316

lib/matplotlib/tests/test_spines.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
unicode_literals)
33

44
import numpy as np
5-
from nose.tools import assert_true
5+
from nose.tools import assert_true, assert_less
66
from matplotlib.externals import six
77

88
import matplotlib
@@ -71,13 +71,11 @@ def test_label_without_ticks():
7171
spine = ax.spines['left']
7272
spinebbox = spine.get_transform().transform_path(
7373
spine.get_path()).get_extents()
74-
# replace with assert_less if >python2.6
75-
assert_true(ax.yaxis.label.get_position()[0] < spinebbox.xmin,
74+
assert_less(ax.yaxis.label.get_position()[0], spinebbox.xmin,
7675
"Y-Axis label not left of the spine")
7776

7877
spine = ax.spines['bottom']
7978
spinebbox = spine.get_transform().transform_path(
8079
spine.get_path()).get_extents()
81-
# replace with assert_less if >python2.6
82-
assert_true(ax.xaxis.label.get_position()[1] < spinebbox.ymin,
80+
assert_less(ax.xaxis.label.get_position()[1], spinebbox.ymin,
8381
"X-Axis label not below the spine")

setupext.py

+6-31
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import os
1010
import re
1111
import subprocess
12+
from subprocess import check_output
1213
import sys
1314
import warnings
1415
from textwrap import fill
@@ -19,32 +20,6 @@
1920
PY3 = (sys.version_info[0] >= 3)
2021

2122

22-
try:
23-
from subprocess import check_output
24-
except ImportError:
25-
# check_output is not available in Python 2.6
26-
def check_output(*popenargs, **kwargs):
27-
"""
28-
Run command with arguments and return its output as a byte
29-
string.
30-
31-
Backported from Python 2.7 as it's implemented as pure python
32-
on stdlib.
33-
"""
34-
process = subprocess.Popen(
35-
stdout=subprocess.PIPE, *popenargs, **kwargs)
36-
output, unused_err = process.communicate()
37-
retcode = process.poll()
38-
if retcode:
39-
cmd = kwargs.get("args")
40-
if cmd is None:
41-
cmd = popenargs[0]
42-
error = subprocess.CalledProcessError(retcode, cmd)
43-
error.output = output
44-
raise error
45-
return output
46-
47-
4823
if sys.platform != 'win32':
4924
if sys.version_info[0] < 3:
5025
from commands import getstatusoutput
@@ -554,13 +529,13 @@ def check(self):
554529

555530
if major < 2:
556531
raise CheckFailed(
557-
"Requires Python 2.6 or later")
558-
elif major == 2 and minor1 < 6:
532+
"Requires Python 2.7 or later")
533+
elif major == 2 and minor1 < 7:
559534
raise CheckFailed(
560-
"Requires Python 2.6 or later (in the 2.x series)")
561-
elif major == 3 and minor1 < 1:
535+
"Requires Python 2.7 or later (in the 2.x series)")
536+
elif major == 3 and minor1 < 4:
562537
raise CheckFailed(
563-
"Requires Python 3.1 or later (in the 3.x series)")
538+
"Requires Python 3.4 or later (in the 3.x series)")
564539

565540
return sys.version
566541

0 commit comments

Comments
 (0)