6
6
from distutils .command .build_ext import build_ext
7
7
from distutils .command .build_scripts import build_scripts
8
8
from distutils .command .install_lib import install_lib
9
+ from distutils .command .install_data import install_data
9
10
from distutils .sysconfig import get_config_var
10
11
from platform import architecture
11
12
from subprocess import Popen , CalledProcessError , PIPE , check_call
12
13
from glob import glob
14
+ import fnmatch
13
15
import shutil
14
16
import sys
15
17
import os
@@ -229,16 +231,35 @@ def install(self):
229
231
if not os .path .exists (self .install_dir ):
230
232
self .mkpath (self .install_dir )
231
233
232
- # only copy clr.pyd and its dependencies
233
- for pattern in ("clr.*" , "Python.Runtime.*" ):
234
- for srcfile in glob (os .path .join (self .build_dir , pattern )):
235
- destfile = os .path .join (self .install_dir , os .path .basename (srcfile ))
236
- self .copy_file (srcfile , destfile )
237
-
234
+ # only copy clr.pyd/.so
235
+ for srcfile in glob (os .path .join (self .build_dir , "clr.*" )):
236
+ destfile = os .path .join (self .install_dir , os .path .basename (srcfile ))
237
+ self .copy_file (srcfile , destfile )
238
+
239
+
240
+ class PythonNET_InstallData (install_data ):
241
+
242
+ def run (self ):
243
+ build_cmd = self .get_finalized_command ("build_ext" )
244
+ install_cmd = self .get_finalized_command ("install" )
245
+ build_lib = os .path .abspath (build_cmd .build_lib )
246
+ install_platlib = os .path .relpath (install_cmd .install_platlib , self .install_dir )
247
+
248
+ for i , data_files in enumerate (self .data_files ):
249
+ if isinstance (data_files , str ):
250
+ self .data_files [i ] = data_files [i ].format (build_lib = build_lib )
251
+ else :
252
+ for j , filename in enumerate (data_files [1 ]):
253
+ data_files [1 ][j ] = filename .format (build_lib = build_lib )
254
+ dest = data_files [0 ].format (install_platlib = install_platlib )
255
+ self .data_files [i ] = dest , data_files [1 ]
256
+
257
+ return install_data .run (self )
258
+
238
259
239
260
class PythonNET_BuildScripts (build_scripts ):
240
261
241
- def finalize_options (self ):
262
+ def run (self ):
242
263
build_scripts .finalize_options (self )
243
264
244
265
# fixup scripts to look in the build_ext output folder
@@ -252,6 +273,8 @@ def finalize_options(self):
252
273
scripts .append (script )
253
274
self .scripts = scripts
254
275
276
+ return build_scripts .run (self )
277
+
255
278
256
279
def _check_output (* popenargs , ** kwargs ):
257
280
"""subprocess.check_output from python 2.7.
@@ -270,6 +293,24 @@ def _check_output(*popenargs, **kwargs):
270
293
271
294
272
295
if __name__ == "__main__" :
296
+ setupdir = os .path .dirname (__file__ )
297
+ if setupdir :
298
+ os .chdir (setupdir )
299
+
300
+ sources = []
301
+ for ext in (".sln" , ".snk" ):
302
+ sources .extend (glob ("*" + ext ))
303
+
304
+ for root , dirnames , filenames in os .walk ("src" ):
305
+ for ext in (".cs" , ".csproj" , ".sln" , ".snk" , ".config" , ".il" , ".py" , ".c" , ".h" , ".ico" ):
306
+ for filename in fnmatch .filter (filenames , "*" + ext ):
307
+ sources .append (os .path .join (root , filename ))
308
+
309
+ for root , dirnames , filenames in os .walk ("tools" ):
310
+ for ext in (".exe" ):
311
+ for filename in fnmatch .filter (filenames , "*" + ext ):
312
+ sources .append (os .path .join (root , filename ))
313
+
273
314
setup (
274
315
name = "pythonnet" ,
275
316
version = "2.0.0.dev1" ,
@@ -280,14 +321,18 @@ def _check_output(*popenargs, **kwargs):
280
321
'Development Status :: 3 - Alpha' ,
281
322
'Intended Audience :: Developers' ],
282
323
ext_modules = [
283
- Extension ("clr" , sources = [])
324
+ Extension ("clr" , sources = sources )
325
+ ],
326
+ data_files = [
327
+ ("{install_platlib}" , ["{build_lib}/Python.Runtime.dll" ]),
284
328
],
285
329
scripts = [_npython_exe ],
286
330
zip_safe = False ,
287
331
cmdclass = {
288
332
"build_ext" : PythonNET_BuildExt ,
289
333
"build_scripts" : PythonNET_BuildScripts ,
290
- "install_lib" : PythonNET_InstallLib
334
+ "install_lib" : PythonNET_InstallLib ,
335
+ "install_data" : PythonNET_InstallData ,
291
336
}
292
337
)
293
338
0 commit comments