| [3] | 1 | |
|---|
| [27] | 2 | NAME = 'PySyck' |
|---|
| 3 | VERSION = '0.55.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://xitology.org/pysyck/" |
|---|
| 15 | DOWNLOAD_URL = URL + "%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 | |
|---|
| [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 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 |
|---|
| [32] | 38 | #home = os.environ.get('HOME', '') |
|---|
| [3] | 39 | |
|---|
| [32] | 40 | CHECK_SYCK = """ |
|---|
| 41 | #include <syck.h> |
|---|
| 42 | #include <stdio.h> |
|---|
| 43 | int main(void) { |
|---|
| 44 | syck_free_parser(syck_new_parser()); |
|---|
| 45 | syck_free_emitter(syck_new_emitter()); |
|---|
| 46 | puts(SYCK_VERSION); |
|---|
| 47 | return 0; |
|---|
| 48 | } |
|---|
| 49 | """ |
|---|
| 50 | CHECK_SYCK_PROG = './_check_syck' |
|---|
| 51 | |
|---|
| 52 | class PySyckBuildExt(build_ext): |
|---|
| 53 | |
|---|
| 54 | def build_extensions(self): |
|---|
| 55 | if not self.force: |
|---|
| 56 | self.check_syck() |
|---|
| 57 | build_ext.build_extensions(self) |
|---|
| 58 | |
|---|
| 59 | def _clean(self, *filenames): |
|---|
| 60 | for filename in filenames: |
|---|
| 61 | try: |
|---|
| 62 | os.remove(filename) |
|---|
| 63 | except OSError: |
|---|
| 64 | pass |
|---|
| 65 | |
|---|
| 66 | def check_syck(self): |
|---|
| 67 | prog = CHECK_SYCK_PROG |
|---|
| 68 | src = prog + '.c' |
|---|
| 69 | file(src, 'w').write(CHECK_SYCK) |
|---|
| 70 | [obj] = self.compiler.object_filenames([src]) |
|---|
| 71 | log.info("checking for syck.h") |
|---|
| 72 | try: |
|---|
| 73 | self.compiler.compile([src]) |
|---|
| 74 | except CompileError: |
|---|
| 75 | self._clean(src, obj) |
|---|
| 76 | raise CompileError, "syck.h is not found" |
|---|
| 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 | if self.compiler.exe_extension: |
|---|
| 84 | prog += self.compiler.exe_extension |
|---|
| 85 | log.info("checking syck version") |
|---|
| 86 | pipe = os.popen(prog, 'r') |
|---|
| 87 | data = pipe.read().strip() |
|---|
| 88 | pipe.close() |
|---|
| 89 | version = float(data) |
|---|
| 90 | log.info("syck version: %s" % version) |
|---|
| 91 | if version < 0.55: |
|---|
| 92 | self._clean(src, obj, prog) |
|---|
| 93 | raise CCompilerError, "syck 0.55 or higher is required" |
|---|
| 94 | self._clean(src, obj, prog) |
|---|
| 95 | |
|---|
| 96 | |
|---|
| [3] | 97 | setup( |
|---|
| [27] | 98 | name=NAME, |
|---|
| 99 | version=VERSION, |
|---|
| 100 | description=DESCRIPTION, |
|---|
| 101 | long_description=LONG_DESCRIPTION, |
|---|
| 102 | author=AUTHOR, |
|---|
| 103 | author_email=AUTHOR_EMAIL, |
|---|
| 104 | license=LICENSE, |
|---|
| 105 | platforms=PLATFORMS, |
|---|
| 106 | url=URL, |
|---|
| 107 | download_url=DOWNLOAD_URL, |
|---|
| 108 | classifiers=CLASSIFIERS, |
|---|
| 109 | |
|---|
| [3] | 110 | package_dir={'': 'lib'}, |
|---|
| 111 | packages=['syck'], |
|---|
| 112 | ext_modules=[ |
|---|
| 113 | Extension('_syck', ['ext/_syckmodule.c'], |
|---|
| [32] | 114 | # include_dirs=['../../include', '%s/include' % home, '/usr/local/include'], |
|---|
| 115 | # library_dirs=['../../lib', '%s/lib' % home, '/usr/local/include'], |
|---|
| [3] | 116 | libraries=['syck'], |
|---|
| 117 | ), |
|---|
| 118 | ], |
|---|
| [32] | 119 | cmdclass={ |
|---|
| 120 | 'build_ext': PySyckBuildExt, |
|---|
| 121 | }, |
|---|
| [3] | 122 | ) |
|---|
| 123 | |
|---|