[Distutils] Extending distutils with 3rd party build commands?
M.-A. Lemburg
mal at egenix.com
Thu Oct 21 01:09:11 CEST 2004
Bob Ippolito wrote:
> On Oct 20, 2004, at 18:38, Bob Ippolito wrote:
>
>> On Oct 20, 2004, at 18:10, M.-A. Lemburg wrote:
>>
>>> Bob Ippolito wrote:
>>>
>>>> I've developed two bdist commands (bdist_pkg and bdist_mpkg) for
>>>> usage on OS X. These commands apply to any setup.py that supports
>>>> an "install" command, similar to bdist_wininst, so it would be nice
>>>> if every setup.py didn't have to explicitly import something in
>>>> order to get the commands there.
>>>> I know I can make it work with a pth file that imports bdist_pkg,
>>>> but that seems a bit costly to do because it will end up importing a
>>>> bunch of stuff (distutils, mainly).
>>>> Is there another way to do it?
>>>
>>>
>>> Submit them for inclusion in the standard distribution ;-)
>>
>>
>> I will, for 2.5... but there's quite some time between now and then.
>
>
> Well I did find another way, thanks to PEP 302.
>
> How "evil" would it be if I had this module imported by a pth file? It
> does do what I want it to do, but I'm not sure if it's safe to inflict
> on users or not..
Import hooks are bad. Avoid them if you can.
What so bad in adding a sinlge import to all your setup.pys ?
That import could then trigger the installation of the new
command by importing distutils and tweaking the cmdclass
in distutils, e.g.
import biDistutilsExtensions
> --
>
> import sys
> import imp
> try:
> set
> except NameError:
> from sets import Set as set
>
> class DistutilsHook(object):
> def __init__(self, package='distutils', hooks=('py2app',
> 'bdist_mpkg')):
> self.package = package
> self.hooks = set(hooks)
> self.hooks.add(package)
>
> def find_module(self, fullname, path=None):
> if fullname in self.hooks:
> self.hooks.remove(fullname)
> if fullname != self.package:
> return None
> try:
> sys.meta_path.remove(self)
> except ValueError:
> pass
> try:
> fileobj, filename, stuff = imp.find_module(fullname, None)
> except ImportError:
> return None
> hooks = list(self.hooks)
> self.hooks.clear()
> return ImpLoader(fileobj, filename, stuff, hooks)
>
> class ImpLoader(object):
> def __init__(self, fileobj, filename, stuff, hooks):
> self.fileobj = fileobj
> self.filename = filename
> self.stuff = stuff
> self.hooks = hooks
>
> def load_module(self, fullname):
> mod = imp.load_module(fullname, self.fileobj, self.filename,
> self.stuff)
> if self.fileobj:
> self.fileobj.close()
> for hook in self.hooks:
> try:
> __import__(hook)
> except:
> pass
> return mod
>
> sys.meta_path.insert(0, DistutilsHook())
>
> _______________________________________________
> Distutils-SIG maillist - Distutils-SIG at python.org
> http://mail.python.org/mailman/listinfo/distutils-sig
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Oct 20 2004)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::
More information about the Distutils-SIG
mailing list