Hi,
I had troubles with distutils 1.0 and the way I use SWIG.
I couldn't find any support for the -shadow option and no way to pass an
extra include dir to swig (like it´s possible for the c compiler)
Therefore I wrote a patch.
It adds an extra_swig_args (list of string) option to Extension.
All the strings are passed to swig without modification, but
if extra_swig_args contains "-c++" or "-shadow" there is some special
action:
"-c++": behaves like build_ext --swig-cpp
"-shadow":
Normally swig generates a file:
foo.c -> foo.so
In this case SWIG generates two files:
foo.py (python shadow classes, imports fooc)
fooc.c -> fooc.so
With this patch build_ext can handle this und generates for foo.i
(foo.py, fooc.c) compiles them and installs them.
Below is the diff against disutils 1.0, apply in your Distutils-1.0
directory with:
patch -p5 < file
I hope it doesn´t break anything, isn´t against distutils design
principles and is so useful that it might become part of distutils.
Please answer me directly, because I didn´t not subscribe ths list.
Regards
joerg
Joerg Baumann joerg.baumann(a)stud.informatik.uni-erlangen.de
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Beware of bugs in the above code; I have only proved it correct,
not tried it.
Don Knuth
diff -r -C 2 -x *pyc /home/jgbauman/download/Distutils-1.0/distutils/command/build_ext.py ./command/build_ext.py
*** /home/jgbauman/download/Distutils-1.0/distutils/command/build_ext.py Sat Sep 30 20:27:54 2000
--- ./command/build_ext.py Fri Oct 6 01:23:08 2000
***************
*** 386,390 ****
# SWIG on 'em to create .c files, and modify the sources list
# accordingly.
! sources = self.swig_sources(sources)
# Next, compile the source code to object files.
--- 386,398 ----
# SWIG on 'em to create .c files, and modify the sources list
# accordingly.
! sources,extra_modules = self.swig_sources(sources,ext.extra_swig_args)
!
! # if there are extra_modules after running swig due to -shadow option
! # copy them to build/lib.xxx
! for module in extra_modules:
! outfile = os.path.join(self.build_lib,os.path.basename(module))
! dir = os.path.dirname(outfile)
! self.mkpath(dir)
! self.copy_file(module, outfile, preserve_mode=0)
# Next, compile the source code to object files.
***************
*** 444,448 ****
! def swig_sources (self, sources):
"""Walk the list of source files in 'sources', looking for SWIG
--- 452,456 ----
! def swig_sources (self, sources, extra_swig_args):
"""Walk the list of source files in 'sources', looking for SWIG
***************
*** 453,456 ****
--- 461,465 ----
new_sources = []
+ new_modules = []
swig_sources = []
swig_targets = {}
***************
*** 461,464 ****
--- 470,479 ----
# the temp dir.
+ if "-c++" in extra_swig_args:
+ self.swig_cpp=1
+ if "-shadow" in extra_swig_args:
+ shadow=1
+ else:
+ shadow=None
if self.swig_cpp:
target_ext = '.cpp'
***************
*** 469,473 ****
(base, ext) = os.path.splitext(source)
if ext == ".i": # SWIG interface file
! new_sources.append(base + target_ext)
swig_sources.append(source)
swig_targets[source] = new_sources[-1]
--- 484,492 ----
(base, ext) = os.path.splitext(source)
if ext == ".i": # SWIG interface file
! if shadow:
! new_modules.append(base + ".py")
! new_sources.append(base + "c" + target_ext)
! else:
! new_sources.append(base + target_ext)
swig_sources.append(source)
swig_targets[source] = new_sources[-1]
***************
*** 476,480 ****
if not swig_sources:
! return new_sources
swig = self.find_swig()
--- 495,499 ----
if not swig_sources:
! return new_sources,new_modules
swig = self.find_swig()
***************
*** 482,486 ****
if self.swig_cpp:
swig_cmd.append("-c++")
!
for source in swig_sources:
target = swig_targets[source]
--- 501,507 ----
if self.swig_cpp:
swig_cmd.append("-c++")
! for arg in extra_swig_args:
! swig_cmd.append(arg)
!
for source in swig_sources:
target = swig_targets[source]
***************
*** 488,492 ****
self.spawn(swig_cmd + ["-o", target, source])
! return new_sources
# swig_sources ()
--- 509,513 ----
self.spawn(swig_cmd + ["-o", target, source])
! return new_sources,new_modules
# swig_sources ()
diff -r -C 2 -x *pyc /home/jgbauman/download/Distutils-1.0/distutils/command/install_lib.py ./command/install_lib.py
*** /home/jgbauman/download/Distutils-1.0/distutils/command/install_lib.py Tue Oct 3 05:32:37 2000
--- ./command/install_lib.py Fri Oct 6 01:11:21 2000
***************
*** 90,94 ****
# (Optionally) compile .py to .pyc
! if outfiles is not None and self.distribution.has_pure_modules():
self.byte_compile(outfiles)
--- 90,94 ----
# (Optionally) compile .py to .pyc
! if outfiles is not None:
self.byte_compile(outfiles)
diff -r -C 2 -x *pyc /home/jgbauman/download/Distutils-1.0/distutils/extension.py ./extension.py
*** /home/jgbauman/download/Distutils-1.0/distutils/extension.py Sun Sep 17 02:45:18 2000
--- ./extension.py Fri Oct 6 01:18:12 2000
***************
*** 74,78 ****
extensions, which typically export exactly one symbol: "init" +
extension_name.
! """
def __init__ (self, name, sources,
--- 74,84 ----
extensions, which typically export exactly one symbol: "init" +
extension_name.
! extra_swig_args : [string]
! any additional options for the swig tool. Unknown options will
! be passed unchanged.
! Known options:
! -c++: enable swig´s C++ support
! -shadow: generate shadow classes in python
! """
def __init__ (self, name, sources,
***************
*** 87,90 ****
--- 93,97 ----
extra_link_args=None,
export_symbols=None,
+ extra_swig_args=None,
):
***************
*** 106,109 ****
--- 113,117 ----
self.extra_link_args = extra_link_args or []
self.export_symbols = export_symbols or []
+ self.extra_swig_args = extra_swig_args or []
# class Extension
Hi all --
I'm uploading a new Distutils code snapshot; the only real important
change is Thomas' fix for the problems with zipfile.py-generated ZIP
files with the Windows installer. Also checked in the recent patches to
config.py and install.py (thanks to Bastian and Lyle!).
Here's the provisional changelog for Distutils 1.0.1 -- if there are no
problems with this snapshot, it will become Distutils 1.0.1 sometime
this weekend.
Relase 1.0.1 (?? October, 2000):
--------------------------------
* fixed Windows installer to deal with ZIP files created by the
zipfile module better (Thomas Heller)
* fixed install command's spurious warnings on Windows (due to
case-sensitive filename comparison)
* two tweaks to the (experimental, unfinished) config command:
make 'check_lib()' more like AC_CHECK_LIB, and make sure
any command-line options are the right type
The code snapshot is at the usual place...
http://www.python.org/sigs/distutils-sig/download.html
Greg
--
Greg Ward gward(a)python.net
http://starship.python.net/~gward/
Hi,
this is a patch to make check_lib more like AC_CHECK_LIB. Sometimes you
need additional libraries to compile programs.
Bastian
diff -BurN --exclude=*.pyc distutils/distutils/command/config.py distutils.patched/distutils/command/config.py
--- distutils/distutils/command/config.py Mon Oct 9 23:28:37 2000
+++ distutils.patched/distutils/command/config.py Tue Oct 10 11:07:17 2000
@@ -310,7 +310,7 @@
# check_func ()
def check_lib (self, library, library_dirs=None,
- headers=None, include_dirs=None):
+ headers=None, include_dirs=None, other_libraries=[]):
"""Determine if 'library' is available to be linked against,
without actually checking that any particular symbols are provided
by it. 'headers' will be used in constructing the source file to
@@ -319,7 +319,8 @@
"""
self._check_compiler()
return self.try_link("int main (void) { }",
- headers, include_dirs, [library], library_dirs)
+ headers, include_dirs,
+ [library]+other_libraries, library_dirs)
def check_header (self, header, include_dirs=None,
library_dirs=None, lang="c"):
On Windows one will often get the warning message "warning: install: modules
installed to 'c:\Python20\', which is not in Python's module search path
(sys.path) -- you'll have to change the search path yourself", even though
the named directory is in fact in the user's PYTHONPATH. The problem is that
the install command is using a case-sensitive comparision of the path names
and Python reports this path entry as "c:\python20" (note the lowercase
"p"). So the comparison fails and the install command emits this false
warning.
The attached patch to the current cvs version of install.py should correct
the problem.
Err, the reported problem wasn't in distutils. It's our software
distribution system called store that overwrote the Makefile for hpux
in config/ with the linux Makefile.
Sorry to waste your time on this (am I blushing?).
roy.
The Computer Center, University of Tromsø, N-9037 TROMSØ, Norway.
phone:+47 77 64 41 07, fax:+47 77 64 41 00
Roy Dragseth, High Perfomance Computing System Administrator
Direct call: +47 77 64 62 56. email: royd(a)cc.uit.no
Hi, I'm trying to build an extension written in c on a system with the
following characteristics:
OS: HP-UX 10.20
Python: v1.6
Distutils: v1.0
gcc: v2.95.2 with hp-ux ld (not gnu ld)
Python is built with gcc, and the problem is that gcc --shared doesn't
work (ok, this is probably me messing up gcc). Python seems to be
aware of this as it builds the shared modules using ld -b directly,
shouldn't distutils do the same thing? It used to, I had no problem
building this extension with python 1.5.2 and distutils 0.8.2.
Any hints greatly appreciated,
Roy.
The Computer Center, University of Tromsø, N-9037 TROMSØ, Norway.
phone:+47 77 64 41 07, fax:+47 77 64 41 00
Roy Dragseth, High Perfomance Computing System Administrator
Direct call: +47 77 64 62 56. email: royd(a)cc.uit.no
I've created a PyXML distribution with recent distutils (0.93 and
1.0). When installing these distributions, the installer creates empty
files only, see
http://download.sourceforge.net/pyxml/PyXML-0.6.0.win32.exe
for an example.
I've tracked this down to usage of the zipfile module. If it does not
find an external zip program (which I did not have), it then tries to
use the zipfile module. Somehow, the installation program later cannot
process the files created with that module.
The problem is probably in the installer, since Winzip 7 is capable of
reading the package, and extracts the files properly.
I have solved the problem by installing infozip on my
machine. However, I'd appreciate if somebody could look into the
problem and let me know what the cause is. If you cannot reproduce the
problem, please let me know as well.
Regards,
Martin
Hi,
I had troubles with distutils 1.0 and the way I use SWIG.
I couldn't find any support for the -shadow option and no way to pass an
extra include dir to swig (like it´s possible for the c compiler)
Therefore I wrote a patch.
It adds an extra_swig_args (list of string) option to Extension.
All the strings are passed to swig without modification, but
if extra_swig_args contains "-c++" or "-shadow" there is some special
action:
"-c++": behaves like build_ext --swig-cpp
"-shadow":
Normally swig generates a file:
foo.c -> foo.so
In this case SWIG generates two files:
foo.py (python shadow classes, imports fooc)
fooc.c -> fooc.so
With this patch build_ext can handle this und generates for foo.i
(foo.py, fooc.c) compiles them and installs them.
Below is the diff against disutils 1.0, apply in your Distutils-1.0
directory with:
patch -p5 < file
I hope it doesn´t break anything, isn´t against distutils design
principles and is so useful that it might become part of distutils.
Please answer me directly, because I didn´t not subscribe ths list.
Regards
joerg
Joerg Baumann joerg.baumann(a)stud.informatik.uni-erlangen.de
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Beware of bugs in the above code; I have only proved it correct,
not tried it.
Don Knuth
diff -r -C 2 -x *pyc /home/jgbauman/download/Distutils-1.0/distutils/command/build_ext.py ./command/build_ext.py
*** /home/jgbauman/download/Distutils-1.0/distutils/command/build_ext.py Sat Sep 30 20:27:54 2000
--- ./command/build_ext.py Fri Oct 6 01:23:08 2000
***************
*** 386,390 ****
# SWIG on 'em to create .c files, and modify the sources list
# accordingly.
! sources = self.swig_sources(sources)
# Next, compile the source code to object files.
--- 386,398 ----
# SWIG on 'em to create .c files, and modify the sources list
# accordingly.
! sources,extra_modules = self.swig_sources(sources,ext.extra_swig_args)
!
! # if there are extra_modules after running swig due to -shadow option
! # copy them to build/lib.xxx
! for module in extra_modules:
! outfile = os.path.join(self.build_lib,os.path.basename(module))
! dir = os.path.dirname(outfile)
! self.mkpath(dir)
! self.copy_file(module, outfile, preserve_mode=0)
# Next, compile the source code to object files.
***************
*** 444,448 ****
! def swig_sources (self, sources):
"""Walk the list of source files in 'sources', looking for SWIG
--- 452,456 ----
! def swig_sources (self, sources, extra_swig_args):
"""Walk the list of source files in 'sources', looking for SWIG
***************
*** 453,456 ****
--- 461,465 ----
new_sources = []
+ new_modules = []
swig_sources = []
swig_targets = {}
***************
*** 461,464 ****
--- 470,479 ----
# the temp dir.
+ if "-c++" in extra_swig_args:
+ self.swig_cpp=1
+ if "-shadow" in extra_swig_args:
+ shadow=1
+ else:
+ shadow=None
if self.swig_cpp:
target_ext = '.cpp'
***************
*** 469,473 ****
(base, ext) = os.path.splitext(source)
if ext == ".i": # SWIG interface file
! new_sources.append(base + target_ext)
swig_sources.append(source)
swig_targets[source] = new_sources[-1]
--- 484,492 ----
(base, ext) = os.path.splitext(source)
if ext == ".i": # SWIG interface file
! if shadow:
! new_modules.append(base + ".py")
! new_sources.append(base + "c" + target_ext)
! else:
! new_sources.append(base + target_ext)
swig_sources.append(source)
swig_targets[source] = new_sources[-1]
***************
*** 476,480 ****
if not swig_sources:
! return new_sources
swig = self.find_swig()
--- 495,499 ----
if not swig_sources:
! return new_sources,new_modules
swig = self.find_swig()
***************
*** 482,486 ****
if self.swig_cpp:
swig_cmd.append("-c++")
!
for source in swig_sources:
target = swig_targets[source]
--- 501,507 ----
if self.swig_cpp:
swig_cmd.append("-c++")
! for arg in extra_swig_args:
! swig_cmd.append(arg)
!
for source in swig_sources:
target = swig_targets[source]
***************
*** 488,492 ****
self.spawn(swig_cmd + ["-o", target, source])
! return new_sources
# swig_sources ()
--- 509,513 ----
self.spawn(swig_cmd + ["-o", target, source])
! return new_sources,new_modules
# swig_sources ()
diff -r -C 2 -x *pyc /home/jgbauman/download/Distutils-1.0/distutils/command/install_lib.py ./command/install_lib.py
*** /home/jgbauman/download/Distutils-1.0/distutils/command/install_lib.py Tue Oct 3 05:32:37 2000
--- ./command/install_lib.py Fri Oct 6 01:11:21 2000
***************
*** 90,94 ****
# (Optionally) compile .py to .pyc
! if outfiles is not None and self.distribution.has_pure_modules():
self.byte_compile(outfiles)
--- 90,94 ----
# (Optionally) compile .py to .pyc
! if outfiles is not None:
self.byte_compile(outfiles)
diff -r -C 2 -x *pyc /home/jgbauman/download/Distutils-1.0/distutils/extension.py ./extension.py
*** /home/jgbauman/download/Distutils-1.0/distutils/extension.py Sun Sep 17 02:45:18 2000
--- ./extension.py Fri Oct 6 01:18:12 2000
***************
*** 74,78 ****
extensions, which typically export exactly one symbol: "init" +
extension_name.
! """
def __init__ (self, name, sources,
--- 74,84 ----
extensions, which typically export exactly one symbol: "init" +
extension_name.
! extra_swig_args : [string]
! any additional options for the swig tool. Unknown options will
! be passed unchanged.
! Known options:
! -c++: enable swig´s C++ support
! -shadow: generate shadow classes in python
! """
def __init__ (self, name, sources,
***************
*** 87,90 ****
--- 93,97 ----
extra_link_args=None,
export_symbols=None,
+ extra_swig_args=None,
):
***************
*** 106,109 ****
--- 113,117 ----
self.extra_link_args = extra_link_args or []
self.export_symbols = export_symbols or []
+ self.extra_swig_args = extra_swig_args or []
# class Extension
Python Distribution Utilities
release 1.0
October 2, 2000
The Python Distribution Utilities, or Distutils for short, are a
collection of modules that aid in the development, distribution, and
installation of Python modules. (It is intended that ultimately the
Distutils will grow up into a system for distributing and installing
whole Python applications, but for now their scope is limited to module
distributions.)
The Distutils are a standard part of Python 1.6 and 2.0; if you are running
1.6 or 2.0, you don't need to install the Distutils separately. (However,
you might want to upgrade if you're running Python 1.6.) This release is
primarily so that you can add the Distutils to a Python 1.5.2 installation
-- you will then be able to install modules that require the Distutils, or
use the Distutils to distribute your own modules.
Distutils 1.0 is the version that will be released with Python 2.0 (unless
last-minute bugs pop up).
More information is available at the Distutils web page:
http://www.python.org/sigs/distutils-sig/
and in the README.txt included in the Distutils source distribution.
You can download the Distutils from
http://www.python.org/sigs/distutils-sig/download.html
Trivial patches can be sent to me (Greg Ward) at gward(a)python.net.
Larger patches should be discussed on the Distutils mailing list:
distutils-sig(a)python.org.
Greg
--
Greg Ward gward(a)python.net
http://starship.python.net/~gward/
And now for something completely different.