2006-03-04 22:43:48 +00:00
|
|
|
|
2006-04-23 18:07:52 +00:00
|
|
|
NAME = 'PyYAML'
|
2016-06-16 00:26:06 +00:00
|
|
|
VERSION = '3.12'
|
2006-04-23 18:07:52 +00:00
|
|
|
DESCRIPTION = "YAML parser and emitter for Python"
|
|
|
|
LONG_DESCRIPTION = """\
|
2009-08-30 20:06:16 +00:00
|
|
|
YAML is a data serialization format designed for human readability
|
|
|
|
and interaction with scripting languages. PyYAML is a YAML parser
|
|
|
|
and emitter for Python.
|
2006-04-23 18:07:52 +00:00
|
|
|
|
2006-05-07 14:36:42 +00:00
|
|
|
PyYAML features a complete YAML 1.1 parser, Unicode support, pickle
|
|
|
|
support, capable extension API, and sensible error messages. PyYAML
|
2009-08-30 20:06:16 +00:00
|
|
|
supports standard YAML tags and provides Python-specific tags that
|
|
|
|
allow to represent an arbitrary Python object.
|
2006-04-23 18:07:52 +00:00
|
|
|
|
2006-05-07 14:36:42 +00:00
|
|
|
PyYAML is applicable for a broad range of tasks from complex
|
|
|
|
configuration files to object serialization and persistance."""
|
2006-03-04 22:43:48 +00:00
|
|
|
AUTHOR = "Kirill Simonov"
|
|
|
|
AUTHOR_EMAIL = 'xi@resolvent.net'
|
|
|
|
LICENSE = "MIT"
|
2006-04-23 18:07:52 +00:00
|
|
|
PLATFORMS = "Any"
|
|
|
|
URL = "http://pyyaml.org/wiki/PyYAML"
|
|
|
|
DOWNLOAD_URL = "http://pyyaml.org/download/pyyaml/%s-%s.tar.gz" % (NAME, VERSION)
|
|
|
|
CLASSIFIERS = [
|
2008-09-30 11:45:18 +00:00
|
|
|
"Development Status :: 5 - Production/Stable",
|
2006-04-23 18:07:52 +00:00
|
|
|
"Intended Audience :: Developers",
|
|
|
|
"License :: OSI Approved :: MIT License",
|
|
|
|
"Operating System :: OS Independent",
|
|
|
|
"Programming Language :: Python",
|
2008-12-05 19:37:52 +00:00
|
|
|
"Programming Language :: Python :: 2",
|
2017-04-16 22:02:35 +00:00
|
|
|
"Programming Language :: Python :: 2.6",
|
2011-05-30 03:28:15 +00:00
|
|
|
"Programming Language :: Python :: 2.7",
|
2008-12-29 17:24:05 +00:00
|
|
|
"Programming Language :: Python :: 3",
|
2016-08-25 22:52:48 +00:00
|
|
|
"Programming Language :: Python :: 3.4",
|
|
|
|
"Programming Language :: Python :: 3.5",
|
2017-04-16 22:02:35 +00:00
|
|
|
"Programming Language :: Python :: 3.6",
|
|
|
|
"Programming Language :: Python :: Implementation :: CPython",
|
|
|
|
"Programming Language :: Python :: Implementation :: PyPy",
|
2006-04-23 18:07:52 +00:00
|
|
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
|
|
"Topic :: Text Processing :: Markup",
|
|
|
|
]
|
|
|
|
|
2008-09-30 13:29:34 +00:00
|
|
|
|
2008-10-02 00:24:42 +00:00
|
|
|
LIBYAML_CHECK = """
|
|
|
|
#include <yaml.h>
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
yaml_parser_t parser;
|
|
|
|
yaml_emitter_t emitter;
|
|
|
|
|
|
|
|
yaml_parser_initialize(&parser);
|
|
|
|
yaml_parser_delete(&parser);
|
|
|
|
|
|
|
|
yaml_emitter_initialize(&emitter);
|
|
|
|
yaml_emitter_delete(&emitter);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2016-08-25 22:52:48 +00:00
|
|
|
import sys, os.path, platform
|
2008-10-09 15:56:20 +00:00
|
|
|
|
2008-10-02 00:24:42 +00:00
|
|
|
from distutils import log
|
2008-10-01 23:16:09 +00:00
|
|
|
from distutils.core import setup, Command
|
|
|
|
from distutils.core import Distribution as _Distribution
|
|
|
|
from distutils.core import Extension as _Extension
|
2008-10-02 00:24:42 +00:00
|
|
|
from distutils.dir_util import mkpath
|
2008-10-01 23:16:09 +00:00
|
|
|
from distutils.command.build_ext import build_ext as _build_ext
|
2008-11-30 14:06:13 +00:00
|
|
|
from distutils.command.bdist_rpm import bdist_rpm as _bdist_rpm
|
2016-06-16 01:28:10 +00:00
|
|
|
from distutils.errors import DistutilsError, CompileError, LinkError, DistutilsPlatformError
|
2008-10-01 23:16:09 +00:00
|
|
|
|
2008-10-09 15:56:20 +00:00
|
|
|
if 'setuptools.extension' in sys.modules:
|
|
|
|
_Extension = sys.modules['setuptools.extension']._Extension
|
|
|
|
sys.modules['distutils.core'].Extension = _Extension
|
|
|
|
sys.modules['distutils.extension'].Extension = _Extension
|
|
|
|
sys.modules['distutils.command.build_ext'].Extension = _Extension
|
|
|
|
|
2016-06-16 00:28:34 +00:00
|
|
|
with_cython = False
|
|
|
|
try:
|
|
|
|
from Cython.Distutils.extension import Extension as _Extension
|
|
|
|
from Cython.Distutils import build_ext as _build_ext
|
|
|
|
with_cython = True
|
|
|
|
except ImportError:
|
|
|
|
pass
|
2008-10-01 23:16:09 +00:00
|
|
|
|
2016-06-17 03:32:32 +00:00
|
|
|
try:
|
|
|
|
from wheel.bdist_wheel import bdist_wheel
|
|
|
|
except ImportError:
|
|
|
|
bdist_wheel = None
|
|
|
|
|
2008-10-01 23:16:09 +00:00
|
|
|
|
|
|
|
class Distribution(_Distribution):
|
|
|
|
|
|
|
|
def __init__(self, attrs=None):
|
|
|
|
_Distribution.__init__(self, attrs)
|
|
|
|
if not self.ext_modules:
|
|
|
|
return
|
2008-10-02 02:40:48 +00:00
|
|
|
for idx in range(len(self.ext_modules)-1, -1, -1):
|
|
|
|
ext = self.ext_modules[idx]
|
2008-10-01 23:16:09 +00:00
|
|
|
if not isinstance(ext, Extension):
|
|
|
|
continue
|
|
|
|
setattr(self, ext.attr_name, None)
|
|
|
|
self.global_options = [
|
|
|
|
(ext.option_name, None,
|
2008-10-02 00:24:42 +00:00
|
|
|
"include %s (default if %s is available)"
|
|
|
|
% (ext.feature_description, ext.feature_name)),
|
2008-10-01 23:16:09 +00:00
|
|
|
(ext.neg_option_name, None,
|
2008-10-02 00:24:42 +00:00
|
|
|
"exclude %s" % ext.feature_description),
|
2008-10-01 23:16:09 +00:00
|
|
|
] + self.global_options
|
|
|
|
self.negative_opt = self.negative_opt.copy()
|
|
|
|
self.negative_opt[ext.neg_option_name] = ext.option_name
|
|
|
|
|
2008-11-30 14:06:13 +00:00
|
|
|
def has_ext_modules(self):
|
|
|
|
if not self.ext_modules:
|
|
|
|
return False
|
|
|
|
for ext in self.ext_modules:
|
|
|
|
with_ext = self.ext_status(ext)
|
|
|
|
if with_ext is None or with_ext:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def ext_status(self, ext):
|
2016-08-25 22:52:48 +00:00
|
|
|
implementation = platform.python_implementation()
|
|
|
|
if implementation != 'CPython':
|
2011-05-29 16:13:17 +00:00
|
|
|
return False
|
2008-11-30 14:06:13 +00:00
|
|
|
if isinstance(ext, Extension):
|
|
|
|
with_ext = getattr(self, ext.attr_name)
|
|
|
|
return with_ext
|
|
|
|
else:
|
|
|
|
return True
|
|
|
|
|
2008-10-01 23:16:09 +00:00
|
|
|
|
|
|
|
class Extension(_Extension):
|
|
|
|
|
2008-10-02 00:24:42 +00:00
|
|
|
def __init__(self, name, sources, feature_name, feature_description,
|
|
|
|
feature_check, **kwds):
|
2016-06-16 00:28:34 +00:00
|
|
|
if not with_cython:
|
2008-10-01 23:16:09 +00:00
|
|
|
for filename in sources[:]:
|
|
|
|
base, ext = os.path.splitext(filename)
|
2008-10-02 02:40:48 +00:00
|
|
|
if ext == '.pyx':
|
|
|
|
sources.remove(filename)
|
|
|
|
sources.append('%s.c' % base)
|
2008-10-01 23:16:09 +00:00
|
|
|
_Extension.__init__(self, name, sources, **kwds)
|
|
|
|
self.feature_name = feature_name
|
|
|
|
self.feature_description = feature_description
|
2008-10-02 00:24:42 +00:00
|
|
|
self.feature_check = feature_check
|
2008-10-01 23:16:09 +00:00
|
|
|
self.attr_name = 'with_' + feature_name.replace('-', '_')
|
|
|
|
self.option_name = 'with-' + feature_name
|
|
|
|
self.neg_option_name = 'without-' + feature_name
|
|
|
|
|
|
|
|
|
|
|
|
class build_ext(_build_ext):
|
|
|
|
|
2008-10-02 02:40:48 +00:00
|
|
|
def run(self):
|
|
|
|
optional = True
|
|
|
|
disabled = True
|
|
|
|
for ext in self.extensions:
|
2008-11-30 14:06:13 +00:00
|
|
|
with_ext = self.distribution.ext_status(ext)
|
|
|
|
if with_ext is None:
|
|
|
|
disabled = False
|
|
|
|
elif with_ext:
|
2008-10-02 02:40:48 +00:00
|
|
|
optional = False
|
|
|
|
disabled = False
|
|
|
|
break
|
|
|
|
if disabled:
|
|
|
|
return
|
|
|
|
try:
|
|
|
|
_build_ext.run(self)
|
2008-12-29 17:24:05 +00:00
|
|
|
except DistutilsPlatformError:
|
|
|
|
exc = sys.exc_info()[1]
|
2008-10-02 02:40:48 +00:00
|
|
|
if optional:
|
|
|
|
log.warn(str(exc))
|
|
|
|
log.warn("skipping build_ext")
|
|
|
|
else:
|
|
|
|
raise
|
|
|
|
|
2008-10-01 23:16:09 +00:00
|
|
|
def get_source_files(self):
|
|
|
|
self.check_extensions_list(self.extensions)
|
|
|
|
filenames = []
|
|
|
|
for ext in self.extensions:
|
2016-06-16 00:28:34 +00:00
|
|
|
if with_cython:
|
2008-12-29 23:21:43 +00:00
|
|
|
self.cython_sources(ext.sources, ext)
|
2008-10-01 23:16:09 +00:00
|
|
|
for filename in ext.sources:
|
|
|
|
filenames.append(filename)
|
|
|
|
base = os.path.splitext(filename)[0]
|
|
|
|
for ext in ['c', 'h', 'pyx', 'pxd']:
|
|
|
|
filename = '%s.%s' % (base, ext)
|
|
|
|
if filename not in filenames and os.path.isfile(filename):
|
|
|
|
filenames.append(filename)
|
|
|
|
return filenames
|
|
|
|
|
2008-11-30 14:06:13 +00:00
|
|
|
def get_outputs(self):
|
|
|
|
self.check_extensions_list(self.extensions)
|
|
|
|
outputs = []
|
|
|
|
for ext in self.extensions:
|
|
|
|
fullname = self.get_ext_fullname(ext.name)
|
|
|
|
filename = os.path.join(self.build_lib,
|
|
|
|
self.get_ext_filename(fullname))
|
|
|
|
if os.path.isfile(filename):
|
|
|
|
outputs.append(filename)
|
|
|
|
return outputs
|
|
|
|
|
2008-10-01 23:16:09 +00:00
|
|
|
def build_extensions(self):
|
|
|
|
self.check_extensions_list(self.extensions)
|
|
|
|
for ext in self.extensions:
|
2008-11-30 14:06:13 +00:00
|
|
|
with_ext = self.distribution.ext_status(ext)
|
|
|
|
if with_ext is None:
|
|
|
|
with_ext = self.check_extension_availability(ext)
|
|
|
|
if not with_ext:
|
|
|
|
continue
|
2016-06-16 00:28:34 +00:00
|
|
|
if with_cython:
|
2008-12-29 23:21:43 +00:00
|
|
|
ext.sources = self.cython_sources(ext.sources, ext)
|
2008-10-01 23:16:09 +00:00
|
|
|
self.build_extension(ext)
|
|
|
|
|
2008-10-02 00:24:42 +00:00
|
|
|
def check_extension_availability(self, ext):
|
|
|
|
cache = os.path.join(self.build_temp, 'check_%s.out' % ext.feature_name)
|
|
|
|
if not self.force and os.path.isfile(cache):
|
|
|
|
data = open(cache).read().strip()
|
|
|
|
if data == '1':
|
|
|
|
return True
|
|
|
|
elif data == '0':
|
|
|
|
return False
|
|
|
|
mkpath(self.build_temp)
|
|
|
|
src = os.path.join(self.build_temp, 'check_%s.c' % ext.feature_name)
|
|
|
|
open(src, 'w').write(ext.feature_check)
|
2008-11-30 14:06:13 +00:00
|
|
|
log.info("checking if %s is compilable" % ext.feature_name)
|
2008-10-02 00:24:42 +00:00
|
|
|
try:
|
|
|
|
[obj] = self.compiler.compile([src],
|
|
|
|
macros=ext.define_macros+[(undef,) for undef in ext.undef_macros],
|
|
|
|
include_dirs=ext.include_dirs,
|
|
|
|
extra_postargs=(ext.extra_compile_args or []),
|
|
|
|
depends=ext.depends)
|
|
|
|
except CompileError:
|
2008-12-28 23:34:19 +00:00
|
|
|
log.warn("")
|
|
|
|
log.warn("%s is not found or a compiler error: forcing --%s"
|
2008-12-28 21:42:35 +00:00
|
|
|
% (ext.feature_name, ext.neg_option_name))
|
2008-12-28 23:34:19 +00:00
|
|
|
log.warn("(if %s is installed correctly, you may need to"
|
2008-10-02 00:24:42 +00:00
|
|
|
% ext.feature_name)
|
2008-12-28 23:34:19 +00:00
|
|
|
log.warn(" specify the option --include-dirs or uncomment and")
|
|
|
|
log.warn(" modify the parameter include_dirs in setup.cfg)")
|
2008-10-02 00:24:42 +00:00
|
|
|
open(cache, 'w').write('0\n')
|
|
|
|
return False
|
|
|
|
prog = 'check_%s' % ext.feature_name
|
2008-11-30 14:06:13 +00:00
|
|
|
log.info("checking if %s is linkable" % ext.feature_name)
|
2008-10-02 00:24:42 +00:00
|
|
|
try:
|
|
|
|
self.compiler.link_executable([obj], prog,
|
|
|
|
output_dir=self.build_temp,
|
|
|
|
libraries=ext.libraries,
|
|
|
|
library_dirs=ext.library_dirs,
|
|
|
|
runtime_library_dirs=ext.runtime_library_dirs,
|
|
|
|
extra_postargs=(ext.extra_link_args or []))
|
|
|
|
except LinkError:
|
2008-12-28 23:34:19 +00:00
|
|
|
log.warn("")
|
|
|
|
log.warn("%s is not found or a linker error: forcing --%s"
|
|
|
|
% (ext.feature_name, ext.neg_option_name))
|
|
|
|
log.warn("(if %s is installed correctly, you may need to"
|
2008-10-02 00:24:42 +00:00
|
|
|
% ext.feature_name)
|
2008-12-28 23:34:19 +00:00
|
|
|
log.warn(" specify the option --library-dirs or uncomment and")
|
|
|
|
log.warn(" modify the parameter library_dirs in setup.cfg)")
|
2008-10-02 00:24:42 +00:00
|
|
|
open(cache, 'w').write('0\n')
|
|
|
|
return False
|
|
|
|
open(cache, 'w').write('1\n')
|
|
|
|
return True
|
|
|
|
|
2008-10-01 23:16:09 +00:00
|
|
|
|
2008-11-30 14:06:13 +00:00
|
|
|
class bdist_rpm(_bdist_rpm):
|
2008-10-01 23:16:09 +00:00
|
|
|
|
2008-11-30 14:06:13 +00:00
|
|
|
def _make_spec_file(self):
|
|
|
|
argv0 = sys.argv[0]
|
|
|
|
features = []
|
|
|
|
for ext in self.distribution.ext_modules:
|
|
|
|
if not isinstance(ext, Extension):
|
|
|
|
continue
|
|
|
|
with_ext = getattr(self.distribution, ext.attr_name)
|
|
|
|
if with_ext is None:
|
|
|
|
continue
|
|
|
|
if with_ext:
|
|
|
|
features.append('--'+ext.option_name)
|
|
|
|
else:
|
|
|
|
features.append('--'+ext.neg_option_name)
|
|
|
|
sys.argv[0] = ' '.join([argv0]+features)
|
|
|
|
spec_file = _bdist_rpm._make_spec_file(self)
|
|
|
|
sys.argv[0] = argv0
|
|
|
|
return spec_file
|
2008-10-01 23:16:09 +00:00
|
|
|
|
2006-03-04 22:43:48 +00:00
|
|
|
|
2008-12-28 20:16:50 +00:00
|
|
|
class test(Command):
|
|
|
|
|
|
|
|
user_options = []
|
|
|
|
|
|
|
|
def initialize_options(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def finalize_options(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
build_cmd = self.get_finalized_command('build')
|
|
|
|
build_cmd.run()
|
|
|
|
sys.path.insert(0, build_cmd.build_lib)
|
2008-12-29 17:24:05 +00:00
|
|
|
if sys.version_info[0] < 3:
|
2008-12-29 19:05:11 +00:00
|
|
|
sys.path.insert(0, 'tests/lib')
|
2008-12-29 17:24:05 +00:00
|
|
|
else:
|
2008-12-29 19:05:11 +00:00
|
|
|
sys.path.insert(0, 'tests/lib3')
|
2008-12-28 20:16:50 +00:00
|
|
|
import test_all
|
2016-06-16 01:28:10 +00:00
|
|
|
if not test_all.main([]):
|
|
|
|
raise DistutilsError("Tests failed")
|
2008-12-28 20:16:50 +00:00
|
|
|
|
|
|
|
|
2016-06-17 03:32:32 +00:00
|
|
|
cmdclass = {
|
|
|
|
'build_ext': build_ext,
|
|
|
|
'bdist_rpm': bdist_rpm,
|
|
|
|
'test': test,
|
|
|
|
}
|
|
|
|
if bdist_wheel:
|
|
|
|
cmdclass['bdist_wheel'] = bdist_wheel
|
|
|
|
|
|
|
|
|
2006-08-19 19:37:57 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
|
2008-12-29 23:21:43 +00:00
|
|
|
setup(
|
|
|
|
name=NAME,
|
|
|
|
version=VERSION,
|
|
|
|
description=DESCRIPTION,
|
|
|
|
long_description=LONG_DESCRIPTION,
|
|
|
|
author=AUTHOR,
|
|
|
|
author_email=AUTHOR_EMAIL,
|
|
|
|
license=LICENSE,
|
|
|
|
platforms=PLATFORMS,
|
|
|
|
url=URL,
|
|
|
|
download_url=DOWNLOAD_URL,
|
|
|
|
classifiers=CLASSIFIERS,
|
|
|
|
|
|
|
|
package_dir={'': {2: 'lib', 3: 'lib3'}[sys.version_info[0]]},
|
|
|
|
packages=['yaml'],
|
|
|
|
ext_modules=[
|
|
|
|
Extension('_yaml', ['ext/_yaml.pyx'],
|
|
|
|
'libyaml', "LibYAML bindings", LIBYAML_CHECK,
|
|
|
|
libraries=['yaml']),
|
|
|
|
],
|
|
|
|
|
|
|
|
distclass=Distribution,
|
2016-06-17 03:32:32 +00:00
|
|
|
cmdclass=cmdclass,
|
2008-12-29 23:21:43 +00:00
|
|
|
)
|
2006-03-04 22:43:48 +00:00
|
|
|
|