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