Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove various Python 2.6 related workarounds #5373

Merged
merged 8 commits into from Nov 5, 2015
7 changes: 1 addition & 6 deletions examples/misc/multiprocess.py
@@ -1,15 +1,10 @@
# Demo of using multiprocessing for generating data in one process and plotting
# in another.
# Written by Robert Cimrman
# Requires >= Python 2.6 for the multiprocessing module or having the
# standalone processing module installed

from __future__ import print_function
import time
try:
from multiprocessing import Process, Pipe
except ImportError:
from processing import Process, Pipe
from multiprocessing import Process, Pipe
import numpy as np

import matplotlib
Expand Down
7 changes: 4 additions & 3 deletions lib/matplotlib/__init__.py
Expand Up @@ -197,10 +197,11 @@ def _forward_ilshift(self, other):


major, minor1, minor2, s, tmp = sys.version_info
_python26 = (major == 2 and minor1 >= 6) or major >= 3
_python27 = (major == 2 and minor1 >= 7)
_python34 = (major == 3 and minor1 >= 4)

if not _python26:
raise ImportError('matplotlib requires Python 2.6 or later')
if not (_python27 or _python34):
raise ImportError('matplotlib requires Python 2.7 or 3.4 or later')


if not compare_versions(numpy.__version__, __version__numpy__):
Expand Down
19 changes: 1 addition & 18 deletions lib/matplotlib/backends/backend_pgf.py
Expand Up @@ -235,31 +235,14 @@ def get_latex_manager():
LatexManagerFactory.previous_instance = new_inst
return new_inst

class WeakSet(object):
# TODO: Poor man's weakref.WeakSet.
# Remove this once python 2.6 support is dropped from matplotlib.

def __init__(self):
self.weak_key_dict = weakref.WeakKeyDictionary()

def add(self, item):
self.weak_key_dict[item] = None

def discard(self, item):
if item in self.weak_key_dict:
del self.weak_key_dict[item]

def __iter__(self):
return six.iterkeys(self.weak_key_dict)


class LatexManager(object):
"""
The LatexManager opens an instance of the LaTeX application for
determining the metrics of text elements. The LaTeX environment can be
modified by setting fonts and/or a custem preamble in the rc parameters.
"""
_unclean_instances = WeakSet()
_unclean_instances = weakref.WeakSet()

@staticmethod
def _build_latex_header():
Expand Down
15 changes: 1 addition & 14 deletions lib/matplotlib/cbook.py
Expand Up @@ -191,20 +191,7 @@ def deprecate(func, message=message, name=name, alternative=alternative,
import textwrap

if isinstance(func, classmethod):
try:
func = func.__func__
except AttributeError:
# classmethods in Python2.6 and below lack the __func__
# attribute so we need to hack around to get it
method = func.__get__(None, object)
if hasattr(method, '__func__'):
func = method.__func__
elif hasattr(method, 'im_func'):
func = method.im_func
else:
# Nothing we can do really... just return the original
# classmethod
return func
func = func.__func__
is_classmethod = True
else:
is_classmethod = False
Expand Down
15 changes: 4 additions & 11 deletions lib/matplotlib/tests/test_labeled_data_unpacking.py
Expand Up @@ -7,17 +7,10 @@
# 3.2+ versions
from nose.tools import assert_regex, assert_not_regex
except ImportError:
try:
# 2.7 versions
from nose.tools import assert_regexp_matches, assert_not_regexp_matches
assert_regex = assert_regexp_matches
assert_not_regex = assert_not_regexp_matches
except ImportError:
# 2.6 versions
def noop(txt, regex):
raise SkipTest("No assert for regex matching in py2.6")
assert_regex = noop
assert_not_regex = noop
# 2.7 versions
from nose.tools import assert_regexp_matches, assert_not_regexp_matches
assert_regex = assert_regexp_matches
assert_not_regex = assert_not_regexp_matches

from ..testing import assert_produces_warning

Expand Down
8 changes: 3 additions & 5 deletions lib/matplotlib/tests/test_spines.py
Expand Up @@ -2,7 +2,7 @@
unicode_literals)

import numpy as np
from nose.tools import assert_true
from nose.tools import assert_true, assert_less
from matplotlib.externals import six

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

spine = ax.spines['bottom']
spinebbox = spine.get_transform().transform_path(
spine.get_path()).get_extents()
# replace with assert_less if >python2.6
assert_true(ax.xaxis.label.get_position()[1] < spinebbox.ymin,
assert_less(ax.xaxis.label.get_position()[1], spinebbox.ymin,
"X-Axis label not below the spine")
37 changes: 6 additions & 31 deletions setupext.py
Expand Up @@ -9,6 +9,7 @@
import os
import re
import subprocess
from subprocess import check_output
import sys
import warnings
from textwrap import fill
Expand All @@ -19,32 +20,6 @@
PY3 = (sys.version_info[0] >= 3)


try:
from subprocess import check_output
except ImportError:
# check_output is not available in Python 2.6
def check_output(*popenargs, **kwargs):
"""
Run command with arguments and return its output as a byte
string.

Backported from Python 2.7 as it's implemented as pure python
on stdlib.
"""
process = subprocess.Popen(
stdout=subprocess.PIPE, *popenargs, **kwargs)
output, unused_err = process.communicate()
retcode = process.poll()
if retcode:
cmd = kwargs.get("args")
if cmd is None:
cmd = popenargs[0]
error = subprocess.CalledProcessError(retcode, cmd)
error.output = output
raise error
return output


if sys.platform != 'win32':
if sys.version_info[0] < 3:
from commands import getstatusoutput
Expand Down Expand Up @@ -554,13 +529,13 @@ def check(self):

if major < 2:
raise CheckFailed(
"Requires Python 2.6 or later")
elif major == 2 and minor1 < 6:
"Requires Python 2.7 or later")
elif major == 2 and minor1 < 7:
raise CheckFailed(
"Requires Python 2.6 or later (in the 2.x series)")
elif major == 3 and minor1 < 1:
"Requires Python 2.7 or later (in the 2.x series)")
elif major == 3 and minor1 < 4:
raise CheckFailed(
"Requires Python 3.1 or later (in the 3.x series)")
"Requires Python 3.4 or later (in the 3.x series)")

return sys.version

Expand Down