2006-03-04 22:43:48 +00:00
2006-04-23 18:07:52 +00:00
NAME = ' PyYAML '
2023-07-18 01:38:18 +02:00
VERSION = ' 6.0.1 '
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
2017-01-22 12:42:27 +01:00
configuration files to object serialization and persistence . """
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 "
2020-12-11 21:12:08 -05:00
URL = " https://pyyaml.org/ "
2018-06-24 17:08:57 -06:00
DOWNLOAD_URL = " https://pypi.org/project/PyYAML/ "
2006-04-23 18:07:52 +00:00
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 " ,
2019-12-08 09:46:19 -08:00
" Programming Language :: Cython " ,
2006-04-23 18:07:52 +00:00
" Programming Language :: Python " ,
2008-12-29 17:24:05 +00:00
" Programming Language :: Python :: 3 " ,
2017-04-16 15:02:35 -07:00
" Programming Language :: Python :: 3.6 " ,
2018-01-31 10:29:58 +02:00
" Programming Language :: Python :: 3.7 " ,
2019-07-30 17:40:33 -07:00
" Programming Language :: Python :: 3.8 " ,
2020-12-11 21:12:08 -05:00
" Programming Language :: Python :: 3.9 " ,
2021-09-23 15:30:53 -07:00
" Programming Language :: Python :: 3.10 " ,
2022-09-14 00:12:45 +02:00
" Programming Language :: Python :: 3.11 " ,
2017-04-16 15:02:35 -07:00
" 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 " ,
]
2020-12-11 21:12:08 -05:00
PROJECT_URLS = {
' Bug Tracker ' : ' https://github.com/yaml/pyyaml/issues ' ,
' CI ' : ' https://github.com/yaml/pyyaml/actions ' ,
' Documentation ' : ' https://pyyaml.org/wiki/PyYAMLDocumentation ' ,
' Mailing lists ' : ' http://lists.sourceforge.net/lists/listinfo/yaml-core ' ,
' Source Code ' : ' https://github.com/yaml/pyyaml ' ,
}
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 ;
}
"""
2021-09-23 15:30:53 -07:00
import sys , os , os . path , pathlib , platform , shutil , tempfile , warnings
# for newer setuptools, enable the embedded distutils before importing setuptools/distutils to avoid warnings
os . environ [ ' SETUPTOOLS_USE_DISTUTILS ' ] = ' local '
2008-10-09 15:56:20 +00:00
2020-12-11 21:12:08 -05:00
from setuptools import setup , Command , Distribution as _Distribution , Extension as _Extension
from setuptools . command . build_ext import build_ext as _build_ext
2021-09-23 15:30:53 -07:00
# NB: distutils imports must remain below setuptools to ensure we use the embedded version
from distutils import log
2016-06-15 20:28:10 -05:00
from distutils . errors import DistutilsError , CompileError , LinkError , DistutilsPlatformError
2008-10-01 23:16:09 +00:00
2016-06-15 19:28:34 -05:00
with_cython = False
2020-12-11 21:12:08 -05:00
if ' sdist ' in sys . argv or os . environ . get ( ' PYYAML_FORCE_CYTHON ' ) == ' 1 ' :
2018-06-28 21:23:52 +02:00
# we need cython here
with_cython = True
2016-06-15 19:28:34 -05:00
try :
from Cython . Distutils . extension import Extension as _Extension
from Cython . Distutils import build_ext as _build_ext
with_cython = True
except ImportError :
2018-06-28 21:23:52 +02:00
if with_cython :
raise
2008-10-01 23:16:09 +00:00
2016-06-16 22:32:32 -05:00
try :
from wheel . bdist_wheel import bdist_wheel
except ImportError :
bdist_wheel = None
2008-10-01 23:16:09 +00:00
2019-03-12 11:35:50 -07:00
# on Windows, disable wheel generation warning noise
windows_ignore_warnings = [
" Unknown distribution option: ' python_requires ' " ,
" Config variable ' Py_DEBUG ' is unset " ,
" Config variable ' WITH_PYMALLOC ' is unset " ,
" Config variable ' Py_UNICODE_SIZE ' is unset " ,
" Cython directive ' language_level ' not set "
]
if platform . system ( ) == ' Windows ' :
for w in windows_ignore_warnings :
warnings . filterwarnings ( ' ignore ' , w )
2008-10-01 23:16:09 +00:00
2020-12-11 21:12:08 -05:00
class Distribution ( _Distribution ) :
2008-10-01 23:16:09 +00:00
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 17:52:48 -05:00
implementation = platform . python_implementation ( )
2020-12-11 21:12:08 -05:00
if implementation not in [ ' CPython ' , ' PyPy ' ] :
2011-05-29 16:13:17 +00:00
return False
2008-11-30 14:06:13 +00:00
if isinstance ( ext , Extension ) :
2020-12-11 21:12:08 -05:00
# the "build by default" behavior is implemented by this returning None
with_ext = getattr ( self , ext . attr_name ) or os . environ . get ( ' PYYAML_FORCE_ {0} ' . format ( ext . feature_name . upper ( ) ) )
try :
with_ext = int ( with_ext ) # attempt coerce envvar to int
except TypeError :
pass
2008-11-30 14:06:13 +00:00
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-15 19:28:34 -05: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-15 19:28:34 -05: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 )
2017-09-08 11:05:24 -04:00
if with_ext is not None and not with_ext :
2008-11-30 14:06:13 +00:00
continue
2016-06-15 19:28:34 -05:00
if with_cython :
2008-12-29 23:21:43 +00:00
ext . sources = self . cython_sources ( ext . sources , ext )
2017-09-08 11:05:24 -04:00
try :
self . build_extension ( ext )
except ( CompileError , LinkError ) :
if with_ext is not None :
raise
log . warn ( " Error compiling module, falling back to pure Python " )
2008-10-02 00:24:42 +00:00
2008-10-01 23:16:09 +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 ) :
2021-11-24 16:37:09 -08:00
warnings . warn ( ' Running tests via `setup.py test` is deprecated and will be removed in a future release. Use `pytest` instead to ensure that the complete test suite is run. ' , DeprecationWarning )
2008-12-28 20:16:50 +00:00
build_cmd = self . get_finalized_command ( ' build ' )
build_cmd . run ( )
2021-09-23 15:30:53 -07:00
# running the tests this way can pollute the post-MANIFEST build sources
# (see https://github.com/yaml/pyyaml/issues/527#issuecomment-921058344)
# until we remove the test command, run tests from an ephemeral copy of the intermediate build sources
tempdir = tempfile . TemporaryDirectory ( prefix = ' test_pyyaml ' )
try :
# have to create a subdir since we don't get dir_exists_ok on copytree until 3.8
temp_test_path = pathlib . Path ( tempdir . name ) / ' pyyaml '
shutil . copytree ( build_cmd . build_lib , temp_test_path )
sys . path . insert ( 0 , str ( temp_test_path ) )
2021-11-24 16:37:09 -08:00
sys . path . insert ( 0 , ' tests/legacy_tests ' )
2021-09-23 15:30:53 -07:00
import test_all
if not test_all . main ( [ ] ) :
raise DistutilsError ( " Tests failed " )
finally :
try :
# this can fail under Windows; best-effort cleanup
tempdir . cleanup ( )
except Exception :
pass
2008-12-28 20:16:50 +00:00
2016-06-16 22:32:32 -05:00
cmdclass = {
' build_ext ' : build_ext ,
' 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 ,
2020-12-11 21:12:08 -05:00
project_urls = PROJECT_URLS ,
2008-12-29 23:21:43 +00:00
2021-09-02 16:41:22 -04:00
package_dir = { ' ' : ' lib ' } ,
2020-12-11 21:12:08 -05:00
packages = [ ' yaml ' , ' _yaml ' ] ,
2008-12-29 23:21:43 +00:00
ext_modules = [
2020-12-11 21:12:08 -05:00
Extension ( ' yaml._yaml ' , [ ' yaml/_yaml.pyx ' ] ,
2008-12-29 23:21:43 +00:00
' libyaml ' , " LibYAML bindings " , LIBYAML_CHECK ,
libraries = [ ' yaml ' ] ) ,
] ,
distclass = Distribution ,
2016-06-16 22:32:32 -05:00
cmdclass = cmdclass ,
2021-09-02 16:47:31 -04:00
python_requires = ' >=3.6 ' ,
2008-12-29 23:21:43 +00:00
)