Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8b79b6f

Browse filesBrowse files
committed
Style fixes to setupext.py.
1 parent 912f9b6 commit 8b79b6f
Copy full SHA for 8b79b6f

File tree

Expand file treeCollapse file tree

1 file changed

+24
-32
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+24
-32
lines changed

‎setupext.py

Copy file name to clipboardExpand all lines: setupext.py
+24-32Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1+
import builtins
2+
import configparser
13
from distutils import sysconfig, version
24
from distutils.core import Extension
35
import distutils.command.build_ext
46
import glob
7+
import hashlib
8+
import importlib
59
import multiprocessing
610
import os
711
import pathlib
812
import platform
913
import re
1014
import shutil
1115
import subprocess
12-
from subprocess import check_output
1316
import sys
17+
import textwrap
18+
import urllib.request
1419
import warnings
15-
from textwrap import fill
1620

1721
import setuptools
1822
import versioneer
@@ -51,12 +55,6 @@ def _get_xdg_cache_dir():
5155
LOCAL_FREETYPE_VERSION = '2.6.1'
5256
LOCAL_FREETYPE_HASH = _freetype_hashes.get(LOCAL_FREETYPE_VERSION, 'unknown')
5357

54-
if sys.platform != 'win32':
55-
from subprocess import getstatusoutput
56-
57-
58-
import configparser
59-
6058

6159
# matplotlib build options, which can be altered using setup.cfg
6260
options = {
@@ -201,15 +199,15 @@ def print_line(char='='):
201199
def print_status(package, status):
202200
initial_indent = "%22s: " % package
203201
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))
207205

208206
def print_message(message):
209207
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))
213211

214212
def print_raw(section):
215213
print(section)
@@ -265,7 +263,6 @@ def get_file_hash(filename):
265263
"""
266264
Get the SHA256 hash of a given filename.
267265
"""
268-
import hashlib
269266
BLOCKSIZE = 1 << 16
270267
hasher = hashlib.sha256()
271268
with open(filename, 'rb') as fd:
@@ -293,13 +290,11 @@ def __init__(self):
293290
self.pkg_config = 'pkg-config'
294291

295292
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
298294
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")
303298

304299
def set_pkgconfig_path(self):
305300
pkgconfig_path = sysconfig.get_config_var('LIBDIR')
@@ -334,8 +329,8 @@ def setup_extension(self, ext, package, default_include_dirs=[],
334329
command = "{0} --libs --cflags ".format(executable)
335330

336331
try:
337-
output = check_output(command, shell=True,
338-
stderr=subprocess.STDOUT)
332+
output = subprocess.check_output(
333+
command, shell=True, stderr=subprocess.STDOUT)
339334
except subprocess.CalledProcessError:
340335
pass
341336
else:
@@ -369,7 +364,7 @@ def get_version(self, package):
369364
if not self.has_pkgconfig:
370365
return None
371366

372-
status, output = getstatusoutput(
367+
status, output = subprocess.getstatusoutput(
373368
self.pkg_config + " %s --modversion" % (package))
374369
if status == 0:
375370
return output
@@ -878,12 +873,10 @@ class Numpy(SetupPackage):
878873

879874
@staticmethod
880875
def include_dirs_hook():
881-
import builtins
882876
if hasattr(builtins, '__NUMPY_SETUP__'):
883877
del builtins.__NUMPY_SETUP__
884-
import imp
885878
import numpy
886-
imp.reload(numpy)
879+
importlib.reload(numpy)
887880

888881
ext = Extension('test', [])
889882
ext.include_dirs.append(numpy.get_include())
@@ -984,7 +977,8 @@ def check(self):
984977
check_include_file(get_include_dirs(), 'freetype2\\ft2build.h', 'freetype')
985978
return 'Using unknown version found on system.'
986979

987-
status, output = getstatusoutput("freetype-config --ftversion")
980+
status, output = subprocess.getstatusoutput(
981+
"freetype-config --ftversion")
988982
if status == 0:
989983
version = output
990984
else:
@@ -1090,8 +1084,6 @@ def do_custom_build(self):
10901084
pass
10911085

10921086
if not os.path.isfile(tarball_path):
1093-
from urllib.request import urlretrieve
1094-
10951087
if not os.path.exists('build'):
10961088
os.makedirs('build')
10971089

@@ -1107,7 +1099,7 @@ def do_custom_build(self):
11071099

11081100
print("Downloading {0}".format(tarball_url))
11091101
try:
1110-
urlretrieve(tarball_url, tarball_path)
1102+
urllib.request.urlretrieve(tarball_url, tarball_path)
11111103
except IOError: # URLError (a subclass) on Py3.
11121104
print("Failed to download {0}".format(tarball_url))
11131105
else:
@@ -1214,7 +1206,7 @@ def check(self):
12141206
check_include_file(get_include_dirs(), 'png.h', 'png')
12151207
return 'Using unknown version found on system.'
12161208

1217-
status, output = getstatusoutput("libpng-config --version")
1209+
status, output = subprocess.getstatusoutput("libpng-config --version")
12181210
if status == 0:
12191211
version = output
12201212
else:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.