11import ast
2+ from distutils .command .build_py import build_py as _build_py
23import os
3- import sys
4+ import shutil
45
5- from setuptools import setup , find_packages
6+ from setuptools import setup
67
78
89class BuildFailed (Exception ):
@@ -18,15 +19,29 @@ class BuildFailed(Exception):
1819# advanced feature and shouldn't be used without care as it may produce invalid
1920# installs of ``libpy``.
2021dont_build = ast .literal_eval (os .environ .get ('LIBPY_DONT_BUILD' , '0' ))
21- if 'build_ext' in sys .argv or 'egg_info' in sys .argv and not dont_build :
22- path = os .path .dirname (os .path .abspath (__file__ ))
23- command = 'make -C "%s"' % path
24- out = os .system (command )
25- if out :
26- raise BuildFailed (
27- "Command {!r} failed with code {}" .format (command , out )
22+
23+
24+ class build_py (_build_py ):
25+ def run (self ):
26+ if self .dry_run or dont_build :
27+ return super ().run ()
28+
29+ super ().run ()
30+ path = os .path .dirname (os .path .abspath (__file__ ))
31+ command = 'make -C "%s" libpy/libpy.so' % path
32+ out = os .system (command )
33+ if out :
34+ raise BuildFailed (
35+ "Command {!r} failed with code {}" .format (command , out )
36+ )
37+
38+ print (os .listdir ('libpy' ))
39+ shutil .copyfile (
40+ 'libpy/libpy.so' ,
41+ os .path .join (self .build_lib , 'libpy' , 'libpy.so' ),
2842 )
2943
44+
3045setup (
3146 name = 'libpy' ,
3247 url = 'https://github.com/quantopian/libpy' ,
@@ -53,6 +68,7 @@ class BuildFailed(Exception):
5368 # we need the headers to be available to the C compiler as regular files;
5469 # we cannot be imported from a ziparchive.
5570 zip_safe = False ,
56- include_package_data = True ,
5771 install_requires = ['numpy' ],
72+ cmdclass = {'build_py' : build_py },
73+ package_data = {'libpy' : ['include/**/*.h' ]},
5874)
0 commit comments