source: pyyaml/trunk/setup.py @ 295

Revision 295, 8.8 KB checked in by xi, 6 years ago (diff)

Dropped tests from the source distribution since LibYAML bindings do not pass them; updated README and announcement.msg; renamed 'yaml.libyaml' to 'yaml.with_libyaml'.

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
[292]34LIBYAML_CHECK = """
35#include <yaml.h>
36
37int main(void) {
38    yaml_parser_t parser;
39    yaml_emitter_t emitter;
40
41    yaml_parser_initialize(&parser);
42    yaml_parser_delete(&parser);
43
44    yaml_emitter_initialize(&emitter);
45    yaml_emitter_delete(&emitter);
46
47    return 0;
48}
49"""
50
51
52from distutils import log
[290]53from distutils.core import setup, Command
54from distutils.core import Distribution as _Distribution
55from distutils.core import Extension as _Extension
[292]56from distutils.dir_util import mkpath
[290]57from distutils.command.build_ext import build_ext as _build_ext
[294]58from distutils.errors import CompileError, LinkError, DistutilsPlatformError
[39]59
[290]60try:
61    from Pyrex.Distutils import Extension as _Extension
62    from Pyrex.Distutils import build_ext as _build_ext
63    with_pyrex = True
64except ImportError:
65    with_pyrex = False
66
67import sys, os.path
68
69
70class Distribution(_Distribution):
71
72    def __init__(self, attrs=None):
73        _Distribution.__init__(self, attrs)
74        if not self.ext_modules:
75            return
[294]76        for idx in range(len(self.ext_modules)-1, -1, -1):
77            ext = self.ext_modules[idx]
[290]78            if not isinstance(ext, Extension):
79                continue
80            setattr(self, ext.attr_name, None)
81            self.global_options = [
82                    (ext.option_name, None,
[292]83                        "include %s (default if %s is available)"
84                        % (ext.feature_description, ext.feature_name)),
[290]85                    (ext.neg_option_name, None,
[292]86                        "exclude %s" % ext.feature_description),
[290]87            ] + self.global_options
88            self.negative_opt = self.negative_opt.copy()
89            self.negative_opt[ext.neg_option_name] = ext.option_name
90
91
92class Extension(_Extension):
93
[292]94    def __init__(self, name, sources, feature_name, feature_description,
95            feature_check, **kwds):
[290]96        if not with_pyrex:
97            for filename in sources[:]:
98                base, ext = os.path.splitext(filename)
[294]99                if ext == '.pyx':
100                    sources.remove(filename)
101                    sources.append('%s.c' % base)
[290]102        _Extension.__init__(self, name, sources, **kwds)
103        self.feature_name = feature_name
104        self.feature_description = feature_description
[292]105        self.feature_check = feature_check
[290]106        self.attr_name = 'with_' + feature_name.replace('-', '_')
107        self.option_name = 'with-' + feature_name
108        self.neg_option_name = 'without-' + feature_name
109
110
111class build_ext(_build_ext):
112
[294]113    def run(self):
114        optional = True
115        disabled = True
116        for ext in self.extensions:
117            if isinstance(ext, Extension):
118                with_ext = getattr(self.distribution, ext.attr_name)
119                if with_ext is None:
120                    disabled = False
121                elif with_ext:
122                    optional = False
123                    disabled = False
124            else:
125                optional = False
126                disabled = False
127                break
128        if disabled:
129            return
130        try:
131            _build_ext.run(self)
132        except DistutilsPlatformError, exc:
133            if optional:
134                log.warn(str(exc))
135                log.warn("skipping build_ext")
136            else:
137                raise
138
[290]139    def get_source_files(self):
140        self.check_extensions_list(self.extensions)
141        filenames = []
142        for ext in self.extensions:
143            if with_pyrex:
144                self.pyrex_sources(ext.sources, ext)
145            for filename in ext.sources:
146                filenames.append(filename)
147                base = os.path.splitext(filename)[0]
148                for ext in ['c', 'h', 'pyx', 'pxd']:
149                    filename = '%s.%s' % (base, ext)
150                    if filename not in filenames and os.path.isfile(filename):
151                        filenames.append(filename)
152        return filenames
153
154    def build_extensions(self):
155        self.check_extensions_list(self.extensions)
156        for ext in self.extensions:
157            if isinstance(ext, Extension):
[292]158                with_ext = getattr(self.distribution, ext.attr_name)
159                if with_ext is None:
160                    with_ext = self.check_extension_availability(ext)
161                if not with_ext:
[290]162                    continue
163            if with_pyrex:
164                ext.sources = self.pyrex_sources(ext.sources, ext)
165            self.build_extension(ext)
166
[292]167    def check_extension_availability(self, ext):
168        cache = os.path.join(self.build_temp, 'check_%s.out' % ext.feature_name)
169        if not self.force and os.path.isfile(cache):
170            data = open(cache).read().strip()
171            if data == '1':
172                return True
173            elif data == '0':
174                return False
175        mkpath(self.build_temp)
176        src = os.path.join(self.build_temp, 'check_%s.c' % ext.feature_name)
177        open(src, 'w').write(ext.feature_check)
178        log.info("checking if %s compiles" % ext.feature_name)
179        try:
180            [obj] = self.compiler.compile([src],
181                    macros=ext.define_macros+[(undef,) for undef in ext.undef_macros],
182                    include_dirs=ext.include_dirs,
183                    extra_postargs=(ext.extra_compile_args or []),
184                    depends=ext.depends)
185        except CompileError:
186            log.warn("%s appears not to be installed" % ext.feature_name)
187            log.warn("(if %s is installed, you may need to specify"
188                    % ext.feature_name)
189            log.warn(" the option --include-dirs or uncomment and modify")
190            log.warn(" the parameter include_dirs in setup.cfg)")
191            open(cache, 'w').write('0\n')
192            return False
193        prog = 'check_%s' % ext.feature_name
194        log.info("checking if %s links" % ext.feature_name)
195        try:
196            self.compiler.link_executable([obj], prog,
197                    output_dir=self.build_temp,
198                    libraries=ext.libraries,
199                    library_dirs=ext.library_dirs,
200                    runtime_library_dirs=ext.runtime_library_dirs,
201                    extra_postargs=(ext.extra_link_args or []))
202        except LinkError:
203            log.warn("unable to link against %s" % ext.feature_name)
204            log.warn("(if %s is installed correctly, you may need to specify"
205                    % ext.feature_name)
206            log.warn(" the option --library-dirs or uncomment and modify")
207            log.warn(" the parameter library_dirs in setup.cfg)")
208            open(cache, 'w').write('0\n')
209            return False
210        open(cache, 'w').write('1\n')
211        return True
[290]212
[292]213
[290]214class test(Command):
215
216    user_options = []
217
218    def initialize_options(self):
219        pass
220
221    def finalize_options(self):
222        pass
223
224    def run(self):
225        build_cmd = self.get_finalized_command('build')
226        build_cmd.run()
227        sys.path.insert(0, build_cmd.build_lib)
228        sys.path.insert(0, 'tests')
229        import test_all
230        test_all.main()
231
232
[227]233if __name__ == '__main__':
[39]234
[227]235    setup(
236        name=NAME,
237        version=VERSION,
238        description=DESCRIPTION,
239        long_description=LONG_DESCRIPTION,
240        author=AUTHOR,
241        author_email=AUTHOR_EMAIL,
242        license=LICENSE,
243        platforms=PLATFORMS,
244        url=URL,
245        download_url=DOWNLOAD_URL,
246        classifiers=CLASSIFIERS,
[39]247
[227]248        package_dir={'': 'lib'},
249        packages=['yaml'],
[290]250        ext_modules=[
[294]251            Extension('_yaml', ['ext/_yaml.pyx'],
[292]252                'libyaml', "LibYAML bindings", LIBYAML_CHECK,
[290]253                libraries=['yaml']),
254        ],
[275]255
[290]256        distclass=Distribution,
257        cmdclass={
258            'build_ext': build_ext,
[295]259#            'test': test,
[275]260        },
[227]261    )
262
Note: See TracBrowser for help on using the repository browser.