| 1 | |
|---|
| 2 | NAME = 'PyYAML' |
|---|
| 3 | VERSION = '3.10' |
|---|
| 4 | DESCRIPTION = "YAML parser and emitter for Python" |
|---|
| 5 | LONG_DESCRIPTION = """\ |
|---|
| 6 | YAML is a data serialization format designed for human readability |
|---|
| 7 | and interaction with scripting languages. PyYAML is a YAML parser |
|---|
| 8 | and 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 |
|---|
| 13 | allow 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.5", |
|---|
| 31 | "Programming Language :: Python :: 2.6", |
|---|
| 32 | "Programming Language :: Python :: 2.7", |
|---|
| 33 | "Programming Language :: Python :: 3", |
|---|
| 34 | "Programming Language :: Python :: 3.0", |
|---|
| 35 | "Programming Language :: Python :: 3.1", |
|---|
| 36 | "Programming Language :: Python :: 3.2", |
|---|
| 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 | with_pyrex = None |
|---|
| 78 | if sys.version_info[0] < 3: |
|---|
| 79 | try: |
|---|
| 80 | from Cython.Distutils.extension import Extension as _Extension |
|---|
| 81 | from Cython.Distutils import build_ext as _build_ext |
|---|
| 82 | with_pyrex = 'cython' |
|---|
| 83 | except ImportError: |
|---|
| 84 | try: |
|---|
| 85 | # Pyrex cannot build _yaml.c at the moment, |
|---|
| 86 | # but it may get fixed eventually. |
|---|
| 87 | from Pyrex.Distutils import Extension as _Extension |
|---|
| 88 | from Pyrex.Distutils import build_ext as _build_ext |
|---|
| 89 | with_pyrex = 'pyrex' |
|---|
| 90 | except ImportError: |
|---|
| 91 | pass |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | class Distribution(_Distribution): |
|---|
| 95 | |
|---|
| 96 | def __init__(self, attrs=None): |
|---|
| 97 | _Distribution.__init__(self, attrs) |
|---|
| 98 | if not self.ext_modules: |
|---|
| 99 | return |
|---|
| 100 | for idx in range(len(self.ext_modules)-1, -1, -1): |
|---|
| 101 | ext = self.ext_modules[idx] |
|---|
| 102 | if not isinstance(ext, Extension): |
|---|
| 103 | continue |
|---|
| 104 | setattr(self, ext.attr_name, None) |
|---|
| 105 | self.global_options = [ |
|---|
| 106 | (ext.option_name, None, |
|---|
| 107 | "include %s (default if %s is available)" |
|---|
| 108 | % (ext.feature_description, ext.feature_name)), |
|---|
| 109 | (ext.neg_option_name, None, |
|---|
| 110 | "exclude %s" % ext.feature_description), |
|---|
| 111 | ] + self.global_options |
|---|
| 112 | self.negative_opt = self.negative_opt.copy() |
|---|
| 113 | self.negative_opt[ext.neg_option_name] = ext.option_name |
|---|
| 114 | |
|---|
| 115 | def has_ext_modules(self): |
|---|
| 116 | if not self.ext_modules: |
|---|
| 117 | return False |
|---|
| 118 | for ext in self.ext_modules: |
|---|
| 119 | with_ext = self.ext_status(ext) |
|---|
| 120 | if with_ext is None or with_ext: |
|---|
| 121 | return True |
|---|
| 122 | return False |
|---|
| 123 | |
|---|
| 124 | def ext_status(self, ext): |
|---|
| 125 | if 'Java' in sys.version or 'IronPython' in sys.version or 'PyPy' in sys.version: |
|---|
| 126 | return False |
|---|
| 127 | if isinstance(ext, Extension): |
|---|
| 128 | with_ext = getattr(self, ext.attr_name) |
|---|
| 129 | return with_ext |
|---|
| 130 | else: |
|---|
| 131 | return True |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | class Extension(_Extension): |
|---|
| 135 | |
|---|
| 136 | def __init__(self, name, sources, feature_name, feature_description, |
|---|
| 137 | feature_check, **kwds): |
|---|
| 138 | if not with_pyrex: |
|---|
| 139 | for filename in sources[:]: |
|---|
| 140 | base, ext = os.path.splitext(filename) |
|---|
| 141 | if ext == '.pyx': |
|---|
| 142 | sources.remove(filename) |
|---|
| 143 | sources.append('%s.c' % base) |
|---|
| 144 | _Extension.__init__(self, name, sources, **kwds) |
|---|
| 145 | self.feature_name = feature_name |
|---|
| 146 | self.feature_description = feature_description |
|---|
| 147 | self.feature_check = feature_check |
|---|
| 148 | self.attr_name = 'with_' + feature_name.replace('-', '_') |
|---|
| 149 | self.option_name = 'with-' + feature_name |
|---|
| 150 | self.neg_option_name = 'without-' + feature_name |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | class build_ext(_build_ext): |
|---|
| 154 | |
|---|
| 155 | def run(self): |
|---|
| 156 | optional = True |
|---|
| 157 | disabled = True |
|---|
| 158 | for ext in self.extensions: |
|---|
| 159 | with_ext = self.distribution.ext_status(ext) |
|---|
| 160 | if with_ext is None: |
|---|
| 161 | disabled = False |
|---|
| 162 | elif with_ext: |
|---|
| 163 | optional = False |
|---|
| 164 | disabled = False |
|---|
| 165 | break |
|---|
| 166 | if disabled: |
|---|
| 167 | return |
|---|
| 168 | try: |
|---|
| 169 | _build_ext.run(self) |
|---|
| 170 | except DistutilsPlatformError: |
|---|
| 171 | exc = sys.exc_info()[1] |
|---|
| 172 | if optional: |
|---|
| 173 | log.warn(str(exc)) |
|---|
| 174 | log.warn("skipping build_ext") |
|---|
| 175 | else: |
|---|
| 176 | raise |
|---|
| 177 | |
|---|
| 178 | def get_source_files(self): |
|---|
| 179 | self.check_extensions_list(self.extensions) |
|---|
| 180 | filenames = [] |
|---|
| 181 | for ext in self.extensions: |
|---|
| 182 | if with_pyrex == 'pyrex': |
|---|
| 183 | self.pyrex_sources(ext.sources, ext) |
|---|
| 184 | elif with_pyrex == 'cython': |
|---|
| 185 | self.cython_sources(ext.sources, ext) |
|---|
| 186 | for filename in ext.sources: |
|---|
| 187 | filenames.append(filename) |
|---|
| 188 | base = os.path.splitext(filename)[0] |
|---|
| 189 | for ext in ['c', 'h', 'pyx', 'pxd']: |
|---|
| 190 | filename = '%s.%s' % (base, ext) |
|---|
| 191 | if filename not in filenames and os.path.isfile(filename): |
|---|
| 192 | filenames.append(filename) |
|---|
| 193 | return filenames |
|---|
| 194 | |
|---|
| 195 | def get_outputs(self): |
|---|
| 196 | self.check_extensions_list(self.extensions) |
|---|
| 197 | outputs = [] |
|---|
| 198 | for ext in self.extensions: |
|---|
| 199 | fullname = self.get_ext_fullname(ext.name) |
|---|
| 200 | filename = os.path.join(self.build_lib, |
|---|
| 201 | self.get_ext_filename(fullname)) |
|---|
| 202 | if os.path.isfile(filename): |
|---|
| 203 | outputs.append(filename) |
|---|
| 204 | return outputs |
|---|
| 205 | |
|---|
| 206 | def build_extensions(self): |
|---|
| 207 | self.check_extensions_list(self.extensions) |
|---|
| 208 | for ext in self.extensions: |
|---|
| 209 | with_ext = self.distribution.ext_status(ext) |
|---|
| 210 | if with_ext is None: |
|---|
| 211 | with_ext = self.check_extension_availability(ext) |
|---|
| 212 | if not with_ext: |
|---|
| 213 | continue |
|---|
| 214 | if with_pyrex == 'pyrex': |
|---|
| 215 | ext.sources = self.pyrex_sources(ext.sources, ext) |
|---|
| 216 | elif with_pyrex == 'cython': |
|---|
| 217 | ext.sources = self.cython_sources(ext.sources, ext) |
|---|
| 218 | self.build_extension(ext) |
|---|
| 219 | |
|---|
| 220 | def check_extension_availability(self, ext): |
|---|
| 221 | cache = os.path.join(self.build_temp, 'check_%s.out' % ext.feature_name) |
|---|
| 222 | if not self.force and os.path.isfile(cache): |
|---|
| 223 | data = open(cache).read().strip() |
|---|
| 224 | if data == '1': |
|---|
| 225 | return True |
|---|
| 226 | elif data == '0': |
|---|
| 227 | return False |
|---|
| 228 | mkpath(self.build_temp) |
|---|
| 229 | src = os.path.join(self.build_temp, 'check_%s.c' % ext.feature_name) |
|---|
| 230 | open(src, 'w').write(ext.feature_check) |
|---|
| 231 | log.info("checking if %s is compilable" % ext.feature_name) |
|---|
| 232 | try: |
|---|
| 233 | [obj] = self.compiler.compile([src], |
|---|
| 234 | macros=ext.define_macros+[(undef,) for undef in ext.undef_macros], |
|---|
| 235 | include_dirs=ext.include_dirs, |
|---|
| 236 | extra_postargs=(ext.extra_compile_args or []), |
|---|
| 237 | depends=ext.depends) |
|---|
| 238 | except CompileError: |
|---|
| 239 | log.warn("") |
|---|
| 240 | log.warn("%s is not found or a compiler error: forcing --%s" |
|---|
| 241 | % (ext.feature_name, ext.neg_option_name)) |
|---|
| 242 | log.warn("(if %s is installed correctly, you may need to" |
|---|
| 243 | % ext.feature_name) |
|---|
| 244 | log.warn(" specify the option --include-dirs or uncomment and") |
|---|
| 245 | log.warn(" modify the parameter include_dirs in setup.cfg)") |
|---|
| 246 | open(cache, 'w').write('0\n') |
|---|
| 247 | return False |
|---|
| 248 | prog = 'check_%s' % ext.feature_name |
|---|
| 249 | log.info("checking if %s is linkable" % ext.feature_name) |
|---|
| 250 | try: |
|---|
| 251 | self.compiler.link_executable([obj], prog, |
|---|
| 252 | output_dir=self.build_temp, |
|---|
| 253 | libraries=ext.libraries, |
|---|
| 254 | library_dirs=ext.library_dirs, |
|---|
| 255 | runtime_library_dirs=ext.runtime_library_dirs, |
|---|
| 256 | extra_postargs=(ext.extra_link_args or [])) |
|---|
| 257 | except LinkError: |
|---|
| 258 | log.warn("") |
|---|
| 259 | log.warn("%s is not found or a linker error: forcing --%s" |
|---|
| 260 | % (ext.feature_name, ext.neg_option_name)) |
|---|
| 261 | log.warn("(if %s is installed correctly, you may need to" |
|---|
| 262 | % ext.feature_name) |
|---|
| 263 | log.warn(" specify the option --library-dirs or uncomment and") |
|---|
| 264 | log.warn(" modify the parameter library_dirs in setup.cfg)") |
|---|
| 265 | open(cache, 'w').write('0\n') |
|---|
| 266 | return False |
|---|
| 267 | open(cache, 'w').write('1\n') |
|---|
| 268 | return True |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | class bdist_rpm(_bdist_rpm): |
|---|
| 272 | |
|---|
| 273 | def _make_spec_file(self): |
|---|
| 274 | argv0 = sys.argv[0] |
|---|
| 275 | features = [] |
|---|
| 276 | for ext in self.distribution.ext_modules: |
|---|
| 277 | if not isinstance(ext, Extension): |
|---|
| 278 | continue |
|---|
| 279 | with_ext = getattr(self.distribution, ext.attr_name) |
|---|
| 280 | if with_ext is None: |
|---|
| 281 | continue |
|---|
| 282 | if with_ext: |
|---|
| 283 | features.append('--'+ext.option_name) |
|---|
| 284 | else: |
|---|
| 285 | features.append('--'+ext.neg_option_name) |
|---|
| 286 | sys.argv[0] = ' '.join([argv0]+features) |
|---|
| 287 | spec_file = _bdist_rpm._make_spec_file(self) |
|---|
| 288 | sys.argv[0] = argv0 |
|---|
| 289 | return spec_file |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | class test(Command): |
|---|
| 293 | |
|---|
| 294 | user_options = [] |
|---|
| 295 | |
|---|
| 296 | def initialize_options(self): |
|---|
| 297 | pass |
|---|
| 298 | |
|---|
| 299 | def finalize_options(self): |
|---|
| 300 | pass |
|---|
| 301 | |
|---|
| 302 | def run(self): |
|---|
| 303 | build_cmd = self.get_finalized_command('build') |
|---|
| 304 | build_cmd.run() |
|---|
| 305 | sys.path.insert(0, build_cmd.build_lib) |
|---|
| 306 | if sys.version_info[0] < 3: |
|---|
| 307 | sys.path.insert(0, 'tests/lib') |
|---|
| 308 | else: |
|---|
| 309 | sys.path.insert(0, 'tests/lib3') |
|---|
| 310 | import test_all |
|---|
| 311 | test_all.main([]) |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | if __name__ == '__main__': |
|---|
| 315 | |
|---|
| 316 | setup( |
|---|
| 317 | name=NAME, |
|---|
| 318 | version=VERSION, |
|---|
| 319 | description=DESCRIPTION, |
|---|
| 320 | long_description=LONG_DESCRIPTION, |
|---|
| 321 | author=AUTHOR, |
|---|
| 322 | author_email=AUTHOR_EMAIL, |
|---|
| 323 | license=LICENSE, |
|---|
| 324 | platforms=PLATFORMS, |
|---|
| 325 | url=URL, |
|---|
| 326 | download_url=DOWNLOAD_URL, |
|---|
| 327 | classifiers=CLASSIFIERS, |
|---|
| 328 | |
|---|
| 329 | package_dir={'': {2: 'lib', 3: 'lib3'}[sys.version_info[0]]}, |
|---|
| 330 | packages=['yaml'], |
|---|
| 331 | ext_modules=[ |
|---|
| 332 | Extension('_yaml', ['ext/_yaml.pyx'], |
|---|
| 333 | 'libyaml', "LibYAML bindings", LIBYAML_CHECK, |
|---|
| 334 | libraries=['yaml']), |
|---|
| 335 | ], |
|---|
| 336 | |
|---|
| 337 | distclass=Distribution, |
|---|
| 338 | |
|---|
| 339 | cmdclass={ |
|---|
| 340 | 'build_ext': build_ext, |
|---|
| 341 | 'bdist_rpm': bdist_rpm, |
|---|
| 342 | 'test': test, |
|---|
| 343 | }, |
|---|
| 344 | ) |
|---|
| 345 | |
|---|