From 5a1e055e0325aa891b85f913044d6a31bd5986e6 Mon Sep 17 00:00:00 2001 From: Tony Roberts Date: Thu, 27 Feb 2014 13:39:07 +0000 Subject: [PATCH 1/2] update setup script so the egg/wheel created has the right files in the right places --- pythonnet/setupmono.py | 68 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 13 deletions(-) diff --git a/pythonnet/setupmono.py b/pythonnet/setupmono.py index 7a0b02901..efb4dc2e3 100644 --- a/pythonnet/setupmono.py +++ b/pythonnet/setupmono.py @@ -4,9 +4,12 @@ """ 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 @@ _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 @@ def build_extension(self, 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 @@ def _build_monoclr(self, 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 @@ def _build_monoclr(self, 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 @@ def _build_monoclr(self, 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 + } ) From 9f4ed0ae666573463cd994dddc18dec5dd88b2bd Mon Sep 17 00:00:00 2001 From: Tony Roberts Date: Thu, 27 Feb 2014 13:47:13 +0000 Subject: [PATCH 2/2] Replace old setup.py with setupmono.py, modified to work on both linux and windows. Remove old unused Makefiles and out of date README.txt. --- .travis.yml | 2 +- pythonnet/Makefile | 193 ------------------------ pythonnet/setup.py | 246 ++++++++++++++++++++++++------- pythonnet/setupmono.py | 199 ------------------------- pythonnet/src/monoclr/Makefile | 51 ------- pythonnet/src/monoclr/README.txt | 23 --- 6 files changed, 193 insertions(+), 521 deletions(-) delete mode 100644 pythonnet/Makefile mode change 100755 => 100644 pythonnet/setup.py delete mode 100644 pythonnet/setupmono.py delete mode 100755 pythonnet/src/monoclr/Makefile delete mode 100644 pythonnet/src/monoclr/README.txt diff --git a/.travis.yml b/.travis.yml index 63d673adf..3c27f6ed6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ before_install: - sudo apt-get -qq install mono-devel mono-gmcs mono-xbuild nunit-console install: - cd pythonnet - - python setupmono.py build_ext --inplace + - python setup.py build_ext --inplace script: - export PYTHONPATH=`pwd` - ./npython src/tests/runtests.py diff --git a/pythonnet/Makefile b/pythonnet/Makefile deleted file mode 100644 index 1f6f01d42..000000000 --- a/pythonnet/Makefile +++ /dev/null @@ -1,193 +0,0 @@ -# Makefile for PythonNET -# usage: -# make PYTHON=/path/to/python -# make PYTHON=C:/Python25/python.exe -# make PYTHON=/path/to/python DEFINE=additional,defines CSCARGS=additional_args -# make clean - -RELEASE = pythonnet-2.0-alpha2 -KEYFILE = pythonnet.key - -PYTHON ?= python -PYTHONVER ?= $(shell $(PYTHON) -c "import sys; \ - print 'PYTHON%i%i' % sys.version_info[:2]") -UCS ?= $(shell $(PYTHON) -c "import sys; \ - print 'UCS%i' % ((sys.maxunicode > 65536) and 4 or 2)") -SITEPACKAGES = $(shell $(PYTHON) -c "from distutils.sysconfig import get_python_lib; \ - print get_python_lib(plat_specific=1, standard_lib=0)") -INSTALL=/usr/bin/install -m644 -# Contributed by VIKAS DHIMAN - - Thanks, Vikas! -ARCH_FULL = $(shell uname -m) -ifneq (, $(findstring 86, $(ARCH_FULL))) - ARCH = x86 -else - ARCH = x64 -endif - -ifeq ($(origin WINDIR), undefined) - RUNNER = mono - ILDASM = monodis - ILASM = ilasm - CSC = gmcs - RUNTIME_REF = - ALL = clr.so monoclr - GACUTIL = gacutil - SN = sn -else - RUNNER = - ILDASM = $${PROGRAMFILES}/Microsoft.NET/SDK/v2.0/Bin/ildasm.exe - ILASM = $${WINDIR}/Microsoft.NET/Framework/v2.0.50727/ilasm.exe - CSC = $${WINDIR}/Microsoft.NET/Framework/v2.0.50727/csc.exe - RUNTIME_REF = - ALL = - GACUTIL = $${PROGRAMFILES}/Microsoft.NET/SDK/v2.0/Bin/gacutil.exe /nologo - SN = $${PROGRAMFILES}/Microsoft.NET/SDK/v2.0/Bin/sn.exe /q -endif - -ifeq ($(origin DEFINE), undefined) - _DEFINE = -else - _DEFINE = /define:$(DEFINE) -endif - -ifeq ($(UCS), UCS4) - RUNTIME_REF = /reference:Mono.Posix.dll -endif - -CSC += /define:$(PYTHONVER) /define:$(UCS) $(_DEFINE) /nologo $(CSCARGS) - -BASEDIR = $(shell pwd) - -PYTHON_CS = $(wildcard $(BASEDIR)/src/console/*.cs) -RUNTIME_CS = $(wildcard $(BASEDIR)/src/runtime/*.cs) -TESTING_CS = $(wildcard $(BASEDIR)/src/testing/*.cs) -EMBED_CS = $(wildcard $(BASEDIR)/src/embed_tests/*.cs) - -all: Python.Runtime.dll python.exe Python.Test.dll clr.pyd $(ALL) - -cleanall: realclean all - -python.exe: Python.Runtime.dll $(PYTHON_CS) - cd "$(BASEDIR)/src/console"; \ - $(CSC) /target:exe /out:../../python.exe \ - /reference:../../Python.Runtime.dll /recurse:*.cs - -Python.Runtime.dll: $(RUNTIME_CS) - cd "$(BASEDIR)/src/runtime"; \ - $(CSC) /unsafe /target:library \ - $(RUNTIME_REF) /out:../../Python.Runtime.dll /recurse:*.cs - -# Contributed by VIKAS DHIMAN - - Thanks, Vikas! -src/runtime/clrmodule.il: src/runtime/clrmodule.pp.il -ifeq ($(origin WINDIR), undefined) - cd "$(BASEDIR)/src/runtime";\ - $(CPP) -C -P -x c++ -I $(ARCH) clrmodule.pp.il -o clrmodule.il -else - cd "$(BASEDIR)/src/runtime";\ - cp oldmodule.il clrmodule.il -endif - -clr.pyd: Python.Runtime.dll src/runtime/clrmodule.il - $(ILASM) /nologo /dll /quiet /output=clr.pyd \ - src/runtime/clrmodule.il - - -clr.so: Python.Runtime.dll src/monoclr/clrmod.c src/monoclr/pynetclr.h \ - src/monoclr/pynetinit.c - $(PYTHON) setup.py build_ext -i - - -Python.Test.dll: Python.Runtime.dll - cd "$(BASEDIR)/src/testing"; \ - $(CSC) /target:library /out:../../Python.Test.dll \ - /reference:../../Python.Runtime.dll,System.Windows.Forms.dll \ - /recurse:*.cs - -Python.EmbeddingTest.dll: Python.Runtime.dll $(EMBED_CS) - cd $(BASEDIR)/src/embed_tests; \ - $(CSC) /target:library /out:../../Python.EmbeddingTest.dll \ - /reference:../../Python.Runtime.dll,System.Windows.Forms.dll,nunit.framework \ - /recurse:*.cs - -.PHONY=clean -clean: - rm -f *.exe *.dll *.so *.pyd - make -C src/monoclr clean - -.PHONY=realclean -realclean: clean - find . \( -name \*.o -o -name \*.so -o -name \*.py[co] -o -name \ - \*.dll -o -name \*.exe -o -name \*.pdb -o -name \*.mdb \ - -o -name \*.pyd -o -name \*~ \) -exec rm -f {} \; - rm -f Python*.il Python*.il2 Python*.res - rm -rf build/ - cd src/console; rm -rf bin; rm -rf obj; cd ../..; - cd src/runtime; rm -rf bin; rm -rf obj; rm clrmodule.il; cd ../..; - cd src/testing; rm -rf bin; rm -rf obj; cd ../..; - cd src/embed_tests; rm -rf bin; rm -rf obj; rm -f TestResult.xml; cd ../..; - cd src/monoclr; make clean; cd ../.. - -.PHONY=test -test: all - rm -f ./src/tests/*.pyc - $(RUNNER) ./python.exe ./src/tests/runtests.py - -.PHONY=dist -dist: realclean - if ! [ -f $(KEYFILE) ]; then \ - echo "Could not find $(KEYFILE) to sign assemblies"; \ - exit 1; \ - fi - rm -rf ./$(RELEASE) - mkdir -p ./release/ - mkdir ./$(RELEASE) - cp ./Makefile ./$(RELEASE)/ - cp ./*.sln ./$(RELEASE)/ - cp ./*.mds ./$(RELEASE)/ - cp ./*.txt ./$(RELEASE)/ - cp ./*.py ./$(RELEASE)/ - svn export ./demo ./$(RELEASE)/demo/ - svn export ./doc ./$(RELEASE)/doc/ - svn export ./src ./$(RELEASE)/src/ - for PY in python2.4 python2.5; do \ - for PYUCS in UCS2 UCS4; do \ - make clean; \ - make PYTHON=$$PY UCS=$$PYUCS CSCARGS="/keyfile:$(BASEDIR)/$(KEYFILE) /optimize"; \ - mkdir ./$(RELEASE)/$$PY-$$PYUCS; \ - cp *.dll *.exe *.pyd *.so ./$(RELEASE)/$$PY-$$PYUCS/; \ - done; \ - done; - tar czf $(RELEASE).tar.gz ./$(RELEASE)/ - zip -r -6 $(RELEASE).zip ./$(RELEASE) - mv $(RELEASE).* ./release/ - rm -rf ./$(RELEASE)/ - -sign: - rm -f release/$(RELEASE)*.sig - cd release; md5sum $(RELEASE).tar.gz $(RELEASE).zip > \ - $(RELEASE).md5 - cd release; sha256sum $(RELEASE).tar.gz $(RELEASE).zip > \ - $(RELEASE).sha - cd release; gpg -sab $(RELEASE).zip - cd release; gpg -sab $(RELEASE).tar.gz - -dis: - $(ILDASM) Python.Runtime.dll /out=Python.Runtime.il - -asm: - $(ILASM) /dll /quiet \ - /resource=Python.Runtime.res /output=Python.Runtime.dll \ - Python.Runtime.il - -monoclr: - make -C $(BASEDIR)/src/monoclr PYTHON=$(PYTHON) - -run: python.exe - $(RUNNER) python.exe - -install: all - $(PYTHON) setup.py install - -mkkey: - $(SN) -k $(KEYFILE) - diff --git a/pythonnet/setup.py b/pythonnet/setup.py old mode 100755 new mode 100644 index c68c0789e..d1d66e06c --- a/pythonnet/setup.py +++ b/pythonnet/setup.py @@ -1,61 +1,199 @@ -#!/usr/bin/env python -# ========================================================================== -# This software is subject to the provisions of the Zope Public License, -# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. -# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED -# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS -# FOR A PARTICULAR PURPOSE. -# ========================================================================== -"""Setup file for Mono clr.so - -Author: Christian Heimes """ - -import os +Setup script for building clr.pyd and dependencies using mono and into +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 -from distutils.core import setup -from distutils.core import Extension -import subprocess +import os + +CONFIG = "Release" # Release or Debug +DEVTOOLS = "MsDev" if sys.platform == "win32" else "Mono" +VERBOSITY = "minimal" # quiet, minimal, normal, detailed, diagnostic + +if DEVTOOLS == "MsDev": + from distutils import msvc9compiler + msvc9compiler.VERSION = 11 + + cc = msvc9compiler.MSVCCompiler() + cc.initialize() + _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) + +_platform = "x64" if architecture()[0] == "64bit" else "x86" + +class PythonNET_BuildExt(build_ext): + + def build_extension(self, ext): + """ + Builds the .pyd file using msbuild or xbuild. + """ + if ext.name != "clr": + return build_ext.build_extension(self, ext) + + dest_file = self.get_ext_fullpath(ext.name) + dest_dir = os.path.dirname(dest_file) + if not os.path.exists(dest_dir): + os.makedirs(dest_dir) + + defines = [ + "PYTHON%d%s" % (sys.version_info[:2]), + "UCS2" if sys.maxunicode < 0x10FFFF else "UCS4", + ] + + if CONFIG == "Debug": + defines.extend(["DEBUG", "TRACE"]) + + cmd = [ + _xbuild, + "pythonnet.sln", + "/p:Configuration=%s" % _config, + "/p:Platform=%s" % _platform, + "/p:DefineConstants=\"%s\"" % _defines_sep.join(defines), + "/p:PythonBuildDir=%s" % os.path.abspath(dest_dir), + "/p:NoNuGet=true", + "/verbosity:%s" % VERBOSITY, + ] + + self.announce("Building: %s" % " ".join(cmd)) + check_call(" ".join(cmd) + " /t:Clean", shell=True) + check_call(" ".join(cmd) + " /t:Build", shell=True) + + if DEVTOOLS == "Mono": + self._build_monoclr(ext) + -VERSION = "%i.%i" % sys.version_info[:2] + def _build_monoclr(self, ext): + mono_libs = _check_output("pkg-config --libs mono-2", shell=True) + mono_cflags = _check_output("pkg-config --cflags mono-2", shell=True) + glib_libs = _check_output("pkg-config --libs glib-2.0", shell=True) + glib_cflags = _check_output("pkg-config --cflags glib-2.0", shell=True) + cflags = mono_cflags.strip() + " " + glib_cflags.strip() + libs = mono_libs.strip() + " " + glib_libs.strip() -def pkgconfig(*packages, **kw): - """From http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/502261 - XXX cmd = "export PKG_CONFIG_PATH=/opt/mono-2.8/lib/pkgconfig:... early 2011 + # build the clr python module + clr_ext = Extension("clr", + sources=[ + "src/monoclr/pynetinit.c", + "src/monoclr/clrmod.c" + ], + extra_compile_args=cflags.split(" "), + extra_link_args=libs.split(" ")) + + build_ext.build_extension(self, clr_ext) + + # build the clr python executable + sources = [ + "src/monoclr/pynetinit.c", + "src/monoclr/python.c", + ] + + macros = ext.define_macros[:] + for undef in ext.undef_macros: + macros.append((undef,)) + + objects = self.compiler.compile(sources, + output_dir=self.build_temp, + macros=macros, + include_dirs=ext.include_dirs, + debug=self.debug, + extra_postargs=cflags.split(" "), + depends=ext.depends) + + output_dir = os.path.dirname(self.get_ext_fullpath(ext.name)) + py_libs = get_config_vars("BLDLIBRARY")[0] + libs += " " + py_libs + + self.compiler.link_executable(objects, + _npython_exe, + output_dir=output_dir, + libraries=self.get_libraries(ext), + library_dirs=ext.library_dirs, + runtime_library_dirs=ext.runtime_library_dirs, + extra_postargs=libs.split(" "), + 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 + of Python. """ - flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'} - cmd = "export PKG_CONFIG_PATH=/lib/pkgconfig; pkg-config --libs --cflags %s" % ' '.join(packages) - popen = subprocess.Popen(cmd, shell=True, close_fds=True, stdout=subprocess.PIPE) - popen.wait() - if popen.returncode != 0: - raise RuntimeError("An error has occured") - output = popen.stdout.read().strip() - - for token in output.split(): - if flag_map.has_key(token[:2]): - kw.setdefault(flag_map.get(token[:2]), []).append(token[2:]) - else: # throw others to extra_link_args - kw.setdefault('extra_link_args', []).append(token) - - for k, v in kw.iteritems(): # remove duplicated - kw[k] = list(set(v)) - - return kw -#argsDict['include_dirs'] += ['/opt/mono-2.8/include','/include:usr/include','/usr/include/glib-2.0','/usr/lib/glib-2.0/include'] -argsDict = pkgconfig('glib-2.0', 'mono-2') - -clr = Extension('clr', - ['src/monoclr/clrmod.c', 'src/monoclr/pynetinit.c'], - depends=['src/monoclr/pynetclr.h'], - **argsDict - ) + process = Popen(stdout=PIPE, *popenargs, **kwargs) + output, unused_err = process.communicate() + retcode = process.poll() + if retcode: + cmd = kwargs.get("args") + if cmd is None: + cmd = popenargs[0] + raise CalledProcessError(retcode, cmd, output=output) + return output -extensions = [] -if os.name == "posix": - extensions.append(clr) -setup(name="clr", - ext_modules = extensions, - scripts = ["src/monoclr/clrpython%s" % VERSION], - ) \ No newline at end of file +if __name__ == "__main__": + setup(name="pythonnet", + ext_modules=[ + Extension("clr", sources=[]) + ], + scripts=[_npython_exe], + zip_safe=False, + cmdclass={ + "build_ext" : PythonNET_BuildExt, + "build_scripts" : PythonNET_BuildScripts, + "install_lib" : PythonNET_InstallLib + } + ) + diff --git a/pythonnet/setupmono.py b/pythonnet/setupmono.py deleted file mode 100644 index efb4dc2e3..000000000 --- a/pythonnet/setupmono.py +++ /dev/null @@ -1,199 +0,0 @@ -""" -Setup script for building clr.pyd and dependencies using mono and into -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 - -CONFIG = "Release" # Release or Debug -DEVTOOLS = "Mono" # Mono or MsDev -VERBOSITY = "minimal" # quiet, minimal, normal, detailed, diagnostic - -if DEVTOOLS == "MsDev": - from distutils import msvc9compiler - msvc9compiler.VERSION = 11 - - cc = msvc9compiler.MSVCCompiler() - cc.initialize() - _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) - -_platform = "x64" if architecture()[0] == "64bit" else "x86" - -class PythonNET_BuildExt(build_ext): - - def build_extension(self, ext): - """ - Builds the .pyd file using msbuild or xbuild. - """ - if ext.name != "clr": - return build_ext.build_extension(self, ext) - - dest_file = self.get_ext_fullpath(ext.name) - dest_dir = os.path.dirname(dest_file) - if not os.path.exists(dest_dir): - os.makedirs(dest_dir) - - defines = [ - "PYTHON%d%s" % (sys.version_info[:2]), - "UCS2" if sys.maxunicode < 0x10FFFF else "UCS4", - ] - - if CONFIG == "Debug": - defines.extend(["DEBUG", "TRACE"]) - - cmd = [ - _xbuild, - "pythonnet.sln", - "/p:Configuration=%s" % _config, - "/p:Platform=%s" % _platform, - "/p:DefineConstants=\"%s\"" % _defines_sep.join(defines), - "/p:PythonBuildDir=%s" % os.path.abspath(dest_dir), - "/p:NoNuGet=true", - "/verbosity:%s" % VERBOSITY, - ] - - self.announce("Building: %s" % " ".join(cmd)) - check_call(" ".join(cmd) + " /t:Clean", shell=True) - check_call(" ".join(cmd) + " /t:Build", shell=True) - - if DEVTOOLS == "Mono": - self._build_monoclr(ext) - - - def _build_monoclr(self, ext): - mono_libs = _check_output("pkg-config --libs mono-2", shell=True) - mono_cflags = _check_output("pkg-config --cflags mono-2", shell=True) - glib_libs = _check_output("pkg-config --libs glib-2.0", shell=True) - glib_cflags = _check_output("pkg-config --cflags glib-2.0", shell=True) - cflags = mono_cflags.strip() + " " + glib_cflags.strip() - libs = mono_libs.strip() + " " + glib_libs.strip() - - # build the clr python module - clr_ext = Extension("clr", - sources=[ - "src/monoclr/pynetinit.c", - "src/monoclr/clrmod.c" - ], - extra_compile_args=cflags.split(" "), - extra_link_args=libs.split(" ")) - - build_ext.build_extension(self, clr_ext) - - # build the clr python executable - sources = [ - "src/monoclr/pynetinit.c", - "src/monoclr/python.c", - ] - - macros = ext.define_macros[:] - for undef in ext.undef_macros: - macros.append((undef,)) - - objects = self.compiler.compile(sources, - output_dir=self.build_temp, - macros=macros, - include_dirs=ext.include_dirs, - debug=self.debug, - extra_postargs=cflags.split(" "), - depends=ext.depends) - - output_dir = os.path.dirname(self.get_ext_fullpath(ext.name)) - py_libs = get_config_vars("BLDLIBRARY")[0] - libs += " " + py_libs - - self.compiler.link_executable(objects, - _npython_exe, - output_dir=output_dir, - libraries=self.get_libraries(ext), - library_dirs=ext.library_dirs, - runtime_library_dirs=ext.runtime_library_dirs, - extra_postargs=libs.split(" "), - 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 - of Python. - """ - process = Popen(stdout=PIPE, *popenargs, **kwargs) - output, unused_err = process.communicate() - retcode = process.poll() - if retcode: - cmd = kwargs.get("args") - if cmd is None: - cmd = popenargs[0] - raise CalledProcessError(retcode, cmd, output=output) - return output - - -if __name__ == "__main__": - setup(name="pythonnet", - ext_modules=[ - Extension("clr", sources=[]) - ], - scripts=[_npython_exe], - zip_safe=False, - cmdclass={ - "build_ext" : PythonNET_BuildExt, - "build_scripts" : PythonNET_BuildScripts, - "install_lib" : PythonNET_InstallLib - } - ) - diff --git a/pythonnet/src/monoclr/Makefile b/pythonnet/src/monoclr/Makefile deleted file mode 100755 index 11b8c9025..000000000 --- a/pythonnet/src/monoclr/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -# Author: Christian Heimes - -PYTHON = python -BASENAME = $(shell $(PYTHON) -c "import sys; print 'python%i.%i' % sys.version_info[:2]") -GCC = gcc - -ifeq ($(origin WINDIR), undefined) - DLL_OR_SO = "-shared" -else - DLL_OR_SO = "-dynamiclib" -endif - - -PY_LIBS = $(shell $(PYTHON) -c "from distutils.sysconfig import get_config_vars; \ - print get_config_vars('BLDLIBRARY')[0]") #-lpython -PY_CFLAGS = -I$(shell $(PYTHON) -c "from distutils.sysconfig import get_config_vars; \ - print get_config_vars('CFLAGS')[0] + ' -I' + get_config_vars('CONFINCLUDEPY')[0]") - -MONO_LIBS = $(shell pkg-config --libs mono) # Was --libs mono -MONO_CFLAGS = $(shell pkg-config --cflags mono) # Was --cflags mono - -LIBS = $(MONO_LIBS) $(PY_LIBS) -CFLAGS = $(MONO_CFLAGS) $(PY_CFLAGS) - -all: clr$(BASENAME) $(BASENAME) clr.so - -clrmod.o: pynetclr.h clrmod.c - $(GCC) $(CFLAGS) -c clrmod.c -o clrmod.o - -clrpython.o: pynetclr.h clrpython.c - $(GCC) $(CFLAGS) -c clrpython.c -o clrpython.o - -pynetinit.o: pynetclr.h pynetinit.c - $(GCC) $(CFLAGS) -c pynetinit.c -o pynetinit.o - -$(BASENAME): python.c - $(GCC) $(PY_CFLAGS) $(PY_LIBS) python.c -o $(BASENAME) - -clr.so: clrmod.o pynetinit.o - $(GCC) $(LIBS) $(DLL_OR_SO) pynetinit.o clrmod.o -o clr.so - -clr$(BASENAME): clrpython.o pynetinit.o - $(GCC) $(LIBS) clrpython.o pynetinit.o -o clr$(BASENAME) - -clean: - rm -f *.o - rm -f *.so - rm -f clrpython2.? - rm -f python2.? - rm -rf build/ - diff --git a/pythonnet/src/monoclr/README.txt b/pythonnet/src/monoclr/README.txt deleted file mode 100644 index a8d8679ca..000000000 --- a/pythonnet/src/monoclr/README.txt +++ /dev/null @@ -1,23 +0,0 @@ -This has been updated to work with MonoFramework 1.9. - -1. On MacOS X, create the following directory structure: - - /PythonNET/src/monoclr - -2. Copy the setup.py to /PythonNET - -3. Copy the C/C++ code and header files to /PythonNET/src/monoclr - -4. Copy the Makefile to /PythonNET/src/monoclr - -5. In a terminal window, from the monoclr folder, run: - - $ make - -6. In a terminal window, from the PythonNET folder, run: - - $ python setup.py build - -7. This creates the clr.so - -8. Copy the clr.so, the Python.Runtime.dll, and the Python.Runtime.dll.config to the site-packages folder. \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy