This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Distutils SWIG support blocks use of SWIG -outdir option
Type: behavior Stage: resolved
Components: Distutils Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Useless error message when distutils fails compiling
View: 11599
Assigned To: tarek Nosy List: andybuckley, eric.araujo, iritkatriel, postofficered, tarek
Priority: normal Keywords:

Created on 2008-12-15 22:22 by andybuckley, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg77883 - (view) Author: Andy Buckley (andybuckley) Date: 2008-12-15 22:22
When using distutils to build an extension module using SWIG, it makes
most sense to use the built-in SWIG support. However, the distutils seem
to "vet" the options passed via the Extension.swig_opts attr/arg:

[...]
ext_modules=[Extension('_hepmc', ['@top_srcdir@/hepmc.i'],
               swig_opts=['-c++', '-I@HEPMCINCPATH@', '-outdir .'],
               include_dirs=['@HEPMCINCPATH@'],
               library_dirs=['@HEPMCLIBPATH@'],
               libraries=['HepMC'])],
[...]

results in this error:

building '_hepmc' extension
swigging ./hepmc.i to ./hepmc_wrap.cpp
swig -python -c++ -I/home/andy/heplocal/include -outdir . -o
./hepmc_wrap.cpp ./hepmc.i
swig error : Unrecognized option -outdir .
Use 'swig -help' for available options.
error: command 'swig' failed with exit status 1

but calling the same swig command works fine. It's the same copy of
swig, but it seems to be distutils rather than swig that is throwing the
error. This is particularly relevant since I need to use -outdir to meet
the autotools "distcheck" requirement of successfully building from a
build-dir separate from the source dir: code generation tools like SWIG
blur such a distinction and so need to support output location flags
like -outdir.

I see this was also noticed some time ago:
http://osdir.com/ml/python.distutils.devel/2006-06/msg00009.html
but no useful reply was ever forthcoming ;(  Maybe this time will be
luckier!
msg80430 - (view) Author: William Fulton (postofficered) Date: 2009-01-24 01:10
This error can be replicated on the command line with suitable quoting
of the -outdir option: 
swig -c++ "-outdir ." 

You need to pass the options correctly by separating them out, so use:

swig_opts=['-c++', '-I@HEPMCINCPATH@', '-outdir', '.']

I suggest distutils is fixed to show the quotes it is effectively adding
when displaying the command, so for the example Andy gave it should display:

swigging ./hepmc.i to ./hepmc_wrap.cpp
swig -python -c++ -I/home/andy/heplocal/include "-outdir ." -o
./hepmc_wrap.cpp ./hepmc.i

The quotes would need adding for display when a user has a space in any
of the options passed to SWIG (including the include_dirs etc).
msg80441 - (view) Author: Tarek Ziadé (tarek) * (Python committer) Date: 2009-01-24 10:29
Good suggestion, I'll add the quotes in the spawn call

Which does a simple log.info(string.join(cmd, ' ')) at the moment
msg80572 - (view) Author: Andy Buckley (andybuckley) Date: 2009-01-26 15:54
Dumb question, but why is distutils wrapping the command args in quotes
anyway? I'm not even sure why lists are being used (rather than a
string) for the options, except that lists are a bit more "Pythony" and
can be used to semantically divide the options from each other. If you
end up having to use separate list elements for the option flag and the
value it takes, doesn't that indicate that the list isn't being used
properly?
msg140031 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-07-08 14:37
Lists are used because that’s what the UNIX exec call accepts, or the constructor of subprocess.Popen.

About using %r in error messages, see also #11599.
msg381143 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-11-16 19:17
I think this was fixed in 11599. Any objections to closing this?
History
Date User Action Args
2022-04-11 14:56:42adminsetgithub: 48922
2020-11-30 19:38:47iritkatrielsetstatus: pending -> closed
stage: resolved
2020-11-16 19:17:15iritkatrielsetstatus: open -> pending

nosy: + iritkatriel
messages: + msg381143

superseder: Useless error message when distutils fails compiling
resolution: duplicate
2011-07-08 14:37:20eric.araujosetnosy: + eric.araujo
messages: + msg140031
2011-06-26 19:01:46terry.reedysetversions: + Python 3.2, - Python 2.6, Python 3.0, Python 3.1
2009-01-26 15:54:25andybuckleysetmessages: + msg80572
2009-01-24 10:29:15tareksetassignee: tarek
messages: + msg80441
nosy: + tarek
versions: + Python 2.6, Python 3.0, Python 3.1, Python 2.7, - Python 2.5
2009-01-24 01:10:12postofficeredsetnosy: + postofficered
messages: + msg80430
2008-12-15 22:22:31andybuckleycreate