source: pyyaml/trunk/setup.py @ 290

Revision 290, 5.1 KB checked in by xi, 6 years ago (diff)

Dropped setuptools-based setup.py in favor of custom distribution and build_ext command.

RevLine 
[39]1
[150]2NAME = 'PyYAML'
[275]3VERSION = '3.06'
[150]4DESCRIPTION = "YAML parser and emitter for Python"
5LONG_DESCRIPTION = """\
6YAML is a data serialization format designed for human readability and
[156]7interaction with scripting languages.  PyYAML is a YAML parser and
8emitter for Python.
[150]9
[156]10PyYAML features a complete YAML 1.1 parser, Unicode support, pickle
11support, capable extension API, and sensible error messages.  PyYAML
12supports standard YAML tags and provides Python-specific tags that allow
13to represent an arbitrary Python object.
[150]14
[156]15PyYAML is applicable for a broad range of tasks from complex
16configuration files to object serialization and persistance."""
[39]17AUTHOR = "Kirill Simonov"
18AUTHOR_EMAIL = 'xi@resolvent.net'
[59]19LICENSE = "MIT"
[150]20PLATFORMS = "Any"
21URL = "http://pyyaml.org/wiki/PyYAML"
22DOWNLOAD_URL = "http://pyyaml.org/download/pyyaml/%s-%s.tar.gz" % (NAME, VERSION)
23CLASSIFIERS = [
[275]24    "Development Status :: 5 - Production/Stable",
[150]25    "Intended Audience :: Developers",
26    "License :: OSI Approved :: MIT License",
27    "Operating System :: OS Independent",
28    "Programming Language :: Python",
29    "Topic :: Software Development :: Libraries :: Python Modules",
30    "Topic :: Text Processing :: Markup",
31]
[39]32
[281]33
[290]34from distutils.core import setup, Command
35from distutils.core import Distribution as _Distribution
36from distutils.core import Extension as _Extension
37from distutils.command.build_ext import build_ext as _build_ext
[39]38
[290]39try:
40    from Pyrex.Distutils import Extension as _Extension
41    from Pyrex.Distutils import build_ext as _build_ext
42    with_pyrex = True
43except ImportError:
44    with_pyrex = False
45
46import sys, os.path
47
48
49class Distribution(_Distribution):
50
51    def __init__(self, attrs=None):
52        _Distribution.__init__(self, attrs)
53        if not self.ext_modules:
54            return
55        for ext in reversed(self.ext_modules):
56            if not isinstance(ext, Extension):
57                continue
58            setattr(self, ext.attr_name, None)
59            self.global_options = [
60                    (ext.option_name, None,
61                        "include %s" % ext.feature_description),
62                    (ext.neg_option_name, None,
63                        "exclude %s (default)" % ext.feature_description),
64            ] + self.global_options
65            self.negative_opt = self.negative_opt.copy()
66            self.negative_opt[ext.neg_option_name] = ext.option_name
67
68
69class Extension(_Extension):
70
71    def __init__(self, name, sources, feature_name, feature_description, **kwds):
72        if not with_pyrex:
73            for filename in sources[:]:
74                base, ext = os.path.splitext(filename)
75                if ext == 'pyx':
76                    sources.replace(filename, '%s.c' % base)
77        _Extension.__init__(self, name, sources, **kwds)
78        self.feature_name = feature_name
79        self.feature_description = feature_description
80        self.attr_name = 'with_' + feature_name.replace('-', '_')
81        self.option_name = 'with-' + feature_name
82        self.neg_option_name = 'without-' + feature_name
83
84
85class build_ext(_build_ext):
86
87    def get_source_files(self):
88        self.check_extensions_list(self.extensions)
89        filenames = []
90        for ext in self.extensions:
91            if with_pyrex:
92                self.pyrex_sources(ext.sources, ext)
93            for filename in ext.sources:
94                filenames.append(filename)
95                base = os.path.splitext(filename)[0]
96                for ext in ['c', 'h', 'pyx', 'pxd']:
97                    filename = '%s.%s' % (base, ext)
98                    if filename not in filenames and os.path.isfile(filename):
99                        filenames.append(filename)
100        return filenames
101
102    def build_extensions(self):
103        self.check_extensions_list(self.extensions)
104        for ext in self.extensions:
105            if isinstance(ext, Extension):
106                if not getattr(self.distribution, ext.attr_name):
107                    continue
108            if with_pyrex:
109                ext.sources = self.pyrex_sources(ext.sources, ext)
110            self.build_extension(ext)
111
112
113class test(Command):
114
115    user_options = []
116
117    def initialize_options(self):
118        pass
119
120    def finalize_options(self):
121        pass
122
123    def run(self):
124        build_cmd = self.get_finalized_command('build')
125        build_cmd.run()
126        sys.path.insert(0, build_cmd.build_lib)
127        sys.path.insert(0, 'tests')
128        import test_all
129        test_all.main()
130
131
[227]132if __name__ == '__main__':
[39]133
[227]134    setup(
135        name=NAME,
136        version=VERSION,
137        description=DESCRIPTION,
138        long_description=LONG_DESCRIPTION,
139        author=AUTHOR,
140        author_email=AUTHOR_EMAIL,
141        license=LICENSE,
142        platforms=PLATFORMS,
143        url=URL,
144        download_url=DOWNLOAD_URL,
145        classifiers=CLASSIFIERS,
[39]146
[227]147        package_dir={'': 'lib'},
148        packages=['yaml'],
[290]149        ext_modules=[
150            Extension('yaml/_yaml', ['ext/_yaml.pyx'],
151                'libyaml', "LibYAML bindings",
152                libraries=['yaml']),
153        ],
[275]154
[290]155        distclass=Distribution,
156        cmdclass={
157            'build_ext': build_ext,
158            'test': test,
[275]159        },
[227]160    )
161
Note: See TracBrowser for help on using the repository browser.