Skip to content

Commit de63017

Browse files
committed
Format setup.py
1 parent 8fe702a commit de63017

File tree

1 file changed

+42
-39
lines changed

1 file changed

+42
-39
lines changed

setup.py

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
DEVTOOLS = "MsDev" if sys.platform == "win32" else "Mono"
2626
ARCH = "x64" if platform.architecture()[0] == "64bit" else "x86"
27+
PY_MAJOR = sys.version_info[0]
28+
PY_MINOR = sys.version_info[1]
2729

2830
###############################################################################
2931
# Windows Keys Constants for MSBUILD tools
@@ -144,9 +146,9 @@ def build_extension(self, ext):
144146
unicode_width = ctypes.sizeof(ctypes.c_wchar)
145147

146148
defines = [
147-
"PYTHON%d%d" % (sys.version_info[:2]),
148-
"PYTHON%d" % (sys.version_info[:1]), # Python Major Version
149-
"UCS%d" % unicode_width,
149+
"PYTHON{0}{1}".format(PY_MAJOR, PY_MINOR),
150+
"PYTHON{0}".format(PY_MAJOR), # Python Major Version
151+
"UCS{0}".format(unicode_width),
150152
]
151153

152154
if CONFIG == "Debug":
@@ -185,51 +187,49 @@ def build_extension(self, ext):
185187

186188
if DEVTOOLS == "MsDev":
187189
_xbuild = '"{0}"'.format(_find_msbuild_tool("msbuild.exe"))
188-
_defines_sep = ";"
189190
_config = "{0}Win".format(CONFIG)
190191

191192
elif DEVTOOLS == "Mono":
192193
_xbuild = "xbuild"
193-
_defines_sep = ","
194194
_config = "{0}Mono".format(CONFIG)
195195
else:
196196
raise NotImplementedError(
197197
"DevTool {0} not supported (use MsDev/Mono)".format(DEVTOOLS))
198198

199199
cmd = [
200200
_xbuild,
201-
"pythonnet.sln",
202-
"/p:Configuration=%s" % _config,
203-
"/p:Platform=%s" % ARCH,
204-
"/p:DefineConstants=\"%s\"" % _defines_sep.join(defines),
205-
"/p:PythonBuildDir=\"%s\"" % os.path.abspath(dest_dir),
206-
"/p:PythonInteropFile=\"%s\"" % os.path.basename(interop_file),
207-
"/verbosity:%s" % VERBOSITY,
201+
'pythonnet.sln',
202+
'/p:Configuration={}'.format(_config),
203+
'/p:Platform={}'.format(ARCH),
204+
'/p:DefineConstants="{}"'.format(','.join(defines)),
205+
'/p:PythonBuildDir="{}"'.format(os.path.abspath(dest_dir)),
206+
'/p:PythonInteropFile="{}"'.format(os.path.basename(interop_file)),
207+
'/verbosity:{}'.format(VERBOSITY),
208208
]
209209

210210
manifest = self._get_manifest(dest_dir)
211211
if manifest:
212-
cmd.append("/p:PythonManifest=\"%s\"" % manifest)
212+
cmd.append('/p:PythonManifest="{0}"'.format(manifest))
213213

214-
self.announce("Building: %s" % " ".join(cmd))
214+
self.announce("Building: {0}".format(" ".join(cmd)))
215215
use_shell = True if DEVTOOLS == "Mono" else False
216216
subprocess.check_call(" ".join(cmd + ["/t:Clean"]), shell=use_shell)
217217
subprocess.check_call(" ".join(cmd + ["/t:Build"]), shell=use_shell)
218218

219219
if DEVTOOLS == "Mono":
220-
self._build_monoclr(ext)
220+
self._build_monoclr()
221221

222222
def _get_manifest(self, build_dir):
223223
if DEVTOOLS == "MsDev" and sys.version_info[:2] > (2, 5):
224224
mt = _find_msbuild_tool("mt.exe", use_windows_sdk=True)
225225
manifest = os.path.abspath(os.path.join(build_dir, "app.manifest"))
226-
cmd = [mt, '-inputresource:"%s"' % sys.executable,
227-
'-out:"%s"' % manifest]
228-
self.announce("Extracting manifest from %s" % sys.executable)
226+
cmd = [mt, '-inputresource:"{0}"'.format(sys.executable),
227+
'-out:"{0}"'.format(manifest)]
228+
self.announce("Extracting manifest from {}".format(sys.executable))
229229
subprocess.check_call(" ".join(cmd), shell=False)
230230
return manifest
231231

232-
def _build_monoclr(self, ext):
232+
def _build_monoclr(self):
233233
mono_libs = _check_output("pkg-config --libs mono-2", shell=True)
234234
mono_cflags = _check_output("pkg-config --cflags mono-2", shell=True)
235235
glib_libs = _check_output("pkg-config --libs glib-2.0", shell=True)
@@ -238,13 +238,15 @@ def _build_monoclr(self, ext):
238238
libs = mono_libs.strip() + " " + glib_libs.strip()
239239

240240
# build the clr python module
241-
clr_ext = Extension("clr",
242-
sources=[
243-
"src/monoclr/pynetinit.c",
244-
"src/monoclr/clrmod.c"
245-
],
246-
extra_compile_args=cflags.split(" "),
247-
extra_link_args=libs.split(" "))
241+
clr_ext = Extension(
242+
"clr",
243+
sources=[
244+
"src/monoclr/pynetinit.c",
245+
"src/monoclr/clrmod.c"
246+
],
247+
extra_compile_args=cflags.split(" "),
248+
extra_link_args=libs.split(" ")
249+
)
248250

249251
build_ext.build_ext.build_extension(self, clr_ext)
250252

@@ -253,23 +255,23 @@ def _install_packages(self):
253255
nuget = os.path.join("tools", "nuget", "nuget.exe")
254256
use_shell = False
255257
if DEVTOOLS == "Mono":
256-
nuget = "mono %s" % nuget
258+
nuget = "mono {0}".format(nuget)
257259
use_shell = True
258260

259-
cmd = "%s update -self" % nuget
260-
self.announce("Updating NuGet: %s" % cmd)
261+
cmd = "{0} update -self".format(nuget)
262+
self.announce("Updating NuGet: {0}".format(cmd))
261263
subprocess.check_call(cmd, shell=use_shell)
262264

263-
cmd = "%s restore pythonnet.sln -o packages" % nuget
264-
self.announce("Installing packages: %s" % cmd)
265+
cmd = "{0} restore pythonnet.sln -o packages".format(nuget)
266+
self.announce("Installing packages: {0}".format(cmd))
265267
subprocess.check_call(cmd, shell=use_shell)
266268

267269

268270
class InstallLibPythonnet(install_lib.install_lib):
269271
def install(self):
270272
if not os.path.isdir(self.build_dir):
271-
self.warn("'%s' does not exist -- no Python modules to install" %
272-
self.build_dir)
273+
self.warn("'{0}' does not exist -- no Python modules"
274+
" to install".format(self.build_dir))
273275
return
274276

275277
if not os.path.exists(self.install_dir):
@@ -305,9 +307,9 @@ def run(self):
305307
def _check_output(*args, **kwargs):
306308
"""Check output wrapper for py2/py3 compatibility"""
307309
output = subprocess.check_output(*args, **kwargs)
308-
if sys.version_info[0] > 2:
309-
return output.decode("ascii")
310-
return output
310+
if PY_MAJOR == 2:
311+
return output
312+
return output.decode("ascii")
311313

312314

313315
def _get_interop_filename():
@@ -316,8 +318,9 @@ def _get_interop_filename():
316318
as most windows users won't have Clang installed, which is
317319
required to generate the file.
318320
"""
319-
interop_file = "interop%d%d%s.cs" % (sys.version_info[0], sys.version_info[1], getattr(sys, "abiflags", ""))
320-
return os.path.join("src", "runtime", interop_file)
321+
interop_filename = "interop{0}{1}{2}.cs".format(
322+
PY_MAJOR, PY_MINOR, getattr(sys, "abiflags", ""))
323+
return os.path.join("src", "runtime", interop_filename)
321324

322325

323326
if __name__ == "__main__":
@@ -382,5 +385,5 @@ def _get_interop_filename():
382385
"install_lib": InstallLibPythonnet,
383386
"install_data": InstallDataPythonnet,
384387
},
385-
setup_requires=setup_requires
388+
setup_requires=setup_requires,
386389
)

0 commit comments

Comments
 (0)