| 1 | |
|---|
| 2 | NAME = 'PyYAML' |
|---|
| 3 | VERSION = '3.07' |
|---|
| 4 | DESCRIPTION = "YAML parser and emitter for Python" |
|---|
| 5 | LONG_DESCRIPTION = """\ |
|---|
| 6 | YAML is a data serialization format designed for human readability and |
|---|
| 7 | interaction with scripting languages. PyYAML is a YAML parser and |
|---|
| 8 | emitter for Python. |
|---|
| 9 | |
|---|
| 10 | PyYAML features a complete YAML 1.1 parser, Unicode support, pickle |
|---|
| 11 | support, capable extension API, and sensible error messages. PyYAML |
|---|
| 12 | supports standard YAML tags and provides Python-specific tags that allow |
|---|
| 13 | to represent an arbitrary Python object. |
|---|
| 14 | |
|---|
| 15 | PyYAML is applicable for a broad range of tasks from complex |
|---|
| 16 | configuration files to object serialization and persistance.""" |
|---|
| 17 | AUTHOR = "Kirill Simonov" |
|---|
| 18 | AUTHOR_EMAIL = 'xi@resolvent.net' |
|---|
| 19 | LICENSE = "MIT" |
|---|
| 20 | PLATFORMS = "Any" |
|---|
| 21 | URL = "http://pyyaml.org/wiki/PyYAML" |
|---|
| 22 | DOWNLOAD_URL = "http://pyyaml.org/download/pyyaml/%s-%s.tar.gz" % (NAME, VERSION) |
|---|
| 23 | CLASSIFIERS = [ |
|---|
| 24 | "Development Status :: 5 - Production/Stable", |
|---|
| 25 | "Intended Audience :: Developers", |
|---|
| 26 | "License :: OSI Approved :: MIT License", |
|---|
| 27 | "Operating System :: OS Independent", |
|---|
| 28 | "Programming Language :: Python", |
|---|
| 29 | "Programming Language :: Python :: 2", |
|---|
| 30 | "Programming Language :: Python :: 2.3", |
|---|
| 31 | "Programming Language :: Python :: 2.4", |
|---|
| 32 | "Programming Language :: Python :: 2.5", |
|---|
| 33 | "Programming Language :: Python :: 2.6", |
|---|
| 34 | # Python 3.0 is not yet supported, but see http://pyyaml.org/ticket/74 |
|---|
| 35 | # "Programming Language :: Python :: 3", |
|---|
| 36 | # "Programming Language :: Python :: 3.0", |
|---|
| 37 | "Topic :: Software Development :: Libraries :: Python Modules", |
|---|
| 38 | "Topic :: Text Processing :: Markup", |
|---|
| 39 | ] |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | LIBYAML_CHECK = """ |
|---|
| 43 | #include <yaml.h> |
|---|
| 44 | |
|---|
| 45 | int main(void) { |
|---|
| 46 | yaml_parser_t parser; |
|---|
| 47 | yaml_emitter_t emitter; |
|---|
| 48 | |
|---|
| 49 | yaml_parser_initialize(&parser); |
|---|
| 50 | yaml_parser_delete(&parser); |
|---|
| 51 | |
|---|
| 52 | yaml_emitter_initialize(&emitter); |
|---|
| 53 | yaml_emitter_delete(&emitter); |
|---|
| 54 | |
|---|
| 55 | return 0; |
|---|
| 56 | } |
|---|
| 57 | """ |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | import sys, os.path |
|---|
| 61 | |
|---|
| 62 | from distutils import log |
|---|
| 63 | from distutils.core import setup, Command |
|---|
| 64 | from distutils.core import Distribution as _Distribution |
|---|
| 65 | from distutils.core import Extension as _Extension |
|---|
| 66 | from distutils.dir_util import mkpath |
|---|
| 67 | from distutils.command.build_ext import build_ext as _build_ext |
|---|
| 68 | from distutils.command.bdist_rpm import bdist_rpm as _bdist_rpm |
|---|
| 69 | from distutils.errors import CompileError, LinkError, DistutilsPlatformError |
|---|
| 70 | |
|---|
| 71 | if 'setuptools.extension' in sys.modules: |
|---|
| 72 | _Extension = sys.modules['setuptools.extension']._Extension |
|---|
| 73 | sys.modules['distutils.core'].Extension = _Extension |
|---|
| 74 | sys.modules['distutils.extension'].Extension = _Extension |
|---|
| 75 | sys.modules['distutils.command.build_ext'].Extension = _Extension |
|---|
| 76 | |
|---|
| 77 | try: |
|---|
| 78 | from Pyrex.Distutils import Extension as _Extension |
|---|
| 79 | from Pyrex.Distutils import build_ext as _build_ext |
|---|
| 80 | with_pyrex = True |
|---|
| 81 | except ImportError: |
|---|
| 82 | with_pyrex = False |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | class Distribution(_Distribution): |
|---|
| 86 | |
|---|
| 87 | def __init__(self, attrs=None): |
|---|
| 88 | _Distribution.__init__(self, attrs) |
|---|
| 89 | if not self.ext_modules: |
|---|
| 90 | return |
|---|
| 91 | for idx in range(len(self.ext_modules)-1, -1, -1): |
|---|
| 92 | ext = self.ext_modules[idx] |
|---|
| 93 | if not isinstance(ext, Extension): |
|---|
| 94 | continue |
|---|
| 95 | setattr(self, ext.attr_name, None) |
|---|
| 96 | self.global_options = [ |
|---|
| 97 | (ext.option_name, None, |
|---|
| 98 | "include %s (default if %s is available)" |
|---|
| 99 | % (ext.feature_description, ext.feature_name)), |
|---|
| 100 | (ext.neg_option_name, None, |
|---|
| 101 | "exclude %s" % ext.feature_description), |
|---|
| 102 | ] + self.global_options |
|---|
| 103 | self.negative_opt = self.negative_opt.copy() |
|---|
| 104 | self.negative_opt[ext.neg_option_name] = ext.option_name |
|---|
| 105 | |
|---|
| 106 | def has_ext_modules(self): |
|---|
| 107 | if not self.ext_modules: |
|---|
| 108 | return False |
|---|
| 109 | for ext in self.ext_modules: |
|---|
| 110 | with_ext = self.ext_status(ext) |
|---|
| 111 | if with_ext is None or with_ext: |
|---|
| 112 | return True |
|---|
| 113 | return False |
|---|
| 114 | |
|---|
| 115 | def ext_status(self, ext): |
|---|
| 116 | if isinstance(ext, Extension): |
|---|
| 117 | with_ext = getattr(self, ext.attr_name) |
|---|
| 118 | return with_ext |
|---|
| 119 | else: |
|---|
| 120 | return True |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | class Extension(_Extension): |
|---|
| 124 | |
|---|
| 125 | def __init__(self, name, sources, feature_name, feature_description, |
|---|
| 126 | feature_check, **kwds): |
|---|
| 127 | if not with_pyrex: |
|---|
| 128 | for filename in sources[:]: |
|---|
| 129 | base, ext = os.path.splitext(filename) |
|---|
| 130 | if ext == '.pyx': |
|---|
| 131 | sources.remove(filename) |
|---|
| 132 | sources.append('%s.c' % base) |
|---|
| 133 | _Extension.__init__(self, name, sources, **kwds) |
|---|
| 134 | self.feature_name = feature_name |
|---|
| 135 | self.feature_description = feature_description |
|---|
| 136 | self.feature_check = feature_check |
|---|
| 137 | self.attr_name = 'with_' + feature_name.replace('-', '_') |
|---|
| 138 | self.option_name = 'with-' + feature_name |
|---|
| 139 | self.neg_option_name = 'without-' + feature_name |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | class build_ext(_build_ext): |
|---|
| 143 | |
|---|
| 144 | def run(self): |
|---|
| 145 | optional = True |
|---|
| 146 | disabled = True |
|---|
| 147 | for ext in self.extensions: |
|---|
| 148 | with_ext = self.distribution.ext_status(ext) |
|---|
| 149 | if with_ext is None: |
|---|
| 150 | disabled = False |
|---|
| 151 | elif with_ext: |
|---|
| 152 | optional = False |
|---|
| 153 | disabled = False |
|---|
| 154 | break |
|---|
| 155 | if disabled: |
|---|
| 156 | return |
|---|
| 157 | try: |
|---|
| 158 | _build_ext.run(self) |
|---|
| 159 | except DistutilsPlatformError, exc: |
|---|
| 160 | if optional: |
|---|
| 161 | log.warn(str(exc)) |
|---|
| 162 | log.warn("skipping build_ext") |
|---|
| 163 | else: |
|---|
| 164 | raise |
|---|
| 165 | |
|---|
| 166 | def get_source_files(self): |
|---|
| 167 | self.check_extensions_list(self.extensions) |
|---|
| 168 | filenames = [] |
|---|
| 169 | for ext in self.extensions: |
|---|
| 170 | if with_pyrex: |
|---|
| 171 | self.pyrex_sources(ext.sources, ext) |
|---|
| 172 | for filename in ext.sources: |
|---|
| 173 | filenames.append(filename) |
|---|
| 174 | base = os.path.splitext(filename)[0] |
|---|
| 175 | for ext in ['c', 'h', 'pyx', 'pxd']: |
|---|
| 176 | filename = '%s.%s' % (base, ext) |
|---|
| 177 | if filename not in filenames and os.path.isfile(filename): |
|---|
| 178 | filenames.append(filename) |
|---|
| 179 | return filenames |
|---|
| 180 | |
|---|
| 181 | def get_outputs(self): |
|---|
| 182 | self.check_extensions_list(self.extensions) |
|---|
| 183 | outputs = [] |
|---|
| 184 | for ext in self.extensions: |
|---|
| 185 | fullname = self.get_ext_fullname(ext.name) |
|---|
| 186 | filename = os.path.join(self.build_lib, |
|---|
| 187 | self.get_ext_filename(fullname)) |
|---|
| 188 | if os.path.isfile(filename): |
|---|
| 189 | outputs.append(filename) |
|---|
| 190 | return outputs |
|---|
| 191 | |
|---|
| 192 | def build_extensions(self): |
|---|
| 193 | self.check_extensions_list(self.extensions) |
|---|
| 194 | for ext in self.extensions: |
|---|
| 195 | with_ext = self.distribution.ext_status(ext) |
|---|
| 196 | if with_ext is None: |
|---|
| 197 | with_ext = self.check_extension_availability(ext) |
|---|
| 198 | if not with_ext: |
|---|
| 199 | continue |
|---|
| 200 | if with_pyrex: |
|---|
| 201 | ext.sources = self.pyrex_sources(ext.sources, ext) |
|---|
| 202 | self.build_extension(ext) |
|---|
| 203 | |
|---|
| 204 | def check_extension_availability(self, ext): |
|---|
| 205 | cache = os.path.join(self.build_temp, 'check_%s.out' % ext.feature_name) |
|---|
| 206 | if not self.force and os.path.isfile(cache): |
|---|
| 207 | data = open(cache).read().strip() |
|---|
| 208 | if data == '1': |
|---|
| 209 | return True |
|---|
| 210 | elif data == '0': |
|---|
| 211 | return False |
|---|
| 212 | mkpath(self.build_temp) |
|---|
| 213 | src = os.path.join(self.build_temp, 'check_%s.c' % ext.feature_name) |
|---|
| 214 | open(src, 'w').write(ext.feature_check) |
|---|
| 215 | log.info("checking if %s is compilable" % ext.feature_name) |
|---|
| 216 | try: |
|---|
| 217 | [obj] = self.compiler.compile([src], |
|---|
| 218 | macros=ext.define_macros+[(undef,) for undef in ext.undef_macros], |
|---|
| 219 | include_dirs=ext.include_dirs, |
|---|
| 220 | extra_postargs=(ext.extra_compile_args or []), |
|---|
| 221 | depends=ext.depends) |
|---|
| 222 | except CompileError: |
|---|
| 223 | log.warn("%s appears not to be installed" % ext.feature_name) |
|---|
| 224 | log.warn("(if %s is installed, you may need to specify" |
|---|
| 225 | % ext.feature_name) |
|---|
| 226 | log.warn(" the option --include-dirs or uncomment and modify") |
|---|
| 227 | log.warn(" the parameter include_dirs in setup.cfg)") |
|---|
| 228 | open(cache, 'w').write('0\n') |
|---|
| 229 | return False |
|---|
| 230 | prog = 'check_%s' % ext.feature_name |
|---|
| 231 | log.info("checking if %s is linkable" % ext.feature_name) |
|---|
| 232 | try: |
|---|
| 233 | self.compiler.link_executable([obj], prog, |
|---|
| 234 | output_dir=self.build_temp, |
|---|
| 235 | libraries=ext.libraries, |
|---|
| 236 | library_dirs=ext.library_dirs, |
|---|
| 237 | runtime_library_dirs=ext.runtime_library_dirs, |
|---|
| 238 | extra_postargs=(ext.extra_link_args or [])) |
|---|
| 239 | except LinkError: |
|---|
| 240 | log.warn("unable to link against %s" % ext.feature_name) |
|---|
| 241 | log.warn("(if %s is installed correctly, you may need to specify" |
|---|
| 242 | % ext.feature_name) |
|---|
| 243 | log.warn(" the option --library-dirs or uncomment and modify") |
|---|
| 244 | log.warn(" the parameter library_dirs in setup.cfg)") |
|---|
| 245 | open(cache, 'w').write('0\n') |
|---|
| 246 | return False |
|---|
| 247 | open(cache, 'w').write('1\n') |
|---|
| 248 | return True |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | class bdist_rpm(_bdist_rpm): |
|---|
| 252 | |
|---|
| 253 | def _make_spec_file(self): |
|---|
| 254 | argv0 = sys.argv[0] |
|---|
| 255 | features = [] |
|---|
| 256 | for ext in self.distribution.ext_modules: |
|---|
| 257 | if not isinstance(ext, Extension): |
|---|
| 258 | continue |
|---|
| 259 | with_ext = getattr(self.distribution, ext.attr_name) |
|---|
| 260 | if with_ext is None: |
|---|
| 261 | continue |
|---|
| 262 | if with_ext: |
|---|
| 263 | features.append('--'+ext.option_name) |
|---|
| 264 | else: |
|---|
| 265 | features.append('--'+ext.neg_option_name) |
|---|
| 266 | sys.argv[0] = ' '.join([argv0]+features) |
|---|
| 267 | spec_file = _bdist_rpm._make_spec_file(self) |
|---|
| 268 | sys.argv[0] = argv0 |
|---|
| 269 | return spec_file |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | class test(Command): |
|---|
| 273 | |
|---|
| 274 | user_options = [] |
|---|
| 275 | |
|---|
| 276 | def initialize_options(self): |
|---|
| 277 | pass |
|---|
| 278 | |
|---|
| 279 | def finalize_options(self): |
|---|
| 280 | pass |
|---|
| 281 | |
|---|
| 282 | def run(self): |
|---|
| 283 | build_cmd = self.get_finalized_command('build') |
|---|
| 284 | build_cmd.run() |
|---|
| 285 | sys.path.insert(0, build_cmd.build_lib) |
|---|
| 286 | sys.path.insert(0, 'tests') |
|---|
| 287 | import test_all |
|---|
| 288 | test_all.main([]) |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | if __name__ == '__main__': |
|---|
| 292 | |
|---|
| 293 | setup( |
|---|
| 294 | name=NAME, |
|---|
| 295 | version=VERSION, |
|---|
| 296 | description=DESCRIPTION, |
|---|
| 297 | long_description=LONG_DESCRIPTION, |
|---|
| 298 | author=AUTHOR, |
|---|
| 299 | author_email=AUTHOR_EMAIL, |
|---|
| 300 | license=LICENSE, |
|---|
| 301 | platforms=PLATFORMS, |
|---|
| 302 | url=URL, |
|---|
| 303 | download_url=DOWNLOAD_URL, |
|---|
| 304 | classifiers=CLASSIFIERS, |
|---|
| 305 | |
|---|
| 306 | package_dir={'': 'lib'}, |
|---|
| 307 | packages=['yaml'], |
|---|
| 308 | ext_modules=[ |
|---|
| 309 | Extension('_yaml', ['ext/_yaml.pyx'], |
|---|
| 310 | 'libyaml', "LibYAML bindings", LIBYAML_CHECK, |
|---|
| 311 | libraries=['yaml']), |
|---|
| 312 | ], |
|---|
| 313 | |
|---|
| 314 | distclass=Distribution, |
|---|
| 315 | cmdclass={ |
|---|
| 316 | 'build_ext': build_ext, |
|---|
| 317 | 'bdist_rpm': bdist_rpm, |
|---|
| 318 | 'test': test, |
|---|
| 319 | }, |
|---|
| 320 | ) |
|---|
| 321 | |
|---|