[Twisted-Python] zpkg usage in Twisted (was: including plugins.tml in a package?)

Christopher Armstrong radeex at gmail.com
Mon Aug 16 23:43:08 EDT 2004


On Mon, 16 Aug 2004 22:50:35 -0400, Fred L. Drake, Jr. <fdrake at acm.org> wrote:
> It just struck me that you cross-posted from the Twisted list; Twisted is
> moving to use the "zpkg" tool I wrote for Zope 3 for packaging.  zpkg
> automatically makes data files from a package part of the installation of
> that package if you don't tell it to do something different with them.
> 
> Information about zpkg is available at:
> 
>     http://www.zope.org/Members/fdrake/zpkgtools/
> 
> I'll be glad to answer questions and generally try to improve the
> documentation to make zpkg easier to learn and use.

And here my cue to start asking questions. :-)

Fred, our setup.py is pretty scary. It's full of hacks specific to
various platforms, etc. I'll list all those which confuse me here and
hopefully you can tell me the best way to port this stuff to zpkg --
whether zpkg handles it already or if I need to extend the way it
calls distutils (and how I can do that).

(in order that they appear in our setup.py)
1) build_scripts_twisted
2) build_ext_twisted
3) OS-X gcc arguments hack
4) WIN32 macro

1) build_scripts_twisted

class build_scripts_twisted(build_scripts):
    """Renames scripts so they end with '.py' on Windows."""

    def run(self):
        build_scripts.run(self)
        if os.name == "nt":
            for f in os.listdir(self.build_dir):
                fpath=os.path.join(self.build_dir, f)
                if not fpath.endswith(".py"):
                    try:
                        os.unlink(fpath + ".py")
                    except EnvironmentError, e:
                        if e.args[1]=='No such file or directory':
                            pass
                    os.rename(fpath, fpath + ".py")

2) build_ext_twisted

This is a doozy. As the name implies, it's a subclass of build_ext. It
overrides build_extensions to call self._detect_modules before calling
the regular build_extensions; _detect_modules does a bunch of compiler
tests, conditionally adding things to self.extensions.

The tests generate .c file that uses CPP directives to test for the
existence of header files and names from those headers. Oh, and one
that checks for a struct member (yow). It uses self.compiler.compile
to run these through the compiler and checks for a CompileError.

3) OS-X GCC arguments hack

# Apple distributes a nasty version of Python 2.2 w/ all release builds of
# OS X 10.2 and OS X Server 10.2
BROKEN_CONFIG = '2.2 (#1, 07/14/02, 23:25:09) \n[GCC Apple cpp-precomp 6.14]'
if sys.platform == 'darwin' and sys.version == BROKEN_CONFIG:
    # change this to 1 if you have some need to compile
    # with -flat_namespace as opposed to -bundle_loader
    FLAT_NAMESPACE = 0
    BROKEN_ARCH = '-arch i386'
    BROKEN_NAMESPACE = '-flat_namespace -undefined_suppress'
    import distutils.sysconfig
    distutils.sysconfig.get_config_vars()
    x = distutils.sysconfig._config_vars['LDSHARED']
    y = x.replace(BROKEN_ARCH, '')
    if not FLAT_NAMESPACE:
        e = os.path.realpath(sys.executable)
        y = y.replace(BROKEN_NAMESPACE, '-bundle_loader ' + e)
    if y != x:
        print "Fixing some of Apple's compiler flag mistakes..."
        distutils.sysconfig._config_vars['LDSHARED'] = y


4) WIN32 macro

# always define WIN32 under Windows
if os.name == 'nt':
    define_macros = [("WIN32", 1)]
else:
    define_macros = []

I got no idea what this does.


Any idea how I should port these things to zpkg?

Thanks!

-- 
 Twisted | Christopher Armstrong: International Man of Twistery
  Radix  |          Release Manager,  Twisted Project
---------+            http://radix.twistedmatrix.com




More information about the Twisted-Python mailing list