[Distutils] setuptools test command on Windows
theller at python.net
Thu Aug 18 21:57:50 CEST 2005
"Phillip J. Eby" <pje at telecommunity.com> writes:
> At 07:08 PM 8/18/2005 +0200, Thomas Heller wrote:
>>Seems I was late to try out setuptools. Fantastic package, is my first
>>impression. But I have still a lot to read and tryout.
>>But here is a first question: The 'test' command runs 'build_ext -i' and
>>then the tests.
> The "develop" command does this too.
>>The workaround I have used for the ctypes project so far is a __path__
>>hack: the main module importing this extension tries to execfile() a
>>special file that is in CVS, but never distributed. This file uses
>>distutils to determine the name of the build directory, inserts this
>>Is there anything in setuptools to work around that problem, or are
>>there any plans or ideas how this could work?
> Well, it occurs to me that it would be good for setuptools to track the
> last-built platform and Python version, and use "build_ext -if" if it
> differs from the current platform. That wouldn't allow simultaneous use of
> different platforms in the same directory, but it would allow serial
> switching between Python versions or platforms (e.g. even cygwin vs. win32)
> to be relatively painless.
build_ext -f rebuilds everything, which takes a long time for ctypes, at
least - because it reconfigures and rebuilds libffi also.
Since all the object files are still there, and in separate build
directories, deleting only the extensions would be enough.
Anyway, I was more thinking of a Python loader module in the current
directory, which would determine the platform-specific lib-directory,
and use imp to load the extension from there, and then update it's
globals from the extension. But I cannot currently figure out how to do
that in a robust way. FYI, here's what I've got so far. It will
probably not work for extensions in packages anyway, and if you run a
build_ext -i, the extension module in the current directory will be used
instead of the loader module:
# This module, when imported, imports an extension instead
# from the distutils' build directory with the same name.
# Must be placed in the same diectory as setup.py.
import sys, os, imp
from distutils.util import get_platform
modname = os.path.splitext(os.path.basename(__file__))
plat_specifier = ".%s-%s" % (get_platform(), sys.version[0:3])
build_dir = os.path.join('build', 'lib' + plat_specifier)
path = [os.path.abspath(os.path.join(os.path.dirname(__file__), build_dir))]
fil, pathname, descr = imp.find_module(modname, path)
mod = imp.load_module(modname, fil, pathname, descr)
More information about the Distutils-SIG