From: David B. <da...@da...> - 2011-12-01 09:40:28
|
For what it's worth, I don't think you should ever rely on distutils to invoke Swig (i.e., never list the .i file in the setup.py). Swig wrapper code was always meant to be self-contained and compilable without requiring a user of your package to also have Swig installed on their machine. If it were me, I would simply list the _wrap.c files in setup.py and ship the generated wrapper code. Cheers, Dave On Nov 30, 2011, at 4:57 PM, Nickolas Fotopoulos wrote: > On 07/07/11 03:06, Aubrey Barnard wrote: >> Greetings Swig users, >> >> It appears that the Python distutils does not install the Python module >> generated by Swig. Does anybody know a correct solution or a workaround? >> >> Here is the scenario. Imagine I have foo.c and foo.i. A setup.py would >> be like the following: >> ---------------------------------------- >> from distutils.core import setup, Extension >> setup(name='foo', >> py_modules=['foo'], >> ext_modules=[ >> Extension( >> name='_foo', >> sources=[ >> 'foo.i', >> 'foo.c', >> ), >> ], >> ) >> ---------------------------------------- >> >> Running "python setup.py install --user" produces: >> $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ >> running install >> running build >> running build_py >> file foo.py (for module foo) not found >> file foo.py (for module foo) not found >> running build_ext >> building '_foo' extension >> swigging foo.i to foo_wrap.c >> swig -python -o foo_wrap.c foo.i >> creating build >> creating build/temp.linux-x86_64-2.7 >> creating build/src >> gcc ... >> running install_lib >> copying build/lib.linux-x86_64-2.7/_foo.so -> >> ~/.local/lib/python2.7/site-packages >> running install_egg_info >> Writing ~/.local/lib/python2.7/site-packages/foo-0.1-py2.7.egg-info >> $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ >> >> Distutils is trying to install foo.py before Swig generates it. > [snip] > > I came across this also and feel that a reply on this list is > appropriate, as it will bite many people putting distutils and SWIG > together. I looked at the source code of distutils.command.build and > found a hard-coded list of sub-commands to execute. My solution is to > reorder them explicitly in my setup.py (tested on Python 2.6 and 2.7): > > # hack distutils so that extensions are built before python modules; > # this is necessary for SWIG-generated .py files > from distutils.command.build import build > build.sub_commands = [('build_ext', build.has_ext_modules), > ('build_py', build.has_pure_modules), > ('build_clib', build.has_c_libraries), > ('build_scripts', build.has_scripts)] > > While this produces exactly the desired result, I would certainly > welcome a more elegant solution, as this is not safe > against additions or deletions of build sub-commands in future or past > versions of distutils. > > Take care, > Nick > > -- > ====================== > Nickolas Fotopoulos > Postdoctoral Scholar > LIGO Laboratory, Caltech > ====================== > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure > contains a definitive record of customers, application performance, > security threats, fraudulent activity, and more. Splunk takes this > data and makes sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-novd2d > _______________________________________________ > Swig-user mailing list > Swi...@li... > https://lists.sourceforge.net/lists/listinfo/swig-user |