11
11
import os
12
12
import platform
13
13
import re
14
+ import shutil
14
15
import subprocess
15
16
from subprocess import check_output
16
17
import sys
17
18
import warnings
18
19
from textwrap import fill
19
- import shutil
20
20
import versioneer
21
21
22
22
23
- PY3min = (sys .version_info [0 ] >= 3 )
24
-
25
-
26
23
def _get_xdg_cache_dir ():
27
24
"""
28
25
Return the XDG cache directory.
@@ -57,16 +54,10 @@ def _get_xdg_cache_dir():
57
54
LOCAL_FREETYPE_HASH = _freetype_hashes .get (LOCAL_FREETYPE_VERSION , 'unknown' )
58
55
59
56
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
64
58
65
59
66
- if PY3min :
67
- import configparser
68
- else :
69
- import ConfigParser as configparser
60
+ import configparser
70
61
71
62
72
63
# matplotlib build options, which can be altered using setup.cfg
@@ -80,10 +71,7 @@ def _get_xdg_cache_dir():
80
71
81
72
setup_cfg = os .environ .get ('MPLSETUPCFG' , 'setup.cfg' )
82
73
if os .path .exists (setup_cfg ):
83
- if PY3min :
84
- config = configparser .ConfigParser ()
85
- else :
86
- config = configparser .SafeConfigParser ()
74
+ config = configparser .ConfigParser ()
87
75
config .read (setup_cfg )
88
76
89
77
if config .has_option ('status' , 'suppress' ):
@@ -564,11 +552,7 @@ def _try_managers(*managers):
564
552
for manager in managers :
565
553
pkg_name = self .pkg_names .get (manager , None )
566
554
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 :
572
556
if manager == 'port' :
573
557
pkgconfig = 'pkgconfig'
574
558
else :
@@ -577,8 +561,6 @@ def _try_managers(*managers):
577
561
'and pkg-config with `{1} install {3}`'
578
562
.format (self .name , manager , pkg_name ,
579
563
pkgconfig ))
580
- except subprocess .CalledProcessError :
581
- pass
582
564
583
565
message = None
584
566
if sys .platform == "win32" :
@@ -809,15 +791,6 @@ def check(self):
809
791
except ImportError :
810
792
msgs += [bad_pytest ]
811
793
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
-
821
794
return ' / ' .join (msgs )
822
795
823
796
def get_packages (self ):
@@ -934,19 +907,12 @@ class Numpy(SetupPackage):
934
907
935
908
@staticmethod
936
909
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 )
950
916
951
917
ext = Extension ('test' , [])
952
918
ext .include_dirs .append (numpy .get_include ())
@@ -1143,11 +1109,7 @@ def do_custom_build(self):
1143
1109
if (tarball_cache_path is not None and
1144
1110
os .path .isfile (tarball_cache_path )):
1145
1111
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 )
1151
1113
try :
1152
1114
shutil .copy (tarball_cache_path , tarball_path )
1153
1115
print ('Using cached tarball: {}'
@@ -1157,10 +1119,7 @@ def do_custom_build(self):
1157
1119
pass
1158
1120
1159
1121
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
1164
1123
1165
1124
if not os .path .exists ('build' ):
1166
1125
os .makedirs ('build' )
@@ -1190,11 +1149,7 @@ def do_custom_build(self):
1190
1149
"You can download the file by "
1191
1150
"alternative means and copy it "
1192
1151
" 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 )
1198
1153
try :
1199
1154
shutil .copy (tarball_path , tarball_cache_path )
1200
1155
print ('Cached tarball at: {}' .format (tarball_cache_path ))
@@ -1473,7 +1428,7 @@ def check(self):
1473
1428
def runtime_check (self ):
1474
1429
""" Checks whether TkAgg runtime dependencies are met
1475
1430
"""
1476
- pkg_name = 'tkinter' if PY3min else 'Tkinter'
1431
+ pkg_name = 'tkinter'
1477
1432
try :
1478
1433
import_module (pkg_name )
1479
1434
except ImportError :
0 commit comments