[Distutils] Extending distutils with 3rd party build commands?
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 sys
> import imp
> except NameError:
> from sets import Set as set
> class DistutilsHook(object):
> def __init__(self, package='distutils', hooks=('py2app',
> self.package = package
> self.hooks = set(hooks)
> def find_module(self, fullname, path=None):
> if fullname in self.hooks:
> if fullname != self.package:
> return None
> except ValueError:
> fileobj, filename, stuff = imp.find_module(fullname, None)
> except ImportError:
> return None
> hooks = list(self.hooks)
> 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,
> if self.fileobj:
> for hook in self.hooks:
> return mod
> sys.meta_path.insert(0, DistutilsHook())
> Distutils-SIG maillist - Distutils-SIG at python.org
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