blob: c9c9f2a711ba89ec1ee1a1c4ea3d4a6027c92ae4 [file] [log] [blame]
Kirill Simonov4c570fa2006-03-04 22:43:48 +00001
Kirill Simonov410d8222006-04-23 18:07:52 +00002NAME = 'PyYAML'
Kirill Simonova667b612008-12-27 19:11:55 +00003VERSION = '3.07'
Kirill Simonov410d8222006-04-23 18:07:52 +00004DESCRIPTION = "YAML parser and emitter for Python"
5LONG_DESCRIPTION = """\
6YAML is a data serialization format designed for human readability and
Kirill Simonov8f22ae62006-05-07 14:36:42 +00007interaction with scripting languages. PyYAML is a YAML parser and
8emitter 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
12supports standard YAML tags and provides Python-specific tags that allow
13to 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
16configuration files to object serialization and persistance."""
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",
Kirill Simonov5d2ae6b2008-12-05 19:35:24 +000030 "Programming Language :: Python :: 2.3",
31 "Programming Language :: Python :: 2.4",
32 "Programming Language :: Python :: 2.5",
33 "Programming Language :: Python :: 2.6",
Kirill Simonov90273932008-12-05 19:37:52 +000034# Python 3.0 is not yet supported, but see http://pyyaml.org/ticket/74
35# "Programming Language :: Python :: 3",
36# "Programming Language :: Python :: 3.0",
Kirill Simonov410d8222006-04-23 18:07:52 +000037 "Topic :: Software Development :: Libraries :: Python Modules",
38 "Topic :: Text Processing :: Markup",
39]
40
Kirill Simonov61e06c42008-09-30 13:29:34 +000041
Kirill Simonovc0d61332008-10-02 00:24:42 +000042LIBYAML_CHECK = """
43#include <yaml.h>
44
45int main(void) {
46 yaml_parser_t parser;
47 yaml_emitter_t emitter;
48
49 yaml_parser_initialize(&parser);
50 yaml_parser_delete(&parser);
51
52 yaml_emitter_initialize(&emitter);
53 yaml_emitter_delete(&emitter);
54
55 return 0;
56}
57"""
58
59
Kirill Simonov9768bab2008-10-09 15:56:20 +000060import sys, os.path
61
Kirill Simonovc0d61332008-10-02 00:24:42 +000062from distutils import log
Kirill Simonovbe829962008-10-01 23:16:09 +000063from distutils.core import setup, Command
64from distutils.core import Distribution as _Distribution
65from distutils.core import Extension as _Extension
Kirill Simonovc0d61332008-10-02 00:24:42 +000066from distutils.dir_util import mkpath
Kirill Simonovbe829962008-10-01 23:16:09 +000067from distutils.command.build_ext import build_ext as _build_ext
Kirill Simonov3ea3d112008-11-30 14:06:13 +000068from distutils.command.bdist_rpm import bdist_rpm as _bdist_rpm
Kirill Simonovf13e4922008-10-02 02:40:48 +000069from distutils.errors import CompileError, LinkError, DistutilsPlatformError
Kirill Simonovbe829962008-10-01 23:16:09 +000070
Kirill Simonov9768bab2008-10-09 15:56:20 +000071if 'setuptools.extension' in sys.modules:
72 _Extension = sys.modules['setuptools.extension']._Extension
73 sys.modules['distutils.core'].Extension = _Extension
74 sys.modules['distutils.extension'].Extension = _Extension
75 sys.modules['distutils.command.build_ext'].Extension = _Extension
76
Kirill Simonovbe829962008-10-01 23:16:09 +000077try:
78 from Pyrex.Distutils import Extension as _Extension
79 from Pyrex.Distutils import build_ext as _build_ext
80 with_pyrex = True
81except ImportError:
82 with_pyrex = False
83
Kirill Simonovbe829962008-10-01 23:16:09 +000084
Kirill Simonovbe829962008-10-01 23:16:09 +000085class Distribution(_Distribution):
86
87 def __init__(self, attrs=None):
88 _Distribution.__init__(self, attrs)
89 if not self.ext_modules:
90 return
Kirill Simonovf13e4922008-10-02 02:40:48 +000091 for idx in range(len(self.ext_modules)-1, -1, -1):
92 ext = self.ext_modules[idx]
Kirill Simonovbe829962008-10-01 23:16:09 +000093 if not isinstance(ext, Extension):
94 continue
95 setattr(self, ext.attr_name, None)
96 self.global_options = [
97 (ext.option_name, None,
Kirill Simonovc0d61332008-10-02 00:24:42 +000098 "include %s (default if %s is available)"
99 % (ext.feature_description, ext.feature_name)),
Kirill Simonovbe829962008-10-01 23:16:09 +0000100 (ext.neg_option_name, None,
Kirill Simonovc0d61332008-10-02 00:24:42 +0000101 "exclude %s" % ext.feature_description),
Kirill Simonovbe829962008-10-01 23:16:09 +0000102 ] + self.global_options
103 self.negative_opt = self.negative_opt.copy()
104 self.negative_opt[ext.neg_option_name] = ext.option_name
105
Kirill Simonov3ea3d112008-11-30 14:06:13 +0000106 def has_ext_modules(self):
107 if not self.ext_modules:
108 return False
109 for ext in self.ext_modules:
110 with_ext = self.ext_status(ext)
111 if with_ext is None or with_ext:
112 return True
113 return False
114
115 def ext_status(self, ext):
116 if isinstance(ext, Extension):
117 with_ext = getattr(self, ext.attr_name)
118 return with_ext
119 else:
120 return True
121
Kirill Simonovbe829962008-10-01 23:16:09 +0000122
123class Extension(_Extension):
124
Kirill Simonovc0d61332008-10-02 00:24:42 +0000125 def __init__(self, name, sources, feature_name, feature_description,
126 feature_check, **kwds):
Kirill Simonovbe829962008-10-01 23:16:09 +0000127 if not with_pyrex:
128 for filename in sources[:]:
129 base, ext = os.path.splitext(filename)
Kirill Simonovf13e4922008-10-02 02:40:48 +0000130 if ext == '.pyx':
131 sources.remove(filename)
132 sources.append('%s.c' % base)
Kirill Simonovbe829962008-10-01 23:16:09 +0000133 _Extension.__init__(self, name, sources, **kwds)
134 self.feature_name = feature_name
135 self.feature_description = feature_description
Kirill Simonovc0d61332008-10-02 00:24:42 +0000136 self.feature_check = feature_check
Kirill Simonovbe829962008-10-01 23:16:09 +0000137 self.attr_name = 'with_' + feature_name.replace('-', '_')
138 self.option_name = 'with-' + feature_name
139 self.neg_option_name = 'without-' + feature_name
140
141
142class build_ext(_build_ext):
143
Kirill Simonovf13e4922008-10-02 02:40:48 +0000144 def run(self):
145 optional = True
146 disabled = True
147 for ext in self.extensions:
Kirill Simonov3ea3d112008-11-30 14:06:13 +0000148 with_ext = self.distribution.ext_status(ext)
149 if with_ext is None:
150 disabled = False
151 elif with_ext:
Kirill Simonovf13e4922008-10-02 02:40:48 +0000152 optional = False
153 disabled = False
154 break
155 if disabled:
156 return
157 try:
158 _build_ext.run(self)
159 except DistutilsPlatformError, exc:
160 if optional:
161 log.warn(str(exc))
162 log.warn("skipping build_ext")
163 else:
164 raise
165
Kirill Simonovbe829962008-10-01 23:16:09 +0000166 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 Simonov3ea3d112008-11-30 14:06:13 +0000181 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 Simonovbe829962008-10-01 23:16:09 +0000192 def build_extensions(self):
193 self.check_extensions_list(self.extensions)
194 for ext in self.extensions:
Kirill Simonov3ea3d112008-11-30 14:06:13 +0000195 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 Simonovbe829962008-10-01 23:16:09 +0000200 if with_pyrex:
201 ext.sources = self.pyrex_sources(ext.sources, ext)
202 self.build_extension(ext)
203
Kirill Simonovc0d61332008-10-02 00:24:42 +0000204 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 Simonov3ea3d112008-11-30 14:06:13 +0000215 log.info("checking if %s is compilable" % ext.feature_name)
Kirill Simonovc0d61332008-10-02 00:24:42 +0000216 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 Simonov1310c512008-12-28 23:34:19 +0000223 log.warn("")
224 log.warn("%s is not found or a compiler error: forcing --%s"
Kirill Simonov8e88d112008-12-28 21:42:35 +0000225 % (ext.feature_name, ext.neg_option_name))
Kirill Simonov1310c512008-12-28 23:34:19 +0000226 log.warn("(if %s is installed correctly, you may need to"
Kirill Simonovc0d61332008-10-02 00:24:42 +0000227 % ext.feature_name)
Kirill Simonov1310c512008-12-28 23:34:19 +0000228 log.warn(" specify the option --include-dirs or uncomment and")
229 log.warn(" modify the parameter include_dirs in setup.cfg)")
Kirill Simonovc0d61332008-10-02 00:24:42 +0000230 open(cache, 'w').write('0\n')
231 return False
232 prog = 'check_%s' % ext.feature_name
Kirill Simonov3ea3d112008-11-30 14:06:13 +0000233 log.info("checking if %s is linkable" % ext.feature_name)
Kirill Simonovc0d61332008-10-02 00:24:42 +0000234 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 Simonov1310c512008-12-28 23:34:19 +0000242 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 Simonovc0d61332008-10-02 00:24:42 +0000246 % ext.feature_name)
Kirill Simonov1310c512008-12-28 23:34:19 +0000247 log.warn(" specify the option --library-dirs or uncomment and")
248 log.warn(" modify the parameter library_dirs in setup.cfg)")
Kirill Simonovc0d61332008-10-02 00:24:42 +0000249 open(cache, 'w').write('0\n')
250 return False
251 open(cache, 'w').write('1\n')
252 return True
253
Kirill Simonovbe829962008-10-01 23:16:09 +0000254
Kirill Simonov3ea3d112008-11-30 14:06:13 +0000255class bdist_rpm(_bdist_rpm):
Kirill Simonovbe829962008-10-01 23:16:09 +0000256
Kirill Simonov3ea3d112008-11-30 14:06:13 +0000257 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 Simonovbe829962008-10-01 23:16:09 +0000274
Kirill Simonov4c570fa2006-03-04 22:43:48 +0000275
Kirill Simonovaff84ff2008-12-28 20:16:50 +0000276class 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)
290 sys.path.insert(0, 'tests')
291 import test_all
292 test_all.main([])
293
294
Kirill Simonov1710a8d2006-08-19 19:37:57 +0000295if __name__ == '__main__':
Kirill Simonov4c570fa2006-03-04 22:43:48 +0000296
Kirill Simonov1710a8d2006-08-19 19:37:57 +0000297 setup(
298 name=NAME,
299 version=VERSION,
300 description=DESCRIPTION,
301 long_description=LONG_DESCRIPTION,
302 author=AUTHOR,
303 author_email=AUTHOR_EMAIL,
304 license=LICENSE,
305 platforms=PLATFORMS,
306 url=URL,
307 download_url=DOWNLOAD_URL,
308 classifiers=CLASSIFIERS,
309
310 package_dir={'': 'lib'},
311 packages=['yaml'],
Kirill Simonovbe829962008-10-01 23:16:09 +0000312 ext_modules=[
Kirill Simonovf13e4922008-10-02 02:40:48 +0000313 Extension('_yaml', ['ext/_yaml.pyx'],
Kirill Simonovc0d61332008-10-02 00:24:42 +0000314 'libyaml', "LibYAML bindings", LIBYAML_CHECK,
Kirill Simonovbe829962008-10-01 23:16:09 +0000315 libraries=['yaml']),
316 ],
Kirill Simonova69b98b2008-09-30 11:45:18 +0000317
Kirill Simonovbe829962008-10-01 23:16:09 +0000318 distclass=Distribution,
319 cmdclass={
320 'build_ext': build_ext,
Kirill Simonov3ea3d112008-11-30 14:06:13 +0000321 'bdist_rpm': bdist_rpm,
Kirill Simonovaff84ff2008-12-28 20:16:50 +0000322 'test': test,
Kirill Simonova69b98b2008-09-30 11:45:18 +0000323 },
Kirill Simonov1710a8d2006-08-19 19:37:57 +0000324 )
Kirill Simonov4c570fa2006-03-04 22:43:48 +0000325