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
7
from distutils .command .install_lib import install_lib
8
+ from distutils .command .install_data import install_data
9
9
from distutils .sysconfig import get_config_var
10
- from distutils .util import convert_path
11
- from distutils .dep_util import newer
12
- from distutils import log
13
10
from platform import architecture
14
11
from subprocess import Popen , CalledProcessError , PIPE , check_call
15
12
from glob import glob
16
- import stat
13
+ import fnmatch
17
14
import sys
18
15
import os
19
16
20
- CONFIG = "Release" # Release or Debug
17
+ CONFIG = "Release" # Release or Debug
21
18
DEVTOOLS = "MsDev" if sys .platform == "win32" else "Mono"
22
- VERBOSITY = "minimal" # quiet, minimal, normal, detailed, diagnostic
19
+ VERBOSITY = "minimal" # quiet, minimal, normal, detailed, diagnostic
23
20
PLATFORM = "x64" if architecture ()[0 ] == "64bit" else "x86"
24
21
25
22
@@ -167,7 +164,6 @@ def build_extension(self, ext):
167
164
if DEVTOOLS == "Mono" :
168
165
self ._build_monoclr (ext )
169
166
170
-
171
167
def _get_manifest (self , build_dir ):
172
168
if DEVTOOLS == "MsDev" and sys .version_info [:2 ] > (2 ,5 ):
173
169
mt = _find_msbuild_tool ("mt.exe" , use_windows_sdk = True )
@@ -177,7 +173,6 @@ def _get_manifest(self, build_dir):
177
173
check_call (" " .join (cmd ), shell = False )
178
174
return manifest
179
175
180
-
181
176
def _build_monoclr (self , ext ):
182
177
mono_libs = _check_output ("pkg-config --libs mono-2" , shell = True )
183
178
mono_cflags = _check_output ("pkg-config --cflags mono-2" , shell = True )
@@ -197,7 +192,6 @@ def _build_monoclr(self, ext):
197
192
198
193
build_ext .build_extension (self , clr_ext )
199
194
200
-
201
195
def _install_packages (self ):
202
196
"""install packages using nuget"""
203
197
nuget = os .path .join ("tools" , "nuget" , "nuget.exe" )
@@ -222,12 +216,31 @@ def install(self):
222
216
if not os .path .exists (self .install_dir ):
223
217
self .mkpath (self .install_dir )
224
218
225
- # only copy clr.pyd and its dependencies
226
- for pattern in ("clr.*" , "Python.Runtime.*" ):
227
- for srcfile in glob (os .path .join (self .build_dir , pattern )):
228
- destfile = os .path .join (self .install_dir , os .path .basename (srcfile ))
229
- self .copy_file (srcfile , destfile )
230
-
219
+ # only copy clr.pyd/.so
220
+ for srcfile in glob (os .path .join (self .build_dir , "clr.*" )):
221
+ destfile = os .path .join (self .install_dir , os .path .basename (srcfile ))
222
+ self .copy_file (srcfile , destfile )
223
+
224
+
225
+ class PythonNET_InstallData (install_data ):
226
+
227
+ def run (self ):
228
+ build_cmd = self .get_finalized_command ("build_ext" )
229
+ install_cmd = self .get_finalized_command ("install" )
230
+ build_lib = os .path .abspath (build_cmd .build_lib )
231
+ install_platlib = os .path .relpath (install_cmd .install_platlib , self .install_dir )
232
+
233
+ for i , data_files in enumerate (self .data_files ):
234
+ if isinstance (data_files , str ):
235
+ self .data_files [i ] = data_files [i ].format (build_lib = build_lib )
236
+ else :
237
+ for j , filename in enumerate (data_files [1 ]):
238
+ data_files [1 ][j ] = filename .format (build_lib = build_lib )
239
+ dest = data_files [0 ].format (install_platlib = install_platlib )
240
+ self .data_files [i ] = dest , data_files [1 ]
241
+
242
+ return install_data .run (self )
243
+
231
244
232
245
def _check_output (* popenargs , ** kwargs ):
233
246
"""subprocess.check_output from python 2.7.
@@ -248,6 +261,24 @@ def _check_output(*popenargs, **kwargs):
248
261
249
262
250
263
if __name__ == "__main__" :
264
+ setupdir = os .path .dirname (__file__ )
265
+ if setupdir :
266
+ os .chdir (setupdir )
267
+
268
+ sources = []
269
+ for ext in (".sln" , ".snk" , ".config" ):
270
+ sources .extend (glob ("*" + ext ))
271
+
272
+ for root , dirnames , filenames in os .walk ("src" ):
273
+ for ext in (".cs" , ".csproj" , ".sln" , ".snk" , ".config" , ".il" , ".py" , ".c" , ".h" , ".ico" ):
274
+ for filename in fnmatch .filter (filenames , "*" + ext ):
275
+ sources .append (os .path .join (root , filename ))
276
+
277
+ for root , dirnames , filenames in os .walk ("tools" ):
278
+ for ext in (".exe" ):
279
+ for filename in fnmatch .filter (filenames , "*" + ext ):
280
+ sources .append (os .path .join (root , filename ))
281
+
251
282
setup (
252
283
name = "pythonnet" ,
253
284
version = "2.0.0.dev1" ,
@@ -258,12 +289,18 @@ def _check_output(*popenargs, **kwargs):
258
289
'Development Status :: 3 - Alpha' ,
259
290
'Intended Audience :: Developers' ],
260
291
ext_modules = [
261
- Extension ("clr" , sources = [])
292
+ Extension ("clr" , sources = sources )
293
+ ],
294
+ data_files = [
295
+ ("{install_platlib}" , [
296
+ "{build_lib}/Python.Runtime.dll" ,
297
+ "Python.Runtime.dll.config" ]),
262
298
],
263
299
zip_safe = False ,
264
300
cmdclass = {
265
- "build_ext" : PythonNET_BuildExt ,
266
- "install_lib" : PythonNET_InstallLib ,
301
+ "build_ext" : PythonNET_BuildExt ,
302
+ "install_lib" : PythonNET_InstallLib ,
303
+ "install_data" : PythonNET_InstallData ,
267
304
}
268
305
)
269
306
0 commit comments