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