Skip to content

Commit ff9273c

Browse files
committed
Remove Python 2 fallbacks in setup code.
1 parent 485f08b commit ff9273c

File tree

2 files changed

+15
-62
lines changed

2 files changed

+15
-62
lines changed

setup.py

-2
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@
119119
'Intended Audience :: Science/Research',
120120
'License :: OSI Approved :: Python Software Foundation License',
121121
'Programming Language :: Python',
122-
'Programming Language :: Python :: 2.7',
123122
'Programming Language :: Python :: 3',
124-
'Programming Language :: Python :: 3.4',
125123
'Programming Language :: Python :: 3.5',
126124
'Programming Language :: Python :: 3.6',
127125
'Topic :: Scientific/Engineering :: Visualization',

setupext.py

+15-60
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,15 @@
1111
import os
1212
import platform
1313
import re
14+
import shutil
1415
import subprocess
1516
from subprocess import check_output
1617
import sys
1718
import warnings
1819
from textwrap import fill
19-
import shutil
2020
import versioneer
2121

2222

23-
PY3min = (sys.version_info[0] >= 3)
24-
25-
2623
def _get_xdg_cache_dir():
2724
"""
2825
Return the XDG cache directory.
@@ -57,16 +54,10 @@ def _get_xdg_cache_dir():
5754
LOCAL_FREETYPE_HASH = _freetype_hashes.get(LOCAL_FREETYPE_VERSION, 'unknown')
5855

5956
if sys.platform != 'win32':
60-
if not PY3min:
61-
from commands import getstatusoutput
62-
else:
63-
from subprocess import getstatusoutput
57+
from subprocess import getstatusoutput
6458

6559

66-
if PY3min:
67-
import configparser
68-
else:
69-
import ConfigParser as configparser
60+
import configparser
7061

7162

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

8172
setup_cfg = os.environ.get('MPLSETUPCFG', 'setup.cfg')
8273
if os.path.exists(setup_cfg):
83-
if PY3min:
84-
config = configparser.ConfigParser()
85-
else:
86-
config = configparser.SafeConfigParser()
74+
config = configparser.ConfigParser()
8775
config.read(setup_cfg)
8876

8977
if config.has_option('status', 'suppress'):
@@ -564,11 +552,7 @@ def _try_managers(*managers):
564552
for manager in managers:
565553
pkg_name = self.pkg_names.get(manager, None)
566554
if pkg_name:
567-
try:
568-
# `shutil.which()` can be used when Python 2.7 support
569-
# is dropped. It is available in Python 3.3+
570-
_ = check_output(["which", manager],
571-
stderr=subprocess.STDOUT)
555+
if shutil.which(manager) is not None:
572556
if manager == 'port':
573557
pkgconfig = 'pkgconfig'
574558
else:
@@ -577,8 +561,6 @@ def _try_managers(*managers):
577561
'and pkg-config with `{1} install {3}`'
578562
.format(self.name, manager, pkg_name,
579563
pkgconfig))
580-
except subprocess.CalledProcessError:
581-
pass
582564

583565
message = None
584566
if sys.platform == "win32":
@@ -809,15 +791,6 @@ def check(self):
809791
except ImportError:
810792
msgs += [bad_pytest]
811793

812-
if PY3min:
813-
msgs += ['using unittest.mock']
814-
else:
815-
try:
816-
import mock
817-
msgs += ['using mock %s' % mock.__version__]
818-
except ImportError:
819-
msgs += [msg_template.format(package='mock')]
820-
821794
return ' / '.join(msgs)
822795

823796
def get_packages(self):
@@ -934,19 +907,12 @@ class Numpy(SetupPackage):
934907

935908
@staticmethod
936909
def include_dirs_hook():
937-
if PY3min:
938-
import builtins
939-
if hasattr(builtins, '__NUMPY_SETUP__'):
940-
del builtins.__NUMPY_SETUP__
941-
import imp
942-
import numpy
943-
imp.reload(numpy)
944-
else:
945-
import __builtin__
946-
if hasattr(__builtin__, '__NUMPY_SETUP__'):
947-
del __builtin__.__NUMPY_SETUP__
948-
import numpy
949-
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)
950916

951917
ext = Extension('test', [])
952918
ext.include_dirs.append(numpy.get_include())
@@ -1143,11 +1109,7 @@ def do_custom_build(self):
11431109
if (tarball_cache_path is not None and
11441110
os.path.isfile(tarball_cache_path)):
11451111
if get_file_hash(tarball_cache_path) == LOCAL_FREETYPE_HASH:
1146-
try:
1147-
os.makedirs('build')
1148-
except OSError:
1149-
# Don't care if it exists.
1150-
pass
1112+
os.makedirs('build', exist_ok=True)
11511113
try:
11521114
shutil.copy(tarball_cache_path, tarball_path)
11531115
print('Using cached tarball: {}'
@@ -1157,10 +1119,7 @@ def do_custom_build(self):
11571119
pass
11581120

11591121
if not os.path.isfile(tarball_path):
1160-
if PY3min:
1161-
from urllib.request import urlretrieve
1162-
else:
1163-
from urllib import urlretrieve
1122+
from urllib.request import urlretrieve
11641123

11651124
if not os.path.exists('build'):
11661125
os.makedirs('build')
@@ -1190,11 +1149,7 @@ def do_custom_build(self):
11901149
"You can download the file by "
11911150
"alternative means and copy it "
11921151
" to '{0}'".format(tarball_path))
1193-
try:
1194-
os.makedirs(tarball_cache_dir)
1195-
except OSError:
1196-
# Don't care if it exists.
1197-
pass
1152+
os.makedirs(tarball_cache_dir, exist_ok=True)
11981153
try:
11991154
shutil.copy(tarball_path, tarball_cache_path)
12001155
print('Cached tarball at: {}'.format(tarball_cache_path))
@@ -1473,7 +1428,7 @@ def check(self):
14731428
def runtime_check(self):
14741429
""" Checks whether TkAgg runtime dependencies are met
14751430
"""
1476-
pkg_name = 'tkinter' if PY3min else 'Tkinter'
1431+
pkg_name = 'tkinter'
14771432
try:
14781433
import_module(pkg_name)
14791434
except ImportError:

0 commit comments

Comments
 (0)