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