Skip to content

Commit 2a45b53

Browse files
authored
Merge pull request matplotlib#10470 from QuLogic/py3-setup
BLD: Remove Python 2 code from setup
2 parents f3a9a65 + 943931c commit 2a45b53

File tree

3 files changed

+40
-79
lines changed

3 files changed

+40
-79
lines changed

lib/matplotlib/__init__.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@
105105

106106
import six
107107

108+
import sys
109+
if sys.version_info < (3, 5): # noqa: E402
110+
raise ImportError("""
111+
Matplotlib 3.0+ does not support Python 2.x, 3.0, 3.1, 3.2, 3.3, or 3.4.
112+
Beginning with Matplotlib 3.0, Python 3.5 and above is required.
113+
114+
See Matplotlib `INSTALL.rst` file for more information:
115+
116+
https://github.com/matplotlib/matplotlib/blob/master/INSTALL.rst
117+
118+
""")
119+
108120
import atexit
109121
from collections import MutableMapping
110122
import contextlib
@@ -121,21 +133,9 @@
121133
import re
122134
import shutil
123135
import stat
124-
import sys
125136
import tempfile
126137
import warnings
127138

128-
if sys.version_info < (3, 5): # noqa: E402
129-
raise ImportError("""
130-
Matplotlib 3.0+ does not support Python 2.x, 3.0, 3.1, 3.2, 3.3, or 3.4.
131-
Beginning with Matplotlib 3.0, Python 3.5 and above is required.
132-
133-
See Matplotlib `INSTALL.rst` file for more information:
134-
135-
https://github.com/matplotlib/matplotlib/blob/master/INSTALL.rst
136-
137-
""")
138-
139139
# cbook must import matplotlib only within function
140140
# definitions, so it is safe to import from it here.
141141
from . import cbook

setup.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414

1515
import sys
1616

17+
if sys.version_info < (3, 5):
18+
error = """
19+
Matplotlib 3.0+ does not support Python 2.x, 3.0, 3.1, 3.2, 3.3, or 3.4.
20+
Beginning with Matplotlib 3.0, Python 3.5 and above is required.
21+
22+
This may be due to an out of date pip.
23+
24+
Make sure you have pip >= 9.0.1.
25+
"""
26+
sys.exit(error)
27+
1728
# distutils is breaking our sdists for files in symlinked dirs.
1829
# distutils will copy if os.link is not available, so this is a hack
1930
# to force copying
@@ -108,9 +119,7 @@
108119
'Intended Audience :: Science/Research',
109120
'License :: OSI Approved :: Python Software Foundation License',
110121
'Programming Language :: Python',
111-
'Programming Language :: Python :: 2.7',
112122
'Programming Language :: Python :: 3',
113-
'Programming Language :: Python :: 3.4',
114123
'Programming Language :: Python :: 3.5',
115124
'Programming Language :: Python :: 3.6',
116125
'Topic :: Scientific/Engineering :: Visualization',

setupext.py

+17-65
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# NOTE: This file must remain Python 2 compatible for the forseeable future,
2-
# to ensure that we error out properly for people with outdated setuptools
3-
# and/or pip.
41
from __future__ import print_function, absolute_import
52

63
from importlib import import_module
@@ -14,18 +11,15 @@
1411
import os
1512
import platform
1613
import re
14+
import shutil
1715
import subprocess
1816
from subprocess import check_output
1917
import sys
2018
import warnings
2119
from textwrap import fill
22-
import shutil
2320
import versioneer
2421

2522

26-
PY3min = (sys.version_info[0] >= 3)
27-
28-
2923
def _get_xdg_cache_dir():
3024
"""
3125
Return the XDG cache directory.
@@ -60,16 +54,10 @@ def _get_xdg_cache_dir():
6054
LOCAL_FREETYPE_HASH = _freetype_hashes.get(LOCAL_FREETYPE_VERSION, 'unknown')
6155

6256
if sys.platform != 'win32':
63-
if not PY3min:
64-
from commands import getstatusoutput
65-
else:
66-
from subprocess import getstatusoutput
57+
from subprocess import getstatusoutput
6758

6859

69-
if PY3min:
70-
import configparser
71-
else:
72-
import ConfigParser as configparser
60+
import configparser
7361

7462

7563
# matplotlib build options, which can be altered using setup.cfg
@@ -83,10 +71,7 @@ def _get_xdg_cache_dir():
8371

8472
setup_cfg = os.environ.get('MPLSETUPCFG', 'setup.cfg')
8573
if os.path.exists(setup_cfg):
86-
if PY3min:
87-
config = configparser.ConfigParser()
88-
else:
89-
config = configparser.SafeConfigParser()
74+
config = configparser.ConfigParser()
9075
config.read(setup_cfg)
9176

9277
if config.has_option('status', 'suppress'):
@@ -567,11 +552,7 @@ def _try_managers(*managers):
567552
for manager in managers:
568553
pkg_name = self.pkg_names.get(manager, None)
569554
if pkg_name:
570-
try:
571-
# `shutil.which()` can be used when Python 2.7 support
572-
# is dropped. It is available in Python 3.3+
573-
_ = check_output(["which", manager],
574-
stderr=subprocess.STDOUT)
555+
if shutil.which(manager) is not None:
575556
if manager == 'port':
576557
pkgconfig = 'pkgconfig'
577558
else:
@@ -580,8 +561,6 @@ def _try_managers(*managers):
580561
'and pkg-config with `{1} install {3}`'
581562
.format(self.name, manager, pkg_name,
582563
pkgconfig))
583-
except subprocess.CalledProcessError:
584-
pass
585564

586565
message = None
587566
if sys.platform == "win32":
@@ -812,15 +791,6 @@ def check(self):
812791
except ImportError:
813792
msgs += [bad_pytest]
814793

815-
if PY3min:
816-
msgs += ['using unittest.mock']
817-
else:
818-
try:
819-
import mock
820-
msgs += ['using mock %s' % mock.__version__]
821-
except ImportError:
822-
msgs += [msg_template.format(package='mock')]
823-
824794
return ' / '.join(msgs)
825795

826796
def get_packages(self):
@@ -937,19 +907,12 @@ class Numpy(SetupPackage):
937907

938908
@staticmethod
939909
def include_dirs_hook():
940-
if PY3min:
941-
import builtins
942-
if hasattr(builtins, '__NUMPY_SETUP__'):
943-
del builtins.__NUMPY_SETUP__
944-
import imp
945-
import numpy
946-
imp.reload(numpy)
947-
else:
948-
import __builtin__
949-
if hasattr(__builtin__, '__NUMPY_SETUP__'):
950-
del __builtin__.__NUMPY_SETUP__
951-
import numpy
952-
reload(numpy)
910+
import builtins
911+
if hasattr(builtins, '__NUMPY_SETUP__'):
912+
del builtins.__NUMPY_SETUP__
913+
import imp
914+
import numpy
915+
imp.reload(numpy)
953916

954917
ext = Extension('test', [])
955918
ext.include_dirs.append(numpy.get_include())
@@ -990,10 +953,10 @@ def add_flags(self, ext):
990953
ext.define_macros.append(('__STDC_FORMAT_MACROS', 1))
991954

992955
def get_setup_requires(self):
993-
return ['numpy>=1.7.1']
956+
return ['numpy>=1.10.0']
994957

995958
def get_install_requires(self):
996-
return ['numpy>=1.7.1']
959+
return ['numpy>=1.10.0']
997960

998961

999962
class LibAgg(SetupPackage):
@@ -1146,11 +1109,7 @@ def do_custom_build(self):
11461109
if (tarball_cache_path is not None and
11471110
os.path.isfile(tarball_cache_path)):
11481111
if get_file_hash(tarball_cache_path) == LOCAL_FREETYPE_HASH:
1149-
try:
1150-
os.makedirs('build')
1151-
except OSError:
1152-
# Don't care if it exists.
1153-
pass
1112+
os.makedirs('build', exist_ok=True)
11541113
try:
11551114
shutil.copy(tarball_cache_path, tarball_path)
11561115
print('Using cached tarball: {}'
@@ -1160,10 +1119,7 @@ def do_custom_build(self):
11601119
pass
11611120

11621121
if not os.path.isfile(tarball_path):
1163-
if PY3min:
1164-
from urllib.request import urlretrieve
1165-
else:
1166-
from urllib import urlretrieve
1122+
from urllib.request import urlretrieve
11671123

11681124
if not os.path.exists('build'):
11691125
os.makedirs('build')
@@ -1193,11 +1149,7 @@ def do_custom_build(self):
11931149
"You can download the file by "
11941150
"alternative means and copy it "
11951151
" to '{0}'".format(tarball_path))
1196-
try:
1197-
os.makedirs(tarball_cache_dir)
1198-
except OSError:
1199-
# Don't care if it exists.
1200-
pass
1152+
os.makedirs(tarball_cache_dir, exist_ok=True)
12011153
try:
12021154
shutil.copy(tarball_path, tarball_cache_path)
12031155
print('Cached tarball at: {}'.format(tarball_cache_path))
@@ -1480,7 +1432,7 @@ def check(self):
14801432
def runtime_check(self):
14811433
""" Checks whether TkAgg runtime dependencies are met
14821434
"""
1483-
pkg_name = 'tkinter' if PY3min else 'Tkinter'
1435+
pkg_name = 'tkinter'
14841436
try:
14851437
import_module(pkg_name)
14861438
except ImportError:

0 commit comments

Comments
 (0)