4
4
"""
5
5
from setuptools import setup , Extension
6
6
from distutils .command .build_ext import build_ext
7
+ from distutils .command .build_scripts import build_scripts
8
+ from distutils .command .install_lib import install_lib
7
9
from distutils .sysconfig import get_config_vars
8
10
from platform import architecture
9
11
from subprocess import Popen , CalledProcessError , PIPE , check_call
12
+ from glob import glob
10
13
import shutil
11
14
import sys
12
15
import os
24
27
_xbuild = cc .find_exe ("msbuild.exe" )
25
28
_defines_sep = ";"
26
29
_config = "%sWin" % CONFIG
30
+ _npython_exe = "nPython.exe"
27
31
28
32
elif DEVTOOLS == "Mono" :
29
33
_xbuild = "xbuild"
30
34
_defines_sep = ","
31
35
_config = "%sMono" % CONFIG
36
+ _npython_exe = "npython"
32
37
33
38
else :
34
39
raise NotImplementedError ("DevTools %s not supported (use MsDev or Mono)" % DEVTOOLS )
@@ -42,7 +47,7 @@ def build_extension(self, ext):
42
47
Builds the .pyd file using msbuild or xbuild.
43
48
"""
44
49
if ext .name != "clr" :
45
- return super ( PythonNET_BuildExt , self ) .build_extension (ext )
50
+ return build_ext .build_extension (self , ext )
46
51
47
52
dest_file = self .get_ext_fullpath (ext .name )
48
53
dest_dir = os .path .dirname (dest_file )
@@ -85,17 +90,15 @@ def _build_monoclr(self, ext):
85
90
libs = mono_libs .strip () + " " + glib_libs .strip ()
86
91
87
92
# build the clr python module
88
- setup (name = "monoclr" ,
89
- ext_modules = [
90
- Extension ("clr" ,
93
+ clr_ext = Extension ("clr" ,
91
94
sources = [
92
95
"src/monoclr/pynetinit.c" ,
93
96
"src/monoclr/clrmod.c"
94
97
],
95
98
extra_compile_args = cflags .split (" " ),
96
- extra_link_args = libs .split (" " ),
97
- )]
98
- )
99
+ extra_link_args = libs .split (" " ))
100
+
101
+ build_ext . build_extension ( self , clr_ext )
99
102
100
103
# build the clr python executable
101
104
sources = [
@@ -120,7 +123,7 @@ def _build_monoclr(self, ext):
120
123
libs += " " + py_libs
121
124
122
125
self .compiler .link_executable (objects ,
123
- "npython" ,
126
+ _npython_exe ,
124
127
output_dir = output_dir ,
125
128
libraries = self .get_libraries (ext ),
126
129
library_dirs = ext .library_dirs ,
@@ -129,6 +132,41 @@ def _build_monoclr(self, ext):
129
132
debug = self .debug )
130
133
131
134
135
+ class PythonNET_InstallLib (install_lib ):
136
+
137
+ def install (self ):
138
+ if not os .path .isdir (self .build_dir ):
139
+ self .warn ("'%s' does not exist -- no Python modules to install" %
140
+ self .build_dir )
141
+ return
142
+
143
+ if not os .path .exists (self .install_dir ):
144
+ self .mkpath (self .install_dir )
145
+
146
+ # only copy clr.pyd and its dependencies
147
+ for pattern in ("clr.*" , "Python.Runtime.*" ):
148
+ for srcfile in glob (os .path .join (self .build_dir , pattern )):
149
+ destfile = os .path .join (self .install_dir , os .path .basename (srcfile ))
150
+ self .copy_file (srcfile , destfile )
151
+
152
+
153
+ class PythonNET_BuildScripts (build_scripts ):
154
+
155
+ def finalize_options (self ):
156
+ build_scripts .finalize_options (self )
157
+
158
+ # fixup scripts to look in the build_ext output folder
159
+ if self .scripts :
160
+ build_ext = self .get_finalized_command ("build_ext" )
161
+ output_dir = os .path .dirname (build_ext .get_ext_fullpath (_npython_exe ))
162
+ scripts = []
163
+ for script in self .scripts :
164
+ if os .path .exists (os .path .join (output_dir , script )):
165
+ script = os .path .join (output_dir , script )
166
+ scripts .append (script )
167
+ self .scripts = scripts
168
+
169
+
132
170
def _check_output (* popenargs , ** kwargs ):
133
171
"""subprocess.check_output from python 2.7.
134
172
Added here to support building for earlier versions
@@ -147,11 +185,15 @@ def _check_output(*popenargs, **kwargs):
147
185
148
186
if __name__ == "__main__" :
149
187
setup (name = "pythonnet" ,
150
- ext_modules = [
188
+ ext_modules = [
151
189
Extension ("clr" , sources = [])
152
- ],
153
- cmdclass = {
154
- "build_ext" : PythonNET_BuildExt
155
- }
190
+ ],
191
+ scripts = [_npython_exe ],
192
+ zip_safe = False ,
193
+ cmdclass = {
194
+ "build_ext" : PythonNET_BuildExt ,
195
+ "build_scripts" : PythonNET_BuildScripts ,
196
+ "install_lib" : PythonNET_InstallLib
197
+ }
156
198
)
157
199
0 commit comments