| [3] | 1 | |
|---|
| [27] | 2 | NAME = 'PySyck' |
|---|
| [124] | 3 | VERSION = '0.61.2' |
|---|
| [27] | 4 | DESCRIPTION = "Python bindings for the Syck YAML parser and emitter" |
|---|
| 5 | LONG_DESCRIPTION = """\ |
|---|
| 6 | YAML is a data serialization format designed for human readability |
|---|
| 7 | and interaction with scripting languages. Syck is an extension for |
|---|
| 8 | reading and writing YAML in scripting languages. PySyck is aimed to |
|---|
| 9 | update the current Python bindings for Syck.""" |
|---|
| 10 | AUTHOR = "Kirill Simonov" |
|---|
| 11 | AUTHOR_EMAIL = 'xi@resolvent.net' |
|---|
| 12 | LICENSE = "BSD" |
|---|
| 13 | PLATFORMS = "Any" |
|---|
| [65] | 14 | URL = "http://pyyaml.org/wiki/PySyck" |
|---|
| 15 | DOWNLOAD_URL = "http://pyyaml.org/download/pysyck/%s-%s.tar.gz" % (NAME, VERSION) |
|---|
| [27] | 16 | CLASSIFIERS = [ |
|---|
| [123] | 17 | "Development Status :: 5 - Production/Stable", |
|---|
| [27] | 18 | "Intended Audience :: Developers", |
|---|
| 19 | "License :: OSI Approved :: BSD License", |
|---|
| 20 | "Programming Language :: Python", |
|---|
| 21 | "Topic :: Software Development :: Libraries :: Python Modules", |
|---|
| 22 | "Topic :: Text Processing :: Markup", |
|---|
| 23 | ] |
|---|
| 24 | |
|---|
| [3] | 25 | from distutils.core import setup, Extension |
|---|
| 26 | |
|---|
| [32] | 27 | from distutils import log |
|---|
| 28 | from distutils.command.build_ext import build_ext |
|---|
| 29 | from distutils.errors import CCompilerError, CompileError, LinkError |
|---|
| 30 | |
|---|
| [3] | 31 | import os |
|---|
| 32 | |
|---|
| [32] | 33 | CHECK_SYCK = """ |
|---|
| 34 | #include <syck.h> |
|---|
| 35 | #include <stdio.h> |
|---|
| 36 | int main(void) { |
|---|
| 37 | syck_free_parser(syck_new_parser()); |
|---|
| 38 | syck_free_emitter(syck_new_emitter()); |
|---|
| 39 | puts(SYCK_VERSION); |
|---|
| 40 | return 0; |
|---|
| 41 | } |
|---|
| 42 | """ |
|---|
| 43 | CHECK_SYCK_PROG = './_check_syck' |
|---|
| 44 | |
|---|
| 45 | class PySyckBuildExt(build_ext): |
|---|
| 46 | |
|---|
| 47 | def build_extensions(self): |
|---|
| 48 | if not self.force: |
|---|
| 49 | self.check_syck() |
|---|
| 50 | build_ext.build_extensions(self) |
|---|
| 51 | |
|---|
| 52 | def _clean(self, *filenames): |
|---|
| 53 | for filename in filenames: |
|---|
| 54 | try: |
|---|
| 55 | os.remove(filename) |
|---|
| 56 | except OSError: |
|---|
| 57 | pass |
|---|
| 58 | |
|---|
| 59 | def check_syck(self): |
|---|
| 60 | prog = CHECK_SYCK_PROG |
|---|
| 61 | src = prog + '.c' |
|---|
| 62 | file(src, 'w').write(CHECK_SYCK) |
|---|
| 63 | [obj] = self.compiler.object_filenames([src]) |
|---|
| 64 | log.info("checking for syck.h") |
|---|
| 65 | try: |
|---|
| 66 | self.compiler.compile([src]) |
|---|
| 67 | except CompileError: |
|---|
| 68 | self._clean(src, obj) |
|---|
| [50] | 69 | raise CompileError, "syck.h is not found, " \ |
|---|
| 70 | "try to uncomment the include_dirs parameter in setup.cfg" |
|---|
| [32] | 71 | log.info("checking for libsyck.a") |
|---|
| 72 | try: |
|---|
| 73 | self.compiler.link_executable([obj], prog, libraries=['syck']) |
|---|
| 74 | except LinkError: |
|---|
| 75 | self._clean(src, obj, prog) |
|---|
| [50] | 76 | raise LinkError, "libsyck.a is not found, " \ |
|---|
| 77 | "try to uncomment the library_dirs parameter in setup.cfg" |
|---|
| [32] | 78 | if self.compiler.exe_extension: |
|---|
| 79 | prog += self.compiler.exe_extension |
|---|
| 80 | log.info("checking syck version") |
|---|
| 81 | pipe = os.popen(prog, 'r') |
|---|
| 82 | data = pipe.read().strip() |
|---|
| 83 | pipe.close() |
|---|
| 84 | version = float(data) |
|---|
| 85 | log.info("syck version: %s" % version) |
|---|
| 86 | if version < 0.55: |
|---|
| 87 | self._clean(src, obj, prog) |
|---|
| 88 | raise CCompilerError, "syck 0.55 or higher is required" |
|---|
| 89 | self._clean(src, obj, prog) |
|---|
| 90 | |
|---|
| 91 | |
|---|
| [3] | 92 | setup( |
|---|
| [27] | 93 | name=NAME, |
|---|
| 94 | version=VERSION, |
|---|
| 95 | description=DESCRIPTION, |
|---|
| 96 | long_description=LONG_DESCRIPTION, |
|---|
| 97 | author=AUTHOR, |
|---|
| 98 | author_email=AUTHOR_EMAIL, |
|---|
| 99 | license=LICENSE, |
|---|
| 100 | platforms=PLATFORMS, |
|---|
| 101 | url=URL, |
|---|
| 102 | download_url=DOWNLOAD_URL, |
|---|
| 103 | classifiers=CLASSIFIERS, |
|---|
| 104 | |
|---|
| [3] | 105 | package_dir={'': 'lib'}, |
|---|
| 106 | packages=['syck'], |
|---|
| 107 | ext_modules=[ |
|---|
| 108 | Extension('_syck', ['ext/_syckmodule.c'], |
|---|
| [65] | 109 | # include_dirs=[], # do not uncomment this, edit setup.cfg instead. |
|---|
| 110 | # library_dirs=[], # do not uncomment this, edit setup.cfg instead. |
|---|
| [3] | 111 | libraries=['syck'], |
|---|
| 112 | ), |
|---|
| 113 | ], |
|---|
| [32] | 114 | cmdclass={ |
|---|
| 115 | 'build_ext': PySyckBuildExt, |
|---|
| 116 | }, |
|---|
| [3] | 117 | ) |
|---|
| 118 | |
|---|