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 | 53b4c07 | 2016-06-15 19:26:06 -0500 | [diff] [blame] | 3 | VERSION = '3.12' |
Kirill Simonov | 410d822 | 2006-04-23 18:07:52 +0000 | [diff] [blame] | 4 | DESCRIPTION = "YAML parser and emitter for Python" |
| 5 | LONG_DESCRIPTION = """\ |
Kirill Simonov | 03b28d0 | 2009-08-30 20:06:16 +0000 | [diff] [blame] | 6 | YAML is a data serialization format designed for human readability |
| 7 | and interaction with scripting languages. PyYAML is a YAML parser |
| 8 | and 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 |
Kirill Simonov | 03b28d0 | 2009-08-30 20:06:16 +0000 | [diff] [blame] | 12 | supports standard YAML tags and provides Python-specific tags that |
| 13 | allow 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 |
Jakub Wilk | d856c20 | 2017-01-22 12:42:27 +0100 | [diff] [blame] | 16 | configuration files to object serialization and persistence.""" |
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", |
Jon Dufresne | 8bca3eb | 2017-04-16 15:02:35 -0700 | [diff] [blame] | 30 | "Programming Language :: Python :: 2.6", |
Kirill Simonov | b1c7014 | 2011-05-30 03:28:15 +0000 | [diff] [blame] | 31 | "Programming Language :: Python :: 2.7", |
Kirill Simonov | 235ab98 | 2008-12-29 17:24:05 +0000 | [diff] [blame] | 32 | "Programming Language :: Python :: 3", |
Kirill Simonov | 16bd7d0 | 2016-08-25 17:52:48 -0500 | [diff] [blame] | 33 | "Programming Language :: Python :: 3.4", |
| 34 | "Programming Language :: Python :: 3.5", |
Jon Dufresne | 8bca3eb | 2017-04-16 15:02:35 -0700 | [diff] [blame] | 35 | "Programming Language :: Python :: 3.6", |
| 36 | "Programming Language :: Python :: Implementation :: CPython", |
| 37 | "Programming Language :: Python :: Implementation :: PyPy", |
Kirill Simonov | 410d822 | 2006-04-23 18:07:52 +0000 | [diff] [blame] | 38 | "Topic :: Software Development :: Libraries :: Python Modules", |
| 39 | "Topic :: Text Processing :: Markup", |
| 40 | ] |
| 41 | |
Kirill Simonov | 61e06c4 | 2008-09-30 13:29:34 +0000 | [diff] [blame] | 42 | |
Kirill Simonov | c0d6133 | 2008-10-02 00:24:42 +0000 | [diff] [blame] | 43 | LIBYAML_CHECK = """ |
| 44 | #include <yaml.h> |
| 45 | |
| 46 | int main(void) { |
| 47 | yaml_parser_t parser; |
| 48 | yaml_emitter_t emitter; |
| 49 | |
| 50 | yaml_parser_initialize(&parser); |
| 51 | yaml_parser_delete(&parser); |
| 52 | |
| 53 | yaml_emitter_initialize(&emitter); |
| 54 | yaml_emitter_delete(&emitter); |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | """ |
| 59 | |
| 60 | |
Kirill Simonov | 16bd7d0 | 2016-08-25 17:52:48 -0500 | [diff] [blame] | 61 | import sys, os.path, platform |
Kirill Simonov | 9768bab | 2008-10-09 15:56:20 +0000 | [diff] [blame] | 62 | |
Kirill Simonov | c0d6133 | 2008-10-02 00:24:42 +0000 | [diff] [blame] | 63 | from distutils import log |
Kirill Simonov | be82996 | 2008-10-01 23:16:09 +0000 | [diff] [blame] | 64 | from distutils.core import setup, Command |
| 65 | from distutils.core import Distribution as _Distribution |
| 66 | from distutils.core import Extension as _Extension |
Kirill Simonov | c0d6133 | 2008-10-02 00:24:42 +0000 | [diff] [blame] | 67 | from distutils.dir_util import mkpath |
Kirill Simonov | be82996 | 2008-10-01 23:16:09 +0000 | [diff] [blame] | 68 | from distutils.command.build_ext import build_ext as _build_ext |
Kirill Simonov | 3ea3d11 | 2008-11-30 14:06:13 +0000 | [diff] [blame] | 69 | from distutils.command.bdist_rpm import bdist_rpm as _bdist_rpm |
Kirill Simonov | 491508b | 2016-06-15 20:28:10 -0500 | [diff] [blame] | 70 | from distutils.errors import DistutilsError, CompileError, LinkError, DistutilsPlatformError |
Kirill Simonov | be82996 | 2008-10-01 23:16:09 +0000 | [diff] [blame] | 71 | |
Kirill Simonov | 9768bab | 2008-10-09 15:56:20 +0000 | [diff] [blame] | 72 | if 'setuptools.extension' in sys.modules: |
| 73 | _Extension = sys.modules['setuptools.extension']._Extension |
| 74 | sys.modules['distutils.core'].Extension = _Extension |
| 75 | sys.modules['distutils.extension'].Extension = _Extension |
| 76 | sys.modules['distutils.command.build_ext'].Extension = _Extension |
| 77 | |
Kirill Simonov | a57fe5c | 2016-06-15 19:28:34 -0500 | [diff] [blame] | 78 | with_cython = False |
| 79 | try: |
| 80 | from Cython.Distutils.extension import Extension as _Extension |
| 81 | from Cython.Distutils import build_ext as _build_ext |
| 82 | with_cython = True |
| 83 | except ImportError: |
| 84 | pass |
Kirill Simonov | be82996 | 2008-10-01 23:16:09 +0000 | [diff] [blame] | 85 | |
Kirill Simonov | 7bd6e03 | 2016-06-16 22:32:32 -0500 | [diff] [blame] | 86 | try: |
| 87 | from wheel.bdist_wheel import bdist_wheel |
| 88 | except ImportError: |
| 89 | bdist_wheel = None |
| 90 | |
Kirill Simonov | be82996 | 2008-10-01 23:16:09 +0000 | [diff] [blame] | 91 | |
Kirill Simonov | be82996 | 2008-10-01 23:16:09 +0000 | [diff] [blame] | 92 | class Distribution(_Distribution): |
| 93 | |
| 94 | def __init__(self, attrs=None): |
| 95 | _Distribution.__init__(self, attrs) |
| 96 | if not self.ext_modules: |
| 97 | return |
Kirill Simonov | f13e492 | 2008-10-02 02:40:48 +0000 | [diff] [blame] | 98 | for idx in range(len(self.ext_modules)-1, -1, -1): |
| 99 | ext = self.ext_modules[idx] |
Kirill Simonov | be82996 | 2008-10-01 23:16:09 +0000 | [diff] [blame] | 100 | if not isinstance(ext, Extension): |
| 101 | continue |
| 102 | setattr(self, ext.attr_name, None) |
| 103 | self.global_options = [ |
| 104 | (ext.option_name, None, |
Kirill Simonov | c0d6133 | 2008-10-02 00:24:42 +0000 | [diff] [blame] | 105 | "include %s (default if %s is available)" |
| 106 | % (ext.feature_description, ext.feature_name)), |
Kirill Simonov | be82996 | 2008-10-01 23:16:09 +0000 | [diff] [blame] | 107 | (ext.neg_option_name, None, |
Kirill Simonov | c0d6133 | 2008-10-02 00:24:42 +0000 | [diff] [blame] | 108 | "exclude %s" % ext.feature_description), |
Kirill Simonov | be82996 | 2008-10-01 23:16:09 +0000 | [diff] [blame] | 109 | ] + self.global_options |
| 110 | self.negative_opt = self.negative_opt.copy() |
| 111 | self.negative_opt[ext.neg_option_name] = ext.option_name |
| 112 | |
Kirill Simonov | 3ea3d11 | 2008-11-30 14:06:13 +0000 | [diff] [blame] | 113 | def has_ext_modules(self): |
| 114 | if not self.ext_modules: |
| 115 | return False |
| 116 | for ext in self.ext_modules: |
| 117 | with_ext = self.ext_status(ext) |
| 118 | if with_ext is None or with_ext: |
| 119 | return True |
| 120 | return False |
| 121 | |
| 122 | def ext_status(self, ext): |
Kirill Simonov | 16bd7d0 | 2016-08-25 17:52:48 -0500 | [diff] [blame] | 123 | implementation = platform.python_implementation() |
| 124 | if implementation != 'CPython': |
Kirill Simonov | 23c952f | 2011-05-29 16:13:17 +0000 | [diff] [blame] | 125 | return False |
Kirill Simonov | 3ea3d11 | 2008-11-30 14:06:13 +0000 | [diff] [blame] | 126 | if isinstance(ext, Extension): |
| 127 | with_ext = getattr(self, ext.attr_name) |
| 128 | return with_ext |
| 129 | else: |
| 130 | return True |
| 131 | |
Kirill Simonov | be82996 | 2008-10-01 23:16:09 +0000 | [diff] [blame] | 132 | |
| 133 | class Extension(_Extension): |
| 134 | |
Kirill Simonov | c0d6133 | 2008-10-02 00:24:42 +0000 | [diff] [blame] | 135 | def __init__(self, name, sources, feature_name, feature_description, |
| 136 | feature_check, **kwds): |
Kirill Simonov | a57fe5c | 2016-06-15 19:28:34 -0500 | [diff] [blame] | 137 | if not with_cython: |
Kirill Simonov | be82996 | 2008-10-01 23:16:09 +0000 | [diff] [blame] | 138 | for filename in sources[:]: |
| 139 | base, ext = os.path.splitext(filename) |
Kirill Simonov | f13e492 | 2008-10-02 02:40:48 +0000 | [diff] [blame] | 140 | if ext == '.pyx': |
| 141 | sources.remove(filename) |
| 142 | sources.append('%s.c' % base) |
Kirill Simonov | be82996 | 2008-10-01 23:16:09 +0000 | [diff] [blame] | 143 | _Extension.__init__(self, name, sources, **kwds) |
| 144 | self.feature_name = feature_name |
| 145 | self.feature_description = feature_description |
Kirill Simonov | c0d6133 | 2008-10-02 00:24:42 +0000 | [diff] [blame] | 146 | self.feature_check = feature_check |
Kirill Simonov | be82996 | 2008-10-01 23:16:09 +0000 | [diff] [blame] | 147 | self.attr_name = 'with_' + feature_name.replace('-', '_') |
| 148 | self.option_name = 'with-' + feature_name |
| 149 | self.neg_option_name = 'without-' + feature_name |
| 150 | |
| 151 | |
| 152 | class build_ext(_build_ext): |
| 153 | |
Kirill Simonov | f13e492 | 2008-10-02 02:40:48 +0000 | [diff] [blame] | 154 | def run(self): |
| 155 | optional = True |
| 156 | disabled = True |
| 157 | for ext in self.extensions: |
Kirill Simonov | 3ea3d11 | 2008-11-30 14:06:13 +0000 | [diff] [blame] | 158 | with_ext = self.distribution.ext_status(ext) |
| 159 | if with_ext is None: |
| 160 | disabled = False |
| 161 | elif with_ext: |
Kirill Simonov | f13e492 | 2008-10-02 02:40:48 +0000 | [diff] [blame] | 162 | optional = False |
| 163 | disabled = False |
| 164 | break |
| 165 | if disabled: |
| 166 | return |
| 167 | try: |
| 168 | _build_ext.run(self) |
Kirill Simonov | 235ab98 | 2008-12-29 17:24:05 +0000 | [diff] [blame] | 169 | except DistutilsPlatformError: |
| 170 | exc = sys.exc_info()[1] |
Kirill Simonov | f13e492 | 2008-10-02 02:40:48 +0000 | [diff] [blame] | 171 | if optional: |
| 172 | log.warn(str(exc)) |
| 173 | log.warn("skipping build_ext") |
| 174 | else: |
| 175 | raise |
| 176 | |
Kirill Simonov | be82996 | 2008-10-01 23:16:09 +0000 | [diff] [blame] | 177 | def get_source_files(self): |
| 178 | self.check_extensions_list(self.extensions) |
| 179 | filenames = [] |
| 180 | for ext in self.extensions: |
Kirill Simonov | a57fe5c | 2016-06-15 19:28:34 -0500 | [diff] [blame] | 181 | if with_cython: |
Kirill Simonov | 7d5f945 | 2008-12-29 23:21:43 +0000 | [diff] [blame] | 182 | self.cython_sources(ext.sources, ext) |
Kirill Simonov | be82996 | 2008-10-01 23:16:09 +0000 | [diff] [blame] | 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 | |
Kirill Simonov | 3ea3d11 | 2008-11-30 14:06:13 +0000 | [diff] [blame] | 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 | |
Kirill Simonov | be82996 | 2008-10-01 23:16:09 +0000 | [diff] [blame] | 203 | def build_extensions(self): |
| 204 | self.check_extensions_list(self.extensions) |
| 205 | for ext in self.extensions: |
Kirill Simonov | 3ea3d11 | 2008-11-30 14:06:13 +0000 | [diff] [blame] | 206 | with_ext = self.distribution.ext_status(ext) |
Donald Stufft | 298e079 | 2017-09-08 11:05:24 -0400 | [diff] [blame] | 207 | if with_ext is not None and not with_ext: |
Kirill Simonov | 3ea3d11 | 2008-11-30 14:06:13 +0000 | [diff] [blame] | 208 | continue |
Kirill Simonov | a57fe5c | 2016-06-15 19:28:34 -0500 | [diff] [blame] | 209 | if with_cython: |
Kirill Simonov | 7d5f945 | 2008-12-29 23:21:43 +0000 | [diff] [blame] | 210 | ext.sources = self.cython_sources(ext.sources, ext) |
Donald Stufft | 298e079 | 2017-09-08 11:05:24 -0400 | [diff] [blame] | 211 | try: |
| 212 | self.build_extension(ext) |
| 213 | except (CompileError, LinkError): |
| 214 | if with_ext is not None: |
| 215 | raise |
| 216 | log.warn("Error compiling module, falling back to pure Python") |
Kirill Simonov | c0d6133 | 2008-10-02 00:24:42 +0000 | [diff] [blame] | 217 | |
Kirill Simonov | be82996 | 2008-10-01 23:16:09 +0000 | [diff] [blame] | 218 | |
Kirill Simonov | 3ea3d11 | 2008-11-30 14:06:13 +0000 | [diff] [blame] | 219 | class bdist_rpm(_bdist_rpm): |
Kirill Simonov | be82996 | 2008-10-01 23:16:09 +0000 | [diff] [blame] | 220 | |
Kirill Simonov | 3ea3d11 | 2008-11-30 14:06:13 +0000 | [diff] [blame] | 221 | def _make_spec_file(self): |
| 222 | argv0 = sys.argv[0] |
| 223 | features = [] |
| 224 | for ext in self.distribution.ext_modules: |
| 225 | if not isinstance(ext, Extension): |
| 226 | continue |
| 227 | with_ext = getattr(self.distribution, ext.attr_name) |
| 228 | if with_ext is None: |
| 229 | continue |
| 230 | if with_ext: |
| 231 | features.append('--'+ext.option_name) |
| 232 | else: |
| 233 | features.append('--'+ext.neg_option_name) |
| 234 | sys.argv[0] = ' '.join([argv0]+features) |
| 235 | spec_file = _bdist_rpm._make_spec_file(self) |
| 236 | sys.argv[0] = argv0 |
| 237 | return spec_file |
Kirill Simonov | be82996 | 2008-10-01 23:16:09 +0000 | [diff] [blame] | 238 | |
Kirill Simonov | 4c570fa | 2006-03-04 22:43:48 +0000 | [diff] [blame] | 239 | |
Kirill Simonov | aff84ff | 2008-12-28 20:16:50 +0000 | [diff] [blame] | 240 | class test(Command): |
| 241 | |
| 242 | user_options = [] |
| 243 | |
| 244 | def initialize_options(self): |
| 245 | pass |
| 246 | |
| 247 | def finalize_options(self): |
| 248 | pass |
| 249 | |
| 250 | def run(self): |
| 251 | build_cmd = self.get_finalized_command('build') |
| 252 | build_cmd.run() |
| 253 | sys.path.insert(0, build_cmd.build_lib) |
Kirill Simonov | 235ab98 | 2008-12-29 17:24:05 +0000 | [diff] [blame] | 254 | if sys.version_info[0] < 3: |
Kirill Simonov | ab8d940 | 2008-12-29 19:05:11 +0000 | [diff] [blame] | 255 | sys.path.insert(0, 'tests/lib') |
Kirill Simonov | 235ab98 | 2008-12-29 17:24:05 +0000 | [diff] [blame] | 256 | else: |
Kirill Simonov | ab8d940 | 2008-12-29 19:05:11 +0000 | [diff] [blame] | 257 | sys.path.insert(0, 'tests/lib3') |
Kirill Simonov | aff84ff | 2008-12-28 20:16:50 +0000 | [diff] [blame] | 258 | import test_all |
Kirill Simonov | 491508b | 2016-06-15 20:28:10 -0500 | [diff] [blame] | 259 | if not test_all.main([]): |
| 260 | raise DistutilsError("Tests failed") |
Kirill Simonov | aff84ff | 2008-12-28 20:16:50 +0000 | [diff] [blame] | 261 | |
| 262 | |
Kirill Simonov | 7bd6e03 | 2016-06-16 22:32:32 -0500 | [diff] [blame] | 263 | cmdclass = { |
| 264 | 'build_ext': build_ext, |
| 265 | 'bdist_rpm': bdist_rpm, |
| 266 | 'test': test, |
| 267 | } |
| 268 | if bdist_wheel: |
| 269 | cmdclass['bdist_wheel'] = bdist_wheel |
| 270 | |
| 271 | |
Kirill Simonov | 1710a8d | 2006-08-19 19:37:57 +0000 | [diff] [blame] | 272 | if __name__ == '__main__': |
Kirill Simonov | 4c570fa | 2006-03-04 22:43:48 +0000 | [diff] [blame] | 273 | |
Kirill Simonov | 7d5f945 | 2008-12-29 23:21:43 +0000 | [diff] [blame] | 274 | setup( |
| 275 | name=NAME, |
| 276 | version=VERSION, |
| 277 | description=DESCRIPTION, |
| 278 | long_description=LONG_DESCRIPTION, |
| 279 | author=AUTHOR, |
| 280 | author_email=AUTHOR_EMAIL, |
| 281 | license=LICENSE, |
| 282 | platforms=PLATFORMS, |
| 283 | url=URL, |
| 284 | download_url=DOWNLOAD_URL, |
| 285 | classifiers=CLASSIFIERS, |
Kirill Simonov | a69b98b | 2008-09-30 11:45:18 +0000 | [diff] [blame] | 286 | |
Kirill Simonov | 7d5f945 | 2008-12-29 23:21:43 +0000 | [diff] [blame] | 287 | package_dir={'': {2: 'lib', 3: 'lib3'}[sys.version_info[0]]}, |
| 288 | packages=['yaml'], |
| 289 | ext_modules=[ |
| 290 | Extension('_yaml', ['ext/_yaml.pyx'], |
| 291 | 'libyaml', "LibYAML bindings", LIBYAML_CHECK, |
| 292 | libraries=['yaml']), |
| 293 | ], |
Kirill Simonov | 235ab98 | 2008-12-29 17:24:05 +0000 | [diff] [blame] | 294 | |
Kirill Simonov | 7d5f945 | 2008-12-29 23:21:43 +0000 | [diff] [blame] | 295 | distclass=Distribution, |
Kirill Simonov | 7bd6e03 | 2016-06-16 22:32:32 -0500 | [diff] [blame] | 296 | cmdclass=cmdclass, |
Kirill Simonov | 7d5f945 | 2008-12-29 23:21:43 +0000 | [diff] [blame] | 297 | ) |