update setup script so the egg/wheel created has the right files in the right places

This commit is contained in:
Tony Roberts 2014-02-27 13:39:07 +00:00
Родитель fd309f5e17
Коммит 5a1e055e03
1 изменённых файлов: 55 добавлений и 13 удалений

Просмотреть файл

@ -4,9 +4,12 @@ an egg or wheel.
"""
from setuptools import setup, Extension
from distutils.command.build_ext import build_ext
from distutils.command.build_scripts import build_scripts
from distutils.command.install_lib import install_lib
from distutils.sysconfig import get_config_vars
from platform import architecture
from subprocess import Popen, CalledProcessError, PIPE, check_call
from glob import glob
import shutil
import sys
import os
@ -24,11 +27,13 @@ if DEVTOOLS == "MsDev":
_xbuild = cc.find_exe("msbuild.exe")
_defines_sep = ";"
_config = "%sWin" % CONFIG
_npython_exe = "nPython.exe"
elif DEVTOOLS == "Mono":
_xbuild = "xbuild"
_defines_sep = ","
_config = "%sMono" % CONFIG
_npython_exe = "npython"
else:
raise NotImplementedError("DevTools %s not supported (use MsDev or Mono)" % DEVTOOLS)
@ -42,7 +47,7 @@ class PythonNET_BuildExt(build_ext):
Builds the .pyd file using msbuild or xbuild.
"""
if ext.name != "clr":
return super(PythonNET_BuildExt, self).build_extension(ext)
return build_ext.build_extension(self, ext)
dest_file = self.get_ext_fullpath(ext.name)
dest_dir = os.path.dirname(dest_file)
@ -85,17 +90,15 @@ class PythonNET_BuildExt(build_ext):
libs = mono_libs.strip() + " " + glib_libs.strip()
# build the clr python module
setup(name="monoclr",
ext_modules=[
Extension("clr",
clr_ext = Extension("clr",
sources=[
"src/monoclr/pynetinit.c",
"src/monoclr/clrmod.c"
],
extra_compile_args=cflags.split(" "),
extra_link_args=libs.split(" "),
)]
)
extra_link_args=libs.split(" "))
build_ext.build_extension(self, clr_ext)
# build the clr python executable
sources = [
@ -120,7 +123,7 @@ class PythonNET_BuildExt(build_ext):
libs += " " + py_libs
self.compiler.link_executable(objects,
"npython",
_npython_exe,
output_dir=output_dir,
libraries=self.get_libraries(ext),
library_dirs=ext.library_dirs,
@ -129,6 +132,41 @@ class PythonNET_BuildExt(build_ext):
debug=self.debug)
class PythonNET_InstallLib(install_lib):
def install(self):
if not os.path.isdir(self.build_dir):
self.warn("'%s' does not exist -- no Python modules to install" %
self.build_dir)
return
if not os.path.exists(self.install_dir):
self.mkpath(self.install_dir)
# only copy clr.pyd and its dependencies
for pattern in ("clr.*", "Python.Runtime.*"):
for srcfile in glob(os.path.join(self.build_dir, pattern)):
destfile = os.path.join(self.install_dir, os.path.basename(srcfile))
self.copy_file(srcfile, destfile)
class PythonNET_BuildScripts(build_scripts):
def finalize_options(self):
build_scripts.finalize_options(self)
# fixup scripts to look in the build_ext output folder
if self.scripts:
build_ext = self.get_finalized_command("build_ext")
output_dir = os.path.dirname(build_ext.get_ext_fullpath(_npython_exe))
scripts = []
for script in self.scripts:
if os.path.exists(os.path.join(output_dir, script)):
script = os.path.join(output_dir, script)
scripts.append(script)
self.scripts = scripts
def _check_output(*popenargs, **kwargs):
"""subprocess.check_output from python 2.7.
Added here to support building for earlier versions
@ -147,11 +185,15 @@ def _check_output(*popenargs, **kwargs):
if __name__ == "__main__":
setup(name="pythonnet",
ext_modules=[
ext_modules=[
Extension("clr", sources=[])
],
cmdclass = {
"build_ext" : PythonNET_BuildExt
}
],
scripts=[_npython_exe],
zip_safe=False,
cmdclass={
"build_ext" : PythonNET_BuildExt,
"build_scripts" : PythonNET_BuildScripts,
"install_lib" : PythonNET_InstallLib
}
)