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