Hi again --
[cc'd to Paul Dubois: you said you weren't following the distutils sig
anymore, but this directly concerns NumPy and I'd like to get your
input!]
here's that sample setup.py for NumPy. See below for discussion (and
questions!).
------------------------------------------------------------------------
#!/usr/bin/env python
# Setup script example for building the Numeric extension to Python.
# This does sucessfully compile all the .dlls. Nothing happens
# with the .py files currently.
# Move this file to the Numerical directory of the LLNL numpy
# distribution and run as:
# python numpysetup.py --verbose build_ext
#
# created 1999/08 Perry Stoll
__rcsid__ = "$Id: numpysetup.py,v 1.1 1999/09/12 20:42:48 gward Exp $"
from distutils.core import setup
setup (name = "numerical",
version = "0.01",
description = "Numerical Extension to Python",
url = "http://www.python.org/sigs/matrix-sig/",
ext_modules = [ ( '_numpy', { 'sources' : [ 'Src/_numpymodule.c',
'Src/arrayobject.c',
'Src/ufuncobject.c'
],
'include_dirs' : ['./Include'],
'def_file' : 'Src/numpy.def' }
),
( 'multiarray', { 'sources' : ['Src/multiarraymodule.c'],
'include_dirs' : ['./Include'],
'def_file': 'Src/multiarray.def'
}
),
( 'umath', { 'sources': ['Src/umathmodule.c'],
'include_dirs' : ['./Include'],
'def_file' : 'Src/umath.def' }
),
( 'fftpack', { 'sources': ['Src/fftpackmodule.c', 'Src/fftpack.c'],
'include_dirs' : ['./Include'],
'def_file' : 'Src/fftpack.def' }
),
( 'lapack_lite', { 'sources' : [ 'Src/lapack_litemodule.c',
'Src/dlapack_lite.c',
'Src/zlapack_lite.c',
'Src/blas_lite.c',
'Src/f2c_lite.c'
],
'include_dirs' : ['./Include'],
'def_file' : 'Src/lapack_lite.def' }
),
( 'ranlib', { 'sources': ['Src/ranlibmodule.c',
'Src/ranlib.c',
'Src/com.c',
'Src/linpack.c',
],
'include_dirs' : ['./Include'],
'def_file' : 'Src/ranlib.def' }
),
]
)
------------------------------------------------------------------------
First, what d'you think? Too clunky and verbose? Too much information
for each extension? I kind of think so, but I'm not sure how to reduce
it elegantly. Right now, the internal data structures needed to compile
a module are pretty obviously exposed: is this a good thing? Or should
there be some more compact form for setup.py that will be expanded later
into the full glory we see above?
I've already made one small step towards reducing the amount of cruft by
factoring 'include_dirs' out and supplying it directly as a parameter to
'setup()'. (But that needs code not in the CVS archive yet, so I've
left the sample setup.py the same for now.)
The next thing I'd like to do is get that damn "def_file" out of there.
To support it in MSVCCompiler, there's already an ugly hack that
unnecessarily affects both the UnixCCompiler and CCompiler classes, and
I want to get rid of that. (I refer to passing the 'build_info'
dictionary into the compiler classes, if you're familiar with the code
-- that dictionary is part of the Distutils extension-building system,
and should not propagate into the more general compiler classes.)
But I don't want to give these weird "def file" things standing on the
order of source files, object files, libraries, etc., because they seem
to me to be a bizarre artifact of one particular compiler, rather than
something present in a wide range of C/C++ compilers.
Based on the NumPy model, it seems like there's a not-too-kludgy way to
handle this problem. Namely:
if building extension "foo":
if file "foo.def" found in same directory as "foo.c"
add "/def:foo.def" to MSVC command line
this will of course require some platform-specific code in the build_ext
command class, but I figured that was coming eventually, so why put it
off? ;-)
To make this hack work with NumPy, one change would be necessary: rename
Src/numpy.def to Src/_numpy.def to match Src/_numpy.c, which implements
the _numpy module. Would this be too much to ask of NumPy? (Paul?)
What about other module distributions that support MSVC++ and thus ship
with "def" files? Could they be made to accomodate this scheme?
Thanks for your feedback --
Greg
--
Greg Ward - software developer gward(a)cnri.reston.va.us
Corporation for National Research Initiatives
1895 Preston White Drive voice: +1-703-620-8990
Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
Hi all --
at long last, I found the time to hack in the ability to compile
extension modules to the Distutils. Mainly, this meant adding a
'build_ext' command which uses a CCompiler instance for all its dirty
work. I also had to add a few methods to CCompiler (and, of course,
UnixCCompiler) to make this work.
And I added a new module, 'spawn', which takes care of running
sub-programs more efficiently and robustly (no shell involved) than
os.system. That's needed, obviously, so we can run the compiler!
If you're in the mood for grubbing over raw source code, then get the
latest from CVS or download a current snapshot. See
http://www.python.org/sigs/distutils-sig/implementation.html
for a link to the code snapshot.
I'm still waiting for more subclasses of CCompiler to appear. At the
very least, we're going to need MSVCCompiler to build extensions on
Windows. Any takers? Also, someone who knows the Mac, and how to run
compilers programmatically there, will have to figure out how to write a
Mac-specific concrete CCompiler subclass.
The spawn module also needs a bit of work to be portable. I suspect
that _win32_spawn() (the intended analog to my _posix_spawn()) will be
easy to implement, if it even needs to go in a separate function at all.
It looks from the Python Library documentation for 1.5.2 that the
os.spawnv() function is all we need, but it's a bit hard to figure out
just what's needed. Windows wizards, please take a look at the
'spawn()' function and see if you can make it work on Windows.
As for actually compiling extensions: well, if you can figure out the
build_ext command, go ahead and give it a whirl. It's a bit cryptic
right now, since there's no documentation and no example setup.py. (I
have a working example at home, but it's not available online.) If you
feel up to it, though, see if you can read the code and figure out
what's going on. I'm just hoping *I'll* be able to figure out what's
going on when I get back from the O'Reilly conference next week... ;-)
Enjoy --
Greg
--
Greg Ward - software developer gward(a)cnri.reston.va.us
Corporation for National Research Initiatives
1895 Preston White Drive voice: +1-703-620-8990
Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
Hi all --
at long last, I have fixed two problems that a couple people noticed a
while ago:
* I folded in Amos Latteier's NT patches almost verbatim -- just
changed an `os.path.sep == "/"' to `os.name == "posix"' and added
some comments bitching about the inadequacy of the current library
installation model (I think this is Python's fault, but for now
Distutils is slavishly aping the situation in Python 1.5.x)
* I fixed the problem whereby running "setup.py install" without
doing anything else caused a crash (because 'build' hadn't yet
been run). Now, the 'install' command automatically runs 'build'
before doing anything; to make this bearable, I added a 'have_run'
dictionary to the Distribution class to keep track of which commands
have been run. So now not only are command classes singletons,
but their 'run' method can only be invoked once -- both restrictions
enforced by Distribution.
The code is checked into CVS, or you can download a snapshot at
http://www.python.org/sigs/distutils-sig/distutils-19990607.tar.gz
Hope someone (Amos?) can try the new version under NT. Any takers for
Mac OS?
BTW, all parties involved in the Great "Where Do We Install Stuff?"
Debate should take a good, hard look at the 'set_final_options()' method
of the Install class in distutils/install.py; this is where all the
policy decisions about where to install files are made. Currently it
apes the Python 1.5 situation as closely as I could figure it out.
Obviously, this is subject to change -- I just don't know to *what* it
will change!
Greg
--
Greg Ward - software developer gward(a)cnri.reston.va.us
Corporation for National Research Initiatives
1895 Preston White Drive voice: +1-703-620-8990
Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
Hi all,
I've been aware that the distutils sig has been simmerring away, but
until recently it has not been directly relevant to what I do.
I like the look of the proposed api, but have one question. Will this
support an installed system that has multiple versions of the same
package installed simultaneously? If not, then this would seem to be a
significant limitation, especially when dependencies between packages
are considered.
Assuming it does, then how will this be achieved? I am presently
managing this with a messy arrangement of symlinks. A package is
installed with its version number in it's name, and a separate
directory is created for an application with links from the
unversioned package name to the versioned one. Then I just set the
pythonpath to this directory.
A sample of what the directory looks like is shown below.
I'm sure there is a better solution that this, and I'm not sure that
this would work under windows anyway (does windows have symlinks?).
So, has this SIG considered such versioning issues yet?
Cheers,
Tim
--------------------------------------------------------------
Tim Docker timd(a)macquarie.com.au
Quantative Applications Division
Macquarie Bank
--------------------------------------------------------------
qad16:qad $ ls -l lib/python/
total 110
drwxr-xr-x 2 mts mts 512 Nov 11 11:23 1.1
-r--r----- 1 root mts 45172 Sep 1 1998 cdrmodule_0_7_1.so
drwxr-xr-x 2 mts mts 512 Sep 1 1998 chart_1_1
drwxr-xr-x 3 mts mts 512 Sep 1 1998 Fnorb_0_7_1
dr-xr-x--- 3 mts mts 512 Nov 11 11:21 Fnorb_0_8
drwxr-xr-x 3 mts mts 1536 Mar 3 12:45 mts_1_1
dr-xr-x--- 7 mts mts 512 Nov 11 11:22 OpenGL_1_5_1
dr-xr-x--- 2 mts mts 1024 Nov 11 11:23 PIL_0_3
drwxr-xr-x 3 mts mts 512 Sep 1 1998 Pmw_0_7
dr-xr-x--- 2 mts mts 512 Nov 11 11:21 v3d_1_1
qad16:qad $ ls -l lib/python/1.1
total 30
lrwxrwxrwx 1 root other 29 Apr 10 10:43 _glumodule.so -> ../OpenGL_1_5_1/_glumodule.so
lrwxrwxrwx 1 root other 30 Apr 10 10:43 _glutmodule.so -> ../OpenGL_1_5_1/_glutmodule.so
lrwxrwxrwx 1 root other 22 Apr 10 10:43 _imaging.so -> ../PIL_0_3/_imaging.so
lrwxrwxrwx 1 root other 36 Apr 10 10:43 _opengl_nummodule.so -> ../OpenGL_1_5_1/_opengl_nummodule.so
lrwxrwxrwx 1 root other 27 Apr 10 10:43 _tkinter.so -> ../OpenGL_1_5_1/_tkinter.so
lrwxrwxrwx 1 mts mts 21 Apr 10 10:43 cdrmodule.so -> ../cdrmodule_0_7_1.so
lrwxrwxrwx 1 mts mts 12 Apr 10 10:43 chart -> ../chart_1_1
lrwxrwxrwx 1 root other 12 Apr 10 10:43 Fnorb -> ../Fnorb_0_8
lrwxrwxrwx 1 mts mts 12 Apr 10 10:43 mts -> ../mts_1_1
lrwxrwxrwx 1 root other 15 Apr 10 10:43 OpenGL -> ../OpenGL_1_5_1
lrwxrwxrwx 1 root other 33 Apr 10 10:43 opengltrmodule.so -> ../OpenGL_1_5_1/opengltrmodule.so
lrwxrwxrwx 1 root other 33 Apr 10 10:43 openglutil_num.so -> ../OpenGL_1_5_1/openglutil_num.so
lrwxrwxrwx 1 root other 10 Apr 10 10:43 PIL -> ../PIL_0_3
lrwxrwxrwx 1 mts mts 10 Apr 10 10:43 Pmw -> ../Pmw_0_7
lrwxrwxrwx 1 root other 10 Apr 10 10:43 v3d -> ../v3d_1_1
What is this, and how can I get rid of it?
cory@cory2k ~/cvs/Twisted
$ python setup.py build -c mingw32
running build
running build_py
running build_ext
error: Python was built with version 6 of Visual Studio, and extensions
need to
be built with the same version of the compiler, but it isn't installed.
I had no problems building these extensions on Python 2.2 following the
instructions at http://sebsauvage.net/python/mingw.html . I did the
same thing substituting 2.3 for 2.2, and got the message above.
Why doesn't it work any more? --compiler=mingw32 is still valid on the
command line.
At 07:05 PM 7/31/03 +0200, Thomas Heller wrote:
>Cory Dodt <corydodt(a)yahoo.com> writes:
>
> >>Subject: [Twisted-Python] Twisted - Python 2.3 - Windows
> >>
> >>Hi,
> >>
> >> anyone who knows when the first Python 2.3 build of twisted for
> >> windows will be available? Which version will it be?
> >>
> >> I tried to build it myself but got into trouble. I first installed
> >> Cygwin and then tried 'setup.py build --compiler=mingw32' as per
> >> documentation, but I got an error message that Python itself is
> >> build with Visual Studio 6.
> >>I don't feel building python myself and I don't have VS6.
> >>
> >
> > I'm with you man, I don't feel like building Python myself either. I
> > have asked the appropriate list
> > (http://mail.python.org/pipermail/distutils-sig/2003-July/003333.html )
> > about this problem. I also tried using distutils from CVS instead of
> > the bundled copy with Python 2.3, and no luck.
It looks like the error occurs when an MSVCCompiler instance is created; I
haven't yet figured out *why* such an instance is being created. I don't
have 2.3 installed on Win32, so as an experiment, I added a 'raise'
statement to 2.2's MSVCCompiler. If I specified compilation with msvc, I
get the error I raised. If I specify mingw32, I don't. So, evidently
2.2's distutils don't create an MSVCCompiler instance when specifying
mingw32. I can't fathom why 2.3 would do so.
Hi folks,
I'm very new to this list and to distutils (this is my first stab at using
it), so don't be afraid to point out the obvious...
I'm trying to make a setup.py that will work on Linux and Win32, and be able
to produce sdists and bdists for both platforms (I understand that I should
use the targeted platform to build the bdist).
The package I'm trying to distribute is actually a Quixote application,
which (for those unfamiliar with Quixote) means it's a web application. I'd
like to install it as a package in site-packages anyway, because that makes
it easier to run multiple instances of the application (with different
configuration data) on a machine without having multiple copies of it. As a
web application, it has a few images, and a style.css file to distribute,
and it also has a misc directory in the package (which perhaps shouldn't go
there, but that's the way I'm trying to do it for now...) which includes a
sample *.cgi file, *.conf file, and a python script intended to be run as a
script (rather than imported as a module/package).
I'm using the data_files argument to pass in those files, and I determine
the directory to install to by extrapolating from the value of
distutils.sysconfig.get_python_lib(), but that doesn't work right when I do
a bdist_wininst (I haven't tried to do an RPM, yet, so I don't know if that
works)... The files end up in "c:\python23\python23\projectTasks...."
instead of "c:\python23\Lib\site-packages\projectTasks....".
I've figured out a hack to do to the data_files (in code below) to make it
work, but then the sdist doesn't work right, on Linux or Win32.
Is there a way to achieve what I'm attempting, or do I just need to figure
out at run time what the user is trying to do (build a bdist, or run an
sdist), and decide then whether to apply my hack or not?
Thanks,
Jason Sibre
Here's my setup.py file:
---------------------------
#!/usr/bin/python
import os, os.path
from distutils.core import setup
from distutils.sysconfig import get_python_lib
from quixote.qx_distutils import qx_build_py
def getFiles(path):
fullFiles = []
files = os.listdir(path)
for f in files:
if f == "CVS": continue
fullFiles.append(os.path.join(path,f))
return fullFiles
webdir = os.path.join(get_python_lib(),'projectTasks','web')
miscFiles = getFiles('web/misc')
staticFiles = getFiles('web/staticFiles')
#I think this is the 'right' way to do it,
#and creates sdists that play nicely
data_files = [
(os.path.join(webdir, 'misc'), miscFiles),
(os.path.join(webdir, 'staticFiles'), staticFiles),
]
#This works (as a hack) to get a win binary to install nicely
#But of course makes a mess if you install from an sdist
#data_files = [
# ('../PURELIB/projectTasks/web/misc', miscFiles),
# ('../PURELIB/projectTasks/web/staticFiles', staticFiles),
# ]
setup(
name = 'projectTasks',
version = "0.1.0",
description = "Project Task manager app for Quixote framework.",
author = "Jason Sibre",
author_email = "jsibre(a)chironsys.com",
package_dir = {'projectTasks':'.'},
packages = ['projectTasks','projectTasks.web'],
data_files = data_files,
cmdclass = {'build_py': qx_build_py},
)
Hello,
I searched the list archives and found some mention of getting SWIG
v1.3 working with distutils but I couldn't find anything on the results
of that effort.
I've got a set of python modules that I'm beginning to convert to C/C++
extensions and some C/C++ code I want to wrap for Python using SWIG
v1.3. I can get the extensions to build and work on their own (MacOS X
10.2.4, MacPython 2.3b1) but I can't get a distutils module to build
them.
My package directory looks something like this:
Lib/
Lib/moduleA.py
Lib/moduleB.py
Packages/
Packages/__init__.py
Packages/moduleC/
Packages/moduleC/moduleC.i
Packages/moduleC/Lib/__init__.py
Packages/moduleC/Include/moduleC.h
Packages/moduleC/Src/moduleC.c
where moduleA, moduleB are currently pure python but which may
eventually converted to wrappers around C code and moduleC is being
built as an extension.
Based on the docs and study of other setup.py scripts, my script looks
something like:
extra_compile_args=["-Ddarwin"]
packages=["WTBlib"]
package_dir={'WTBlib':"Lib"}
include_dirs=[os.path.join('/usr','local','lib')]
ext_modules=[]
packages.append('WTBlib.moduleC')
package_dir['WTBlib.moduleC']=os.path.join('Packages','moduleC','Lib')
include_dirs.append(os.path.join('Packages','moduleC','Include'))
ext_modules.append(Extension('moduleC',
[os.path.join('Packages','moduleC','Src','moduleC.c'),
os.path.join('Packages','moduleC','moduleC.i')],
extra_compile_args = extra_compile_args,
include_dirs=include_dirs))
setup(name='WTBlib',version = "0.1",
packages = packages,
package_dir = package_dir,
description = "",
include_dirs = include_dirs,
ext_package = "WTBlib",
ext_modules = ext_modules)
Currently, it fails trying to build the SWIG wrapper. So I built the
wrappers manually (moduleC_wrap.c and moduleC.py and modified setup.py
accordingly.
I expected it to build in site-packages something like:
WTBlib/
WTBlib/moduleA.py
WTBlib/moduleB.py
WTBlib/moduleC/
WTBlib/moduleC/_moduleC.so
WTBlib/moduleC/moduleC.py
WTBlib/moduleC/__init__.py
which I believe is what I want. However, after having to modify things
like #include paths in the wrapper file I can finally get it to build
something like:
WTBlib/
WTBlib/__init__.py
WTBlib/moduleA.py
WTBlib/moduleB.py
WTBlib/moduleC.so
WTBlib/moduleC/
WTBlib/moduleC/moduleC.py
WTBlib/moduleC/__init__.py
which just doesn't work at all. Pretends to import but no guts in the
routines.
Part of my problem is clearly that I don't understand how each of the
components entered into the setup.py gets transformed into a path for
such things as file copy and compilation parameters. Is there a better
source of info on that?
What is the status of letting distutils build the wrapper files?
Also, just what is the __init__.py file for and is there ever a reason
to put routines in it?
Thanks,
Tom