Skip to content

Commit 5359098

Browse files
committed
Organize imports
1 parent 9143b54 commit 5359098

File tree

1 file changed

+37
-38
lines changed

1 file changed

+37
-38
lines changed

setup.py

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,35 @@
66
an egg or wheel.
77
"""
88

9-
from setuptools import setup, Extension
10-
from distutils.command.build_ext import build_ext
11-
from distutils.command.install_lib import install_lib
12-
from distutils.command.install_data import install_data
13-
from distutils.sysconfig import get_config_var
14-
from distutils.spawn import find_executable
15-
from distutils import log
16-
from platform import architecture
17-
from subprocess import check_output, check_call
18-
from glob import glob
199
import fnmatch
20-
import sys
10+
import glob
2111
import os
12+
import platform
13+
import subprocess
14+
import sys
15+
import sysconfig
16+
from distutils import log, spawn
17+
from distutils.command import build_ext, install_data, install_lib
18+
19+
from setuptools import Extension, setup
2220

2321
CONFIG = "Release" # Release or Debug
24-
DEVTOOLS = "MsDev" if sys.platform == "win32" else "Mono"
2522
VERBOSITY = "minimal" # quiet, minimal, normal, detailed, diagnostic
26-
ARCH = "x64" if architecture()[0] == "64bit" else "x86"
23+
24+
DEVTOOLS = "MsDev" if sys.platform == "win32" else "Mono"
25+
ARCH = "x64" if platform.architecture()[0] == "64bit" else "x86"
2726

2827

2928
def _find_msbuild_tool(tool="msbuild.exe", use_windows_sdk=False):
3029
"""Return full path to one of the Microsoft build tools"""
31-
path = find_executable(tool)
30+
path = spawn.find_executable(tool)
3231
if path:
3332
return path
3433

35-
try:
36-
import _winreg
37-
except ImportError:
38-
import winreg as _winreg
34+
try: # PY2
35+
import _winreg as winreg
36+
except ImportError: # PY3
37+
import winreg
3938

4039
keys_to_check = []
4140
if use_windows_sdk:
@@ -64,16 +63,16 @@ def _find_msbuild_tool(tool="msbuild.exe", use_windows_sdk=False):
6463

6564
# read the possible tools paths from the various registry locations
6665
paths_to_check = []
67-
hreg = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
66+
hreg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
6867
try:
6968
for key_to_check in keys_to_check:
7069
sdk_name, key, value_name = key_to_check[:3]
7170
suffix = key_to_check[3] if len(key_to_check) > 3 else None
7271
hkey = None
7372
try:
74-
hkey = _winreg.OpenKey(hreg, key)
75-
val, type_ = _winreg.QueryValueEx(hkey, value_name)
76-
if type_ != _winreg.REG_SZ:
73+
hkey = winreg.OpenKey(hreg, key)
74+
val, type_ = winreg.QueryValueEx(hkey, value_name)
75+
if type_ != winreg.REG_SZ:
7776
continue
7877
if suffix:
7978
val = os.path.join(val, suffix)
@@ -119,11 +118,11 @@ def _find_msbuild_tool(tool="msbuild.exe", use_windows_sdk=False):
119118
"DevTools %s not supported (use MsDev or Mono)" % DEVTOOLS)
120119

121120

122-
class BuildExtPythonnet(build_ext):
121+
class BuildExtPythonnet(build_ext.build_ext):
123122
def build_extension(self, ext):
124123
"""Builds the .pyd file using msbuild or xbuild"""
125124
if ext.name != "clr":
126-
return build_ext.build_extension(self, ext)
125+
return build_ext.build_ext.build_extension(self, ext)
127126

128127
# install packages using nuget
129128
self._install_packages()
@@ -157,7 +156,7 @@ def build_extension(self, ext):
157156
defines.append("MONO_LINUX")
158157

159158
# Check if --enable-shared was set when Python was built
160-
enable_shared = get_config_var("Py_ENABLE_SHARED")
159+
enable_shared = sysconfig.get_config_var("Py_ENABLE_SHARED")
161160
if enable_shared:
162161
# Double-check if libpython is linked dynamically with python
163162
lddout = _check_output(["ldd", sys.executable])
@@ -179,7 +178,7 @@ def build_extension(self, ext):
179178
interop_file = _get_interop_filename()
180179
if not os.path.exists(interop_file):
181180
geninterop = os.path.join("tools", "geninterop", "geninterop.py")
182-
check_call([sys.executable, geninterop, interop_file])
181+
subprocess.check_call([sys.executable, geninterop, interop_file])
183182

184183
cmd = [
185184
_xbuild,
@@ -198,8 +197,8 @@ def build_extension(self, ext):
198197

199198
self.announce("Building: %s" % " ".join(cmd))
200199
use_shell = True if DEVTOOLS == "Mono" else False
201-
check_call(" ".join(cmd + ["/t:Clean"]), shell=use_shell)
202-
check_call(" ".join(cmd + ["/t:Build"]), shell=use_shell)
200+
subprocess.check_call(" ".join(cmd + ["/t:Clean"]), shell=use_shell)
201+
subprocess.check_call(" ".join(cmd + ["/t:Build"]), shell=use_shell)
203202

204203
if DEVTOOLS == "Mono":
205204
self._build_monoclr(ext)
@@ -211,7 +210,7 @@ def _get_manifest(self, build_dir):
211210
cmd = [mt, '-inputresource:"%s"' % sys.executable,
212211
'-out:"%s"' % manifest]
213212
self.announce("Extracting manifest from %s" % sys.executable)
214-
check_call(" ".join(cmd), shell=False)
213+
subprocess.check_call(" ".join(cmd), shell=False)
215214
return manifest
216215

217216
def _build_monoclr(self, ext):
@@ -231,7 +230,7 @@ def _build_monoclr(self, ext):
231230
extra_compile_args=cflags.split(" "),
232231
extra_link_args=libs.split(" "))
233232

234-
build_ext.build_extension(self, clr_ext)
233+
build_ext.build_ext.build_extension(self, clr_ext)
235234

236235
def _install_packages(self):
237236
"""install packages using nuget"""
@@ -243,14 +242,14 @@ def _install_packages(self):
243242

244243
cmd = "%s update -self" % nuget
245244
self.announce("Updating NuGet: %s" % cmd)
246-
check_call(cmd, shell=use_shell)
245+
subprocess.check_call(cmd, shell=use_shell)
247246

248247
cmd = "%s restore pythonnet.sln -o packages" % nuget
249248
self.announce("Installing packages: %s" % cmd)
250-
check_call(cmd, shell=use_shell)
249+
subprocess.check_call(cmd, shell=use_shell)
251250

252251

253-
class InstallLibPythonnet(install_lib):
252+
class InstallLibPythonnet(install_lib.install_lib):
254253
def install(self):
255254
if not os.path.isdir(self.build_dir):
256255
self.warn("'%s' does not exist -- no Python modules to install" %
@@ -261,13 +260,13 @@ def install(self):
261260
self.mkpath(self.install_dir)
262261

263262
# only copy clr.pyd/.so
264-
for srcfile in glob(os.path.join(self.build_dir, "clr.*")):
263+
for srcfile in glob.glob(os.path.join(self.build_dir, "clr.*")):
265264
destfile = os.path.join(
266265
self.install_dir, os.path.basename(srcfile))
267266
self.copy_file(srcfile, destfile)
268267

269268

270-
class InstallDataPythonnet(install_data):
269+
class InstallDataPythonnet(install_data.install_data):
271270
def run(self):
272271
build_cmd = self.get_finalized_command("build_ext")
273272
install_cmd = self.get_finalized_command("install")
@@ -284,12 +283,12 @@ def run(self):
284283
dest = data_files[0].format(install_platlib=install_platlib)
285284
self.data_files[i] = dest, data_files[1]
286285

287-
return install_data.run(self)
286+
return install_data.install_data.run(self)
288287

289288

290289
def _check_output(*args, **kwargs):
291290
"""Check output wrapper for py2/py3 compatibility"""
292-
output = check_output(*args, **kwargs)
291+
output = subprocess.check_output(*args, **kwargs)
293292
if sys.version_info[0] > 2:
294293
return output.decode("ascii")
295294
return output
@@ -312,7 +311,7 @@ def _get_interop_filename():
312311

313312
sources = []
314313
for ext in (".sln", ".snk", ".config"):
315-
sources.extend(glob("*" + ext))
314+
sources.extend(glob.glob("*" + ext))
316315

317316
for root, dirnames, filenames in os.walk("src"):
318317
for ext in (".cs", ".csproj", ".sln", ".snk", ".config", ".il",

0 commit comments

Comments
 (0)