1
+ import builtins
2
+ import configparser
1
3
from distutils import sysconfig , version
2
4
from distutils .core import Extension
3
5
import distutils .command .build_ext
4
6
import glob
7
+ import hashlib
8
+ import importlib
5
9
import multiprocessing
6
10
import os
7
11
import pathlib
8
12
import platform
9
13
import re
10
14
import shutil
11
15
import subprocess
12
- from subprocess import check_output
13
16
import sys
17
+ import textwrap
18
+ import urllib .request
14
19
import warnings
15
- from textwrap import fill
16
20
17
21
import setuptools
18
22
import versioneer
@@ -51,12 +55,6 @@ def _get_xdg_cache_dir():
51
55
LOCAL_FREETYPE_VERSION = '2.6.1'
52
56
LOCAL_FREETYPE_HASH = _freetype_hashes .get (LOCAL_FREETYPE_VERSION , 'unknown' )
53
57
54
- if sys .platform != 'win32' :
55
- from subprocess import getstatusoutput
56
-
57
-
58
- import configparser
59
-
60
58
61
59
# matplotlib build options, which can be altered using setup.cfg
62
60
options = {
@@ -201,15 +199,15 @@ def print_line(char='='):
201
199
def print_status (package , status ):
202
200
initial_indent = "%22s: " % package
203
201
indent = ' ' * 24
204
- print (fill (str (status ), width = 76 ,
205
- initial_indent = initial_indent ,
206
- subsequent_indent = indent ))
202
+ print (textwrap . fill (str (status ), width = 76 ,
203
+ initial_indent = initial_indent ,
204
+ subsequent_indent = indent ))
207
205
208
206
def print_message (message ):
209
207
indent = ' ' * 24 + "* "
210
- print (fill (str (message ), width = 76 ,
211
- initial_indent = indent ,
212
- subsequent_indent = indent ))
208
+ print (textwrap . fill (str (message ), width = 76 ,
209
+ initial_indent = indent ,
210
+ subsequent_indent = indent ))
213
211
214
212
def print_raw (section ):
215
213
print (section )
@@ -265,7 +263,6 @@ def get_file_hash(filename):
265
263
"""
266
264
Get the SHA256 hash of a given filename.
267
265
"""
268
- import hashlib
269
266
BLOCKSIZE = 1 << 16
270
267
hasher = hashlib .sha256 ()
271
268
with open (filename , 'rb' ) as fd :
@@ -293,13 +290,11 @@ def __init__(self):
293
290
self .pkg_config = 'pkg-config'
294
291
295
292
self .set_pkgconfig_path ()
296
- status , output = getstatusoutput (self .pkg_config + " --help" )
297
- self .has_pkgconfig = (status == 0 )
293
+ self .has_pkgconfig = shutil .which (self .pkg_config ) is not None
298
294
if not self .has_pkgconfig :
299
- print ("IMPORTANT WARNING:" )
300
- print (
301
- " pkg-config is not installed.\n "
302
- " matplotlib may not be able to find some of its dependencies" )
295
+ print ("IMPORTANT WARNING:\n "
296
+ " pkg-config is not installed.\n "
297
+ " matplotlib may not be able to find some of its dependencies" )
303
298
304
299
def set_pkgconfig_path (self ):
305
300
pkgconfig_path = sysconfig .get_config_var ('LIBDIR' )
@@ -334,8 +329,8 @@ def setup_extension(self, ext, package, default_include_dirs=[],
334
329
command = "{0} --libs --cflags " .format (executable )
335
330
336
331
try :
337
- output = check_output (command , shell = True ,
338
- stderr = subprocess .STDOUT )
332
+ output = subprocess . check_output (
333
+ command , shell = True , stderr = subprocess .STDOUT )
339
334
except subprocess .CalledProcessError :
340
335
pass
341
336
else :
@@ -369,7 +364,7 @@ def get_version(self, package):
369
364
if not self .has_pkgconfig :
370
365
return None
371
366
372
- status , output = getstatusoutput (
367
+ status , output = subprocess . getstatusoutput (
373
368
self .pkg_config + " %s --modversion" % (package ))
374
369
if status == 0 :
375
370
return output
@@ -878,12 +873,10 @@ class Numpy(SetupPackage):
878
873
879
874
@staticmethod
880
875
def include_dirs_hook ():
881
- import builtins
882
876
if hasattr (builtins , '__NUMPY_SETUP__' ):
883
877
del builtins .__NUMPY_SETUP__
884
- import imp
885
878
import numpy
886
- imp .reload (numpy )
879
+ importlib .reload (numpy )
887
880
888
881
ext = Extension ('test' , [])
889
882
ext .include_dirs .append (numpy .get_include ())
@@ -984,7 +977,8 @@ def check(self):
984
977
check_include_file (get_include_dirs (), 'freetype2\\ ft2build.h' , 'freetype' )
985
978
return 'Using unknown version found on system.'
986
979
987
- status , output = getstatusoutput ("freetype-config --ftversion" )
980
+ status , output = subprocess .getstatusoutput (
981
+ "freetype-config --ftversion" )
988
982
if status == 0 :
989
983
version = output
990
984
else :
@@ -1090,8 +1084,6 @@ def do_custom_build(self):
1090
1084
pass
1091
1085
1092
1086
if not os .path .isfile (tarball_path ):
1093
- from urllib .request import urlretrieve
1094
-
1095
1087
if not os .path .exists ('build' ):
1096
1088
os .makedirs ('build' )
1097
1089
@@ -1107,7 +1099,7 @@ def do_custom_build(self):
1107
1099
1108
1100
print ("Downloading {0}" .format (tarball_url ))
1109
1101
try :
1110
- urlretrieve (tarball_url , tarball_path )
1102
+ urllib . request . urlretrieve (tarball_url , tarball_path )
1111
1103
except IOError : # URLError (a subclass) on Py3.
1112
1104
print ("Failed to download {0}" .format (tarball_url ))
1113
1105
else :
@@ -1214,7 +1206,7 @@ def check(self):
1214
1206
check_include_file (get_include_dirs (), 'png.h' , 'png' )
1215
1207
return 'Using unknown version found on system.'
1216
1208
1217
- status , output = getstatusoutput ("libpng-config --version" )
1209
+ status , output = subprocess . getstatusoutput ("libpng-config --version" )
1218
1210
if status == 0 :
1219
1211
version = output
1220
1212
else :
0 commit comments