| 1 | |
|---|
| 2 | NAME = 'PySyck' |
|---|
| 3 | VERSION = '0.61.1' |
|---|
| 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" |
|---|
| 14 | URL = "http://pyyaml.org/wiki/PySyck" |
|---|
| 15 | DOWNLOAD_URL = "http://pyyaml.org/download/pysyck/%s-%s.tar.gz" % (NAME, VERSION) |
|---|
| 16 | CLASSIFIERS = [ |
|---|
| 17 | "Development Status :: 3 - Alpha", |
|---|
| 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 | |
|---|
| 25 | from distutils.core import setup, Extension |
|---|
| 26 | |
|---|
| 27 | from distutils import log |
|---|
| 28 | from distutils.command.build_ext import build_ext |
|---|
| 29 | from distutils.errors import CCompilerError, CompileError, LinkError |
|---|
| 30 | |
|---|
| 31 | import sys |
|---|
| 32 | if sys.version < '2.2.4': |
|---|
| 33 | from distutils.dist import DistributionMetadata |
|---|
| 34 | DistributionMetadata.classifiers = None |
|---|
| 35 | DistributionMetadata.download_url = None |
|---|
| 36 | |
|---|
| 37 | import os |
|---|
| 38 | |
|---|
| 39 | CHECK_SYCK = """ |
|---|
| 40 | #include <syck.h> |
|---|
| 41 | #include <stdio.h> |
|---|
| 42 | int main(void) { |
|---|
| 43 | syck_free_parser(syck_new_parser()); |
|---|
| 44 | syck_free_emitter(syck_new_emitter()); |
|---|
| 45 | puts(SYCK_VERSION); |
|---|
| 46 | return 0; |
|---|
| 47 | } |
|---|
| 48 | """ |
|---|
| 49 | CHECK_SYCK_PROG = './_check_syck' |
|---|
| 50 | |
|---|
| 51 | class PySyckBuildExt(build_ext): |
|---|
| 52 | |
|---|
| 53 | def build_extensions(self): |
|---|
| 54 | if not self.force: |
|---|
| 55 | self.check_syck() |
|---|
| 56 | build_ext.build_extensions(self) |
|---|
| 57 | |
|---|
| 58 | def _clean(self, *filenames): |
|---|
| 59 | for filename in filenames: |
|---|
| 60 | try: |
|---|
| 61 | os.remove(filename) |
|---|
| 62 | except OSError: |
|---|
| 63 | pass |
|---|
| 64 | |
|---|
| 65 | def check_syck(self): |
|---|
| 66 | prog = CHECK_SYCK_PROG |
|---|
| 67 | src = prog + '.c' |
|---|
| 68 | file(src, 'w').write(CHECK_SYCK) |
|---|
| 69 | [obj] = self.compiler.object_filenames([src]) |
|---|
| 70 | log.info("checking for syck.h") |
|---|
| 71 | try: |
|---|
| 72 | self.compiler.compile([src]) |
|---|
| 73 | except CompileError: |
|---|
| 74 | self._clean(src, obj) |
|---|
| 75 | raise CompileError, "syck.h is not found, " \ |
|---|
| 76 | "try to uncomment the include_dirs parameter in setup.cfg" |
|---|
| 77 | log.info("checking for libsyck.a") |
|---|
| 78 | try: |
|---|
| 79 | self.compiler.link_executable([obj], prog, libraries=['syck']) |
|---|
| 80 | except LinkError: |
|---|
| 81 | self._clean(src, obj, prog) |
|---|
| 82 | raise LinkError, "libsyck.a is not found, " \ |
|---|
| 83 | "try to uncomment the library_dirs parameter in setup.cfg" |
|---|
| 84 | if self.compiler.exe_extension: |
|---|
| 85 | prog += self.compiler.exe_extension |
|---|
| 86 | log.info("checking syck version") |
|---|
| 87 | pipe = os.popen(prog, 'r') |
|---|
| 88 | data = pipe.read().strip() |
|---|
| 89 | pipe.close() |
|---|
| 90 | version = float(data) |
|---|
| 91 | log.info("syck version: %s" % version) |
|---|
| 92 | if version < 0.55: |
|---|
| 93 | self._clean(src, obj, prog) |
|---|
| 94 | raise CCompilerError, "syck 0.55 or higher is required" |
|---|
| 95 | self._clean(src, obj, prog) |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | setup( |
|---|
| 99 | name=NAME, |
|---|
| 100 | version=VERSION, |
|---|
| 101 | description=DESCRIPTION, |
|---|
| 102 | long_description=LONG_DESCRIPTION, |
|---|
| 103 | author=AUTHOR, |
|---|
| 104 | author_email=AUTHOR_EMAIL, |
|---|
| 105 | license=LICENSE, |
|---|
| 106 | platforms=PLATFORMS, |
|---|
| 107 | url=URL, |
|---|
| 108 | download_url=DOWNLOAD_URL, |
|---|
| 109 | classifiers=CLASSIFIERS, |
|---|
| 110 | |
|---|
| 111 | package_dir={'': 'lib'}, |
|---|
| 112 | packages=['syck'], |
|---|
| 113 | ext_modules=[ |
|---|
| 114 | Extension('_syck', ['ext/_syckmodule.c'], |
|---|
| 115 | # include_dirs=[], # do not uncomment this, edit setup.cfg instead. |
|---|
| 116 | # library_dirs=[], # do not uncomment this, edit setup.cfg instead. |
|---|
| 117 | libraries=['syck'], |
|---|
| 118 | ), |
|---|
| 119 | ], |
|---|
| 120 | cmdclass={ |
|---|
| 121 | 'build_ext': PySyckBuildExt, |
|---|
| 122 | }, |
|---|
| 123 | ) |
|---|
| 124 | |
|---|