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