| [39] | 1 | |
|---|
| [150] | 2 | NAME = 'PyYAML' |
|---|
| [275] | 3 | VERSION = '3.06' |
|---|
| [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", |
|---|
| [306] | 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", |
|---|
| [150] | 37 | "Topic :: Software Development :: Libraries :: Python Modules", |
|---|
| 38 | "Topic :: Text Processing :: Markup", |
|---|
| 39 | ] |
|---|
| [39] | 40 | |
|---|
| [281] | 41 | |
|---|
| [292] | 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 | |
|---|
| [298] | 60 | import sys, os.path |
|---|
| 61 | |
|---|
| [292] | 62 | from distutils import log |
|---|
| [290] | 63 | from distutils.core import setup, Command |
|---|
| 64 | from distutils.core import Distribution as _Distribution |
|---|
| 65 | from distutils.core import Extension as _Extension |
|---|
| [292] | 66 | from distutils.dir_util import mkpath |
|---|
| [290] | 67 | from distutils.command.build_ext import build_ext as _build_ext |
|---|
| [301] | 68 | from distutils.command.bdist_rpm import bdist_rpm as _bdist_rpm |
|---|
| [294] | 69 | from distutils.errors import CompileError, LinkError, DistutilsPlatformError |
|---|
| [39] | 70 | |
|---|
| [298] | 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 | |
|---|
| [290] | 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 | |
|---|
| 86 | class Distribution(_Distribution): |
|---|
| 87 | |
|---|
| 88 | def __init__(self, attrs=None): |
|---|
| 89 | _Distribution.__init__(self, attrs) |
|---|
| 90 | if not self.ext_modules: |
|---|
| 91 | return |
|---|
| [294] | 92 | for idx in range(len(self.ext_modules)-1, -1, -1): |
|---|
| 93 | ext = self.ext_modules[idx] |
|---|
| [290] | 94 | if not isinstance(ext, Extension): |
|---|
| 95 | continue |
|---|
| 96 | setattr(self, ext.attr_name, None) |
|---|
| 97 | self.global_options = [ |
|---|
| 98 | (ext.option_name, None, |
|---|
| [292] | 99 | "include %s (default if %s is available)" |
|---|
| 100 | % (ext.feature_description, ext.feature_name)), |
|---|
| [290] | 101 | (ext.neg_option_name, None, |
|---|
| [292] | 102 | "exclude %s" % ext.feature_description), |
|---|
| [290] | 103 | ] + self.global_options |
|---|
| 104 | self.negative_opt = self.negative_opt.copy() |
|---|
| 105 | self.negative_opt[ext.neg_option_name] = ext.option_name |
|---|
| 106 | |
|---|
| [301] | 107 | def has_ext_modules(self): |
|---|
| 108 | if not self.ext_modules: |
|---|
| 109 | return False |
|---|
| 110 | for ext in self.ext_modules: |
|---|
| 111 | with_ext = self.ext_status(ext) |
|---|
| 112 | if with_ext is None or with_ext: |
|---|
| 113 | return True |
|---|
| 114 | return False |
|---|
| [290] | 115 | |
|---|
| [301] | 116 | def ext_status(self, ext): |
|---|
| 117 | if isinstance(ext, Extension): |
|---|
| 118 | with_ext = getattr(self, ext.attr_name) |
|---|
| 119 | return with_ext |
|---|
| 120 | else: |
|---|
| 121 | return True |
|---|
| 122 | |
|---|
| 123 | |
|---|
| [290] | 124 | class Extension(_Extension): |
|---|
| 125 | |
|---|
| [292] | 126 | def __init__(self, name, sources, feature_name, feature_description, |
|---|
| 127 | feature_check, **kwds): |
|---|
| [290] | 128 | if not with_pyrex: |
|---|
| 129 | for filename in sources[:]: |
|---|
| 130 | base, ext = os.path.splitext(filename) |
|---|
| [294] | 131 | if ext == '.pyx': |
|---|
| 132 | sources.remove(filename) |
|---|
| 133 | sources.append('%s.c' % base) |
|---|
| [290] | 134 | _Extension.__init__(self, name, sources, **kwds) |
|---|
| 135 | self.feature_name = feature_name |
|---|
| 136 | self.feature_description = feature_description |
|---|
| [292] | 137 | self.feature_check = feature_check |
|---|
| [290] | 138 | self.attr_name = 'with_' + feature_name.replace('-', '_') |
|---|
| 139 | self.option_name = 'with-' + feature_name |
|---|
| 140 | self.neg_option_name = 'without-' + feature_name |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | class build_ext(_build_ext): |
|---|
| 144 | |
|---|
| [294] | 145 | def run(self): |
|---|
| 146 | optional = True |
|---|
| 147 | disabled = True |
|---|
| 148 | for ext in self.extensions: |
|---|
| [301] | 149 | with_ext = self.distribution.ext_status(ext) |
|---|
| 150 | if with_ext is None: |
|---|
| 151 | disabled = False |
|---|
| 152 | elif with_ext: |
|---|
| [294] | 153 | optional = False |
|---|
| 154 | disabled = False |
|---|
| 155 | break |
|---|
| 156 | if disabled: |
|---|
| 157 | return |
|---|
| 158 | try: |
|---|
| 159 | _build_ext.run(self) |
|---|
| 160 | except DistutilsPlatformError, exc: |
|---|
| 161 | if optional: |
|---|
| 162 | log.warn(str(exc)) |
|---|
| 163 | log.warn("skipping build_ext") |
|---|
| 164 | else: |
|---|
| 165 | raise |
|---|
| 166 | |
|---|
| [290] | 167 | def get_source_files(self): |
|---|
| 168 | self.check_extensions_list(self.extensions) |
|---|
| 169 | filenames = [] |
|---|
| 170 | for ext in self.extensions: |
|---|
| 171 | if with_pyrex: |
|---|
| 172 | self.pyrex_sources(ext.sources, ext) |
|---|
| 173 | for filename in ext.sources: |
|---|
| 174 | filenames.append(filename) |
|---|
| 175 | base = os.path.splitext(filename)[0] |
|---|
| 176 | for ext in ['c', 'h', 'pyx', 'pxd']: |
|---|
| 177 | filename = '%s.%s' % (base, ext) |
|---|
| 178 | if filename not in filenames and os.path.isfile(filename): |
|---|
| 179 | filenames.append(filename) |
|---|
| 180 | return filenames |
|---|
| 181 | |
|---|
| [301] | 182 | def get_outputs(self): |
|---|
| 183 | self.check_extensions_list(self.extensions) |
|---|
| 184 | outputs = [] |
|---|
| 185 | for ext in self.extensions: |
|---|
| 186 | fullname = self.get_ext_fullname(ext.name) |
|---|
| 187 | filename = os.path.join(self.build_lib, |
|---|
| 188 | self.get_ext_filename(fullname)) |
|---|
| 189 | if os.path.isfile(filename): |
|---|
| 190 | outputs.append(filename) |
|---|
| 191 | return outputs |
|---|
| 192 | |
|---|
| [290] | 193 | def build_extensions(self): |
|---|
| 194 | self.check_extensions_list(self.extensions) |
|---|
| 195 | for ext in self.extensions: |
|---|
| [301] | 196 | with_ext = self.distribution.ext_status(ext) |
|---|
| 197 | if with_ext is None: |
|---|
| 198 | with_ext = self.check_extension_availability(ext) |
|---|
| 199 | if not with_ext: |
|---|
| 200 | continue |
|---|
| [290] | 201 | if with_pyrex: |
|---|
| 202 | ext.sources = self.pyrex_sources(ext.sources, ext) |
|---|
| 203 | self.build_extension(ext) |
|---|
| 204 | |
|---|
| [292] | 205 | def check_extension_availability(self, ext): |
|---|
| 206 | cache = os.path.join(self.build_temp, 'check_%s.out' % ext.feature_name) |
|---|
| 207 | if not self.force and os.path.isfile(cache): |
|---|
| 208 | data = open(cache).read().strip() |
|---|
| 209 | if data == '1': |
|---|
| 210 | return True |
|---|
| 211 | elif data == '0': |
|---|
| 212 | return False |
|---|
| 213 | mkpath(self.build_temp) |
|---|
| 214 | src = os.path.join(self.build_temp, 'check_%s.c' % ext.feature_name) |
|---|
| 215 | open(src, 'w').write(ext.feature_check) |
|---|
| [301] | 216 | log.info("checking if %s is compilable" % ext.feature_name) |
|---|
| [292] | 217 | try: |
|---|
| 218 | [obj] = self.compiler.compile([src], |
|---|
| 219 | macros=ext.define_macros+[(undef,) for undef in ext.undef_macros], |
|---|
| 220 | include_dirs=ext.include_dirs, |
|---|
| 221 | extra_postargs=(ext.extra_compile_args or []), |
|---|
| 222 | depends=ext.depends) |
|---|
| 223 | except CompileError: |
|---|
| 224 | log.warn("%s appears not to be installed" % ext.feature_name) |
|---|
| 225 | log.warn("(if %s is installed, you may need to specify" |
|---|
| 226 | % ext.feature_name) |
|---|
| 227 | log.warn(" the option --include-dirs or uncomment and modify") |
|---|
| 228 | log.warn(" the parameter include_dirs in setup.cfg)") |
|---|
| 229 | open(cache, 'w').write('0\n') |
|---|
| 230 | return False |
|---|
| 231 | prog = 'check_%s' % ext.feature_name |
|---|
| [301] | 232 | log.info("checking if %s is linkable" % ext.feature_name) |
|---|
| [292] | 233 | try: |
|---|
| 234 | self.compiler.link_executable([obj], prog, |
|---|
| 235 | output_dir=self.build_temp, |
|---|
| 236 | libraries=ext.libraries, |
|---|
| 237 | library_dirs=ext.library_dirs, |
|---|
| 238 | runtime_library_dirs=ext.runtime_library_dirs, |
|---|
| 239 | extra_postargs=(ext.extra_link_args or [])) |
|---|
| 240 | except LinkError: |
|---|
| 241 | log.warn("unable to link against %s" % ext.feature_name) |
|---|
| 242 | log.warn("(if %s is installed correctly, you may need to specify" |
|---|
| 243 | % ext.feature_name) |
|---|
| 244 | log.warn(" the option --library-dirs or uncomment and modify") |
|---|
| 245 | log.warn(" the parameter library_dirs in setup.cfg)") |
|---|
| 246 | open(cache, 'w').write('0\n') |
|---|
| 247 | return False |
|---|
| 248 | open(cache, 'w').write('1\n') |
|---|
| 249 | return True |
|---|
| [290] | 250 | |
|---|
| [292] | 251 | |
|---|
| [301] | 252 | class bdist_rpm(_bdist_rpm): |
|---|
| [290] | 253 | |
|---|
| [301] | 254 | def _make_spec_file(self): |
|---|
| 255 | argv0 = sys.argv[0] |
|---|
| 256 | features = [] |
|---|
| 257 | for ext in self.distribution.ext_modules: |
|---|
| 258 | if not isinstance(ext, Extension): |
|---|
| 259 | continue |
|---|
| 260 | with_ext = getattr(self.distribution, ext.attr_name) |
|---|
| 261 | if with_ext is None: |
|---|
| 262 | continue |
|---|
| 263 | if with_ext: |
|---|
| 264 | features.append('--'+ext.option_name) |
|---|
| 265 | else: |
|---|
| 266 | features.append('--'+ext.neg_option_name) |
|---|
| 267 | sys.argv[0] = ' '.join([argv0]+features) |
|---|
| 268 | spec_file = _bdist_rpm._make_spec_file(self) |
|---|
| 269 | sys.argv[0] = argv0 |
|---|
| 270 | return spec_file |
|---|
| [290] | 271 | |
|---|
| 272 | |
|---|
| [227] | 273 | if __name__ == '__main__': |
|---|
| [39] | 274 | |
|---|
| [227] | 275 | setup( |
|---|
| 276 | name=NAME, |
|---|
| 277 | version=VERSION, |
|---|
| 278 | description=DESCRIPTION, |
|---|
| 279 | long_description=LONG_DESCRIPTION, |
|---|
| 280 | author=AUTHOR, |
|---|
| 281 | author_email=AUTHOR_EMAIL, |
|---|
| 282 | license=LICENSE, |
|---|
| 283 | platforms=PLATFORMS, |
|---|
| 284 | url=URL, |
|---|
| 285 | download_url=DOWNLOAD_URL, |
|---|
| 286 | classifiers=CLASSIFIERS, |
|---|
| [39] | 287 | |
|---|
| [227] | 288 | package_dir={'': 'lib'}, |
|---|
| 289 | packages=['yaml'], |
|---|
| [290] | 290 | ext_modules=[ |
|---|
| [294] | 291 | Extension('_yaml', ['ext/_yaml.pyx'], |
|---|
| [292] | 292 | 'libyaml', "LibYAML bindings", LIBYAML_CHECK, |
|---|
| [290] | 293 | libraries=['yaml']), |
|---|
| 294 | ], |
|---|
| [275] | 295 | |
|---|
| [290] | 296 | distclass=Distribution, |
|---|
| 297 | cmdclass={ |
|---|
| 298 | 'build_ext': build_ext, |
|---|
| [301] | 299 | 'bdist_rpm': bdist_rpm, |
|---|
| [275] | 300 | }, |
|---|
| [227] | 301 | ) |
|---|
| 302 | |
|---|