root/trunk/setup.py @ 23010

Revision 23010, 2.9 KB (checked in by radix, 2 years ago)

Merge easy_install-1286-5

Author: radix
Reviewer: therve, exarkun
Fixes #1286

The top-level setup.py file has been rewritten as a normal distutils script.
It also added optional support for setuptools, so that it's possible to
easy_install Twisted and even have it automatically download zope.interface
if necessary. twisted.python.dist has changed so that it now accepts a list
of Extension objects which know how to check if they should be built, rather
than a function that dynamically creates a list of buildable Extensions.
This made sharing between subproject and main Twisted setup.py files easier.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2
3# Copyright (c) 2001-2008 Twisted Matrix Laboratories.
4# See LICENSE for details.
5
6"""
7Distutils installer for Twisted.
8"""
9
10try:
11    # Load setuptools, to build a specific source package
12    import setuptools
13except ImportError:
14    pass
15
16import sys, os
17
18
19def getExtensions():
20    """
21    Get all extensions from core and all subprojects.
22    """
23    extensions = []
24    for dir in os.listdir("twisted") + [""]:
25        topfiles = os.path.join("twisted", dir, "topfiles")
26        if os.path.isdir(topfiles):
27            ns = {}
28            setup_py = os.path.join(topfiles, "setup.py")
29            execfile(setup_py, ns, ns)
30            if "extensions" in ns:
31                extensions.extend(ns["extensions"])
32    return extensions
33
34
35def main(args):
36    """
37    Invoke twisted.python.dist with the appropriate metadata about the
38    Twisted package.
39    """
40    if os.path.exists('twisted'):
41        sys.path.insert(0, '.')
42    from twisted import copyright
43    from twisted.python.dist import getDataFiles, getScripts, getPackages, setup
44
45    # "" is included because core scripts are directly in bin/
46    projects = [''] + [x for x in os.listdir('bin')
47                       if os.path.isdir(os.path.join("bin", x))
48                       and not x.startswith(".")]
49    scripts = []
50    for i in projects:
51        scripts.extend(getScripts(i))
52
53        setup_args = dict(
54            # metadata
55            name="Twisted",
56            version=copyright.version,
57            description="An asynchronous networking framework written in "
58                        "Python",
59            author="Twisted Matrix Laboratories",
60            author_email="twisted-python@twistedmatrix.com",
61            maintainer="Glyph Lefkowitz",
62            maintainer_email="glyph@twistedmatrix.com",
63            url="http://twistedmatrix.com/",
64            license="MIT",
65            long_description="""\
66An extensible framework for Python programming, with special focus
67on event-based network programming and multiprotocol integration.
68""",
69            packages = getPackages('twisted'),
70            conditionalExtensions = getExtensions(),
71            scripts = scripts,
72            data_files=getDataFiles('twisted'),
73            )
74
75    if 'setuptools' in sys.modules:
76        from pkg_resources import parse_requirements
77        requirements = ["zope.interface"]
78        try:
79            list(parse_requirements(requirements))
80        except:
81            print """You seem to be running a very old version of setuptools.
82This version of setuptools has a bug parsing dependencies, so automatic
83dependency resolution is disabled.
84"""
85        else:
86            setup_args['install_requires'] = requirements
87        setup_args['include_package_data'] = True
88        setup_args['zip_safe'] = False
89    setup(**setup_args)
90
91
92if __name__ == "__main__":
93    try:
94        main(sys.argv[1:])
95    except KeyboardInterrupt:
96        sys.exit(1)
Note: See TracBrowser for help on using the browser.