classification
Title: Custom order for the subcommands of build
Type: enhancement Stage:
Components: Distutils Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: tarek Nosy List: Joshua.J.Cogliati, ciantic, eric.araujo, lemburg, pebbe, tarek
Priority: normal Keywords:

Created on 2009-12-22 14:35 by ciantic, last changed 2014-11-05 22:10 by Joshua.J.Cogliati.

Messages (4)
msg96798 - (view) Author: Jari Pennanen (ciantic) Date: 2009-12-22 14:35
Long story short: Sometimes build_ext should be run before build_py, or 
something similar.

As an example when using SWIG and setup.py the build order is incorrect: 
During build_ext the SWIG generates .py files that should be used during 
build_py, but since build_py was already ran this doesn't work.

It would be useful if one could for example define custom order for 
subcommands in setup, in this case like: 

    setup(..., build_order=['build_ext', 'build_py'])

If adding a new keyword argument to setup is not an option, some other 
way to specify custom build order should be considered.

This is common problem especially using SWIG. Discussion about this 
issue was in here http://mail.python.org/pipermail/distutils-sig/2009-
December/015010.html the workaround for SWIG case is to use following 
setup.py:

   #!/usr/bin/env python
   from distutils.core import setup, Extension
   from distutils.command.build_py import build_py

   dist = setup(...)

   # Rerun the build_py
   build_py = build_py(dist)
   build_py.ensure_finalized()
   build_py.run()
msg96816 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2009-12-22 21:18
The distutils way of implementing a different fixed order would be to
create a build command sub-class, override the .sub_commands list and
then register this new subclass as 'build' command with distutils via
the cmdclass setup() keyword argument. (eGenix uses this approach in
mxSetup.py - see egenix-mx-base)

Note that I don't think that just providing an alternative order of
build_py and build_ext would solve the SWIG issue - e.g. build_py
wouldn't know about the new files SWIG generates unless the SWIG build
process explicitly tells the build_py command about these new files.

It would probably be better to add a completely new command just for
managing the SWIG build process to distutils. This could then add the
generated files, run build_ext with the required special arguments,
rerun build_py, etc.
msg96837 - (view) Author: Jari Pennanen (ciantic) Date: 2009-12-23 11:09
> Note that I don't think that just providing an alternative order of 
build_py and build_ext would solve the SWIG issue - e.g. build_py 
wouldn't know about the new files SWIG generates unless the SWIG build 
process explicitly tells the build_py command about these new files.

I don't think this is the case, let me explain:

Usually to my naive understanding, (I've just developed first SWIG 
python extension) the generated .py filenames are *known by name* 
beforehand, thus I can do following:

    #!/usr/bin/env python

    from distutils.core import setup, Extension
    from distutils.command.build_py import build_py

    dist = setup(name='mypythonmodule',
        ext_modules=[
            Extension('swiggedmodule', ['swiggedinterface.i'], 
                ...
            )
        ],
        py_modules=['swiggedmodule'], # We *know* that the SWIG 
                                      # generation creates this module.
    )

    # Rerun the build_py to ensure that swig generated py is build
    build_py = build_py(dist)
    build_py.ensure_finalized()
    build_py.run()

The very first line of `swiggedinterface.i` is the key here, it is 
created by us, which explicitely says it will create swiggedmodule.py:

    %module "swiggedmodule"
    ...

This fact makes us sure that it creates only swiggedmodule.py and we can 
safely put it in setup py without any guessing work. This is why the 
simply re-running the built_py works, or running "setup.py build_ext 
build_py" but users of the module shouldn't need to use different way of 
building the swig modules than other modules.
msg230717 - (view) Author: Joshua J Cogliati (Joshua.J.Cogliati) * Date: 2014-11-05 22:10
The documentation does claim that swig should just work "the build_ext command knows how to deal with SWIG extensions: it will run SWIG on the interface file and compile the resulting C/C++ file into your extension."

It would be nice if there was one obvious way to compile a swig extension.  (See for example the workarounds suggested in http://stackoverflow.com/questions/12491328 )
History
Date User Action Args
2014-11-05 22:10:12Joshua.J.Cogliatisetnosy: + Joshua.J.Cogliati
messages: + msg230717
2012-02-26 12:58:51pebbesetnosy: + pebbe
2012-02-21 03:17:55eric.araujosetnosy: + eric.araujo
2009-12-23 11:09:57cianticsetmessages: + msg96837
2009-12-22 21:18:34lemburgsetmessages: + msg96816
2009-12-22 14:54:10tareksetnosy: + lemburg
2009-12-22 14:35:12cianticcreate