From: SourceForge.net <no...@so...> - 2007-10-02 22:33:40
|
Bugs item #1796681, was opened at 2007-09-17 14:49 Message generated for change (Comment added) made by chrishbarker You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101645&aid=1796681&group_id=1645 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: documentation Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Christopher Barker (chrishbarker) Assigned to: David M. Beazley (beazley) Summary: Build Instructions for Python should use distutils Initial Comment: The build instructions in the doc for Python extensions should use distutils. Distutils has been a standard part of Python for a long time now, and is THE way to build extensions -- it does all the hard work for you, and the same configuration works on multiple platforms. Here is some suggested text: The easiest way to build extensions to python is to the the distutils (http://docs.python.org/dist/dist.html). The general idea is that you write a configuration file (conventionally called: setup.py), that describes your extension (and related python modules). Teh distutils will then build it for you, using all the right headers, compiler settings, etc that you need to work with your version of python. Here is a simple sample setup.py file: #!/usr/bin/env python """ setup.py file for SWIG example """ from distutils.core import setup, Extension example_module = Extension('examplemodule', sources=['example_wrap.c', 'example.c'], ) setup (name = 'example', version = '0.1', author = "SWIG Docs", description = """Simple swig example from docs""", ext_modules = [examplemodule]) Once this is saved as "setup.py", you can build your extension like this: % swig -python example.i % python setup.pu build_ext --inplace And a so, or pyd or... will be created for you. It will build a version that matches the python that you eun the command with. Taking apart teh command line: * python -- the version of python you want to build for * setup.py -- the name of your setup script (it can be called anything, but setup.py is the tradition) * build_ext -- telling distutils to build extensions * --inplace -- this tells distutils to put the extension lib in the current dir. Other wise, it will put it inside a build hierarchy, and you'd have to move it to use it. The distutils has many other features, consult the python distutils docs for details. This same approach works on all platforms, if the appropriate compiler is installed. (it can even build extensions to the standard Windows Python using MingGW) NOTE: No one recommends statically linking and re-building the interpreter these days. -Chris ---------------------------------------------------------------------- >Comment By: Christopher Barker (chrishbarker) Date: 2007-10-02 15:33 Message: Logged In: YES user_id=662322 Originator: YES OK, fair enough. Patch enclosed. I've added a distutils section, ande also changed the order a bit, putting distutils as the first build section (as it really should be the most common). I also: - added a bit of code to the example, so that everything needed to build the sample is there. - added a bit of text to the other build sections, referring to distutils. I think it would be better to remove or greatly trim down the other build sections -- those approaches are rarely used, and I don't think these docs are up-to-date enough to be easy to follow and work anyway. But that's not my call. -Chris File Added: Python.patch ---------------------------------------------------------------------- Comment By: William Fulton (wsfulton) Date: 2007-09-30 14:22 Message: Logged In: YES user_id=242951 Originator: NO Could you submit a patch with these suggestions by modifying the python docs (Python.html) from svn and I'll commit this. Thanks. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101645&aid=1796681&group_id=1645 |