blob: 479ff04fa7c1723579480ee274ddb0443385d4ef [file] [log] [blame]
Kirill Simonov4c570fa2006-03-04 22:43:48 +00001
Kirill Simonov410d8222006-04-23 18:07:52 +00002NAME = 'PyYAML'
Kirill Simonov53b4c072016-06-15 19:26:06 -05003VERSION = '3.12'
Kirill Simonov410d8222006-04-23 18:07:52 +00004DESCRIPTION = "YAML parser and emitter for Python"
5LONG_DESCRIPTION = """\
Kirill Simonov03b28d02009-08-30 20:06:16 +00006YAML is a data serialization format designed for human readability
7and interaction with scripting languages. PyYAML is a YAML parser
8and emitter for Python.
Kirill Simonov410d8222006-04-23 18:07:52 +00009
Kirill Simonov8f22ae62006-05-07 14:36:42 +000010PyYAML features a complete YAML 1.1 parser, Unicode support, pickle
11support, capable extension API, and sensible error messages. PyYAML
Kirill Simonov03b28d02009-08-30 20:06:16 +000012supports standard YAML tags and provides Python-specific tags that
13allow to represent an arbitrary Python object.
Kirill Simonov410d8222006-04-23 18:07:52 +000014
Kirill Simonov8f22ae62006-05-07 14:36:42 +000015PyYAML is applicable for a broad range of tasks from complex
Jakub Wilkd856c202017-01-22 12:42:27 +010016configuration files to object serialization and persistence."""
Kirill Simonov4c570fa2006-03-04 22:43:48 +000017AUTHOR = "Kirill Simonov"
18AUTHOR_EMAIL = 'xi@resolvent.net'
19LICENSE = "MIT"
Kirill Simonov410d8222006-04-23 18:07:52 +000020PLATFORMS = "Any"
21URL = "http://pyyaml.org/wiki/PyYAML"
22DOWNLOAD_URL = "http://pyyaml.org/download/pyyaml/%s-%s.tar.gz" % (NAME, VERSION)
23CLASSIFIERS = [
Kirill Simonova69b98b2008-09-30 11:45:18 +000024 "Development Status :: 5 - Production/Stable",
Kirill Simonov410d8222006-04-23 18:07:52 +000025 "Intended Audience :: Developers",
26 "License :: OSI Approved :: MIT License",
27 "Operating System :: OS Independent",
28 "Programming Language :: Python",
Kirill Simonov90273932008-12-05 19:37:52 +000029 "Programming Language :: Python :: 2",
Jon Dufresne8bca3eb2017-04-16 15:02:35 -070030 "Programming Language :: Python :: 2.6",
Kirill Simonovb1c70142011-05-30 03:28:15 +000031 "Programming Language :: Python :: 2.7",
Kirill Simonov235ab982008-12-29 17:24:05 +000032 "Programming Language :: Python :: 3",
Kirill Simonov16bd7d02016-08-25 17:52:48 -050033 "Programming Language :: Python :: 3.4",
34 "Programming Language :: Python :: 3.5",
Jon Dufresne8bca3eb2017-04-16 15:02:35 -070035 "Programming Language :: Python :: 3.6",
36 "Programming Language :: Python :: Implementation :: CPython",
37 "Programming Language :: Python :: Implementation :: PyPy",
Kirill Simonov410d8222006-04-23 18:07:52 +000038 "Topic :: Software Development :: Libraries :: Python Modules",
39 "Topic :: Text Processing :: Markup",
40]
41
Kirill Simonov61e06c42008-09-30 13:29:34 +000042
Kirill Simonovc0d61332008-10-02 00:24:42 +000043LIBYAML_CHECK = """
44#include <yaml.h>
45
46int 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 Simonov16bd7d02016-08-25 17:52:48 -050061import sys, os.path, platform
Kirill Simonov9768bab2008-10-09 15:56:20 +000062
Kirill Simonovc0d61332008-10-02 00:24:42 +000063from distutils import log
Kirill Simonovbe829962008-10-01 23:16:09 +000064from distutils.core import setup, Command
65from distutils.core import Distribution as _Distribution
66from distutils.core import Extension as _Extension
Kirill Simonovc0d61332008-10-02 00:24:42 +000067from distutils.dir_util import mkpath
Kirill Simonovbe829962008-10-01 23:16:09 +000068from distutils.command.build_ext import build_ext as _build_ext
Kirill Simonov3ea3d112008-11-30 14:06:13 +000069from distutils.command.bdist_rpm import bdist_rpm as _bdist_rpm
Kirill Simonov491508b2016-06-15 20:28:10 -050070from distutils.errors import DistutilsError, CompileError, LinkError, DistutilsPlatformError
Kirill Simonovbe829962008-10-01 23:16:09 +000071
Kirill Simonov9768bab2008-10-09 15:56:20 +000072if '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 Simonova57fe5c2016-06-15 19:28:34 -050078with_cython = False
79try:
80 from Cython.Distutils.extension import Extension as _Extension
81 from Cython.Distutils import build_ext as _build_ext
82 with_cython = True
83except ImportError:
84 pass
Kirill Simonovbe829962008-10-01 23:16:09 +000085
Kirill Simonov7bd6e032016-06-16 22:32:32 -050086try:
87 from wheel.bdist_wheel import bdist_wheel
88except ImportError:
89 bdist_wheel = None
90
Kirill Simonovbe829962008-10-01 23:16:09 +000091
Kirill Simonovbe829962008-10-01 23:16:09 +000092class Distribution(_Distribution):
93
94 def __init__(self, attrs=None):
95 _Distribution.__init__(self, attrs)
96 if not self.ext_modules:
97 return
Kirill Simonovf13e4922008-10-02 02:40:48 +000098 for idx in range(len(self.ext_modules)-1, -1, -1):
99 ext = self.ext_modules[idx]
Kirill Simonovbe829962008-10-01 23:16:09 +0000100 if not isinstance(ext, Extension):
101 continue
102 setattr(self, ext.attr_name, None)
103 self.global_options = [
104 (ext.option_name, None,
Kirill Simonovc0d61332008-10-02 00:24:42 +0000105 "include %s (default if %s is available)"
106 % (ext.feature_description, ext.feature_name)),
Kirill Simonovbe829962008-10-01 23:16:09 +0000107 (ext.neg_option_name, None,
Kirill Simonovc0d61332008-10-02 00:24:42 +0000108 "exclude %s" % ext.feature_description),
Kirill Simonovbe829962008-10-01 23:16:09 +0000109 ] + self.global_options
110 self.negative_opt = self.negative_opt.copy()
111 self.negative_opt[ext.neg_option_name] = ext.option_name
112
Kirill Simonov3ea3d112008-11-30 14:06:13 +0000113 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 Simonov16bd7d02016-08-25 17:52:48 -0500123 implementation = platform.python_implementation()
124 if implementation != 'CPython':
Kirill Simonov23c952f2011-05-29 16:13:17 +0000125 return False
Kirill Simonov3ea3d112008-11-30 14:06:13 +0000126 if isinstance(ext, Extension):
127 with_ext = getattr(self, ext.attr_name)
128 return with_ext
129 else:
130 return True
131
Kirill Simonovbe829962008-10-01 23:16:09 +0000132
133class Extension(_Extension):
134
Kirill Simonovc0d61332008-10-02 00:24:42 +0000135 def __init__(self, name, sources, feature_name, feature_description,
136 feature_check, **kwds):
Kirill Simonova57fe5c2016-06-15 19:28:34 -0500137 if not with_cython:
Kirill Simonovbe829962008-10-01 23:16:09 +0000138 for filename in sources[:]:
139 base, ext = os.path.splitext(filename)
Kirill Simonovf13e4922008-10-02 02:40:48 +0000140 if ext == '.pyx':
141 sources.remove(filename)
142 sources.append('%s.c' % base)
Kirill Simonovbe829962008-10-01 23:16:09 +0000143 _Extension.__init__(self, name, sources, **kwds)
144 self.feature_name = feature_name
145 self.feature_description = feature_description
Kirill Simonovc0d61332008-10-02 00:24:42 +0000146 self.feature_check = feature_check
Kirill Simonovbe829962008-10-01 23:16:09 +0000147 self.attr_name = 'with_' + feature_name.replace('-', '_')
148 self.option_name = 'with-' + feature_name
149 self.neg_option_name = 'without-' + feature_name
150
151
152class build_ext(_build_ext):
153
Kirill Simonovf13e4922008-10-02 02:40:48 +0000154 def run(self):
155 optional = True
156 disabled = True
157 for ext in self.extensions:
Kirill Simonov3ea3d112008-11-30 14:06:13 +0000158 with_ext = self.distribution.ext_status(ext)
159 if with_ext is None:
160 disabled = False
161 elif with_ext:
Kirill Simonovf13e4922008-10-02 02:40:48 +0000162 optional = False
163 disabled = False
164 break
165 if disabled:
166 return
167 try:
168 _build_ext.run(self)
Kirill Simonov235ab982008-12-29 17:24:05 +0000169 except DistutilsPlatformError:
170 exc = sys.exc_info()[1]
Kirill Simonovf13e4922008-10-02 02:40:48 +0000171 if optional:
172 log.warn(str(exc))
173 log.warn("skipping build_ext")
174 else:
175 raise
176
Kirill Simonovbe829962008-10-01 23:16:09 +0000177 def get_source_files(self):
178 self.check_extensions_list(self.extensions)
179 filenames = []
180 for ext in self.extensions:
Kirill Simonova57fe5c2016-06-15 19:28:34 -0500181 if with_cython:
Kirill Simonov7d5f9452008-12-29 23:21:43 +0000182 self.cython_sources(ext.sources, ext)
Kirill Simonovbe829962008-10-01 23:16:09 +0000183 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 Simonov3ea3d112008-11-30 14:06:13 +0000192 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 Simonovbe829962008-10-01 23:16:09 +0000203 def build_extensions(self):
204 self.check_extensions_list(self.extensions)
205 for ext in self.extensions:
Kirill Simonov3ea3d112008-11-30 14:06:13 +0000206 with_ext = self.distribution.ext_status(ext)
Donald Stufft298e0792017-09-08 11:05:24 -0400207 if with_ext is not None and not with_ext:
Kirill Simonov3ea3d112008-11-30 14:06:13 +0000208 continue
Kirill Simonova57fe5c2016-06-15 19:28:34 -0500209 if with_cython:
Kirill Simonov7d5f9452008-12-29 23:21:43 +0000210 ext.sources = self.cython_sources(ext.sources, ext)
Donald Stufft298e0792017-09-08 11:05:24 -0400211 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 Simonovc0d61332008-10-02 00:24:42 +0000217
Kirill Simonovbe829962008-10-01 23:16:09 +0000218
Kirill Simonov3ea3d112008-11-30 14:06:13 +0000219class bdist_rpm(_bdist_rpm):
Kirill Simonovbe829962008-10-01 23:16:09 +0000220
Kirill Simonov3ea3d112008-11-30 14:06:13 +0000221 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 Simonovbe829962008-10-01 23:16:09 +0000238
Kirill Simonov4c570fa2006-03-04 22:43:48 +0000239
Kirill Simonovaff84ff2008-12-28 20:16:50 +0000240class 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 Simonov235ab982008-12-29 17:24:05 +0000254 if sys.version_info[0] < 3:
Kirill Simonovab8d9402008-12-29 19:05:11 +0000255 sys.path.insert(0, 'tests/lib')
Kirill Simonov235ab982008-12-29 17:24:05 +0000256 else:
Kirill Simonovab8d9402008-12-29 19:05:11 +0000257 sys.path.insert(0, 'tests/lib3')
Kirill Simonovaff84ff2008-12-28 20:16:50 +0000258 import test_all
Kirill Simonov491508b2016-06-15 20:28:10 -0500259 if not test_all.main([]):
260 raise DistutilsError("Tests failed")
Kirill Simonovaff84ff2008-12-28 20:16:50 +0000261
262
Kirill Simonov7bd6e032016-06-16 22:32:32 -0500263cmdclass = {
264 'build_ext': build_ext,
265 'bdist_rpm': bdist_rpm,
266 'test': test,
267}
268if bdist_wheel:
269 cmdclass['bdist_wheel'] = bdist_wheel
270
271
Kirill Simonov1710a8d2006-08-19 19:37:57 +0000272if __name__ == '__main__':
Kirill Simonov4c570fa2006-03-04 22:43:48 +0000273
Kirill Simonov7d5f9452008-12-29 23:21:43 +0000274 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 Simonova69b98b2008-09-30 11:45:18 +0000286
Kirill Simonov7d5f9452008-12-29 23:21:43 +0000287 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 Simonov235ab982008-12-29 17:24:05 +0000294
Kirill Simonov7d5f9452008-12-29 23:21:43 +0000295 distclass=Distribution,
Kirill Simonov7bd6e032016-06-16 22:32:32 -0500296 cmdclass=cmdclass,
Kirill Simonov7d5f9452008-12-29 23:21:43 +0000297 )