setup.py (4655B)
1 from __future__ import print_function 2 3 import ast 4 import codecs 5 import sys 6 7 from os.path import join, dirname 8 from setuptools import setup, find_packages, __version__ as setuptools_version 9 from pkg_resources import parse_version 10 11 import pkg_resources 12 13 try: 14 import _markerlib.markers 15 except ImportError: 16 _markerlib = None 17 18 19 # _markerlib.default_environment() obtains its data from _VARS 20 # and wraps it in another dict, but _markerlib_evaluate writes 21 # to the dict while it is iterating the keys, causing an error 22 # on Python 3 only. 23 # Replace _markerlib.default_environment to return a custom dict 24 # that has all the necessary markers, and ignores any writes. 25 26 class Python3MarkerDict(dict): 27 28 def __setitem__(self, key, value): 29 pass 30 31 def pop(self, i=-1): 32 return self[i] 33 34 35 if _markerlib and sys.version_info[0] == 3: 36 env = _markerlib.markers._VARS 37 for key in list(env.keys()): 38 new_key = key.replace('.', '_') 39 if new_key != key: 40 env[new_key] = env[key] 41 42 _markerlib.markers._VARS = Python3MarkerDict(env) 43 44 def default_environment(): 45 return _markerlib.markers._VARS 46 47 _markerlib.default_environment = default_environment 48 49 # Avoid the very buggy pkg_resources.parser, which doesn't consistently 50 # recognise the markers needed by this setup.py 51 # Change this to setuptools 20.10.0 to support all markers. 52 if pkg_resources: 53 if parse_version(setuptools_version) < parse_version('18.5'): 54 MarkerEvaluation = pkg_resources.MarkerEvaluation 55 56 del pkg_resources.parser 57 pkg_resources.evaluate_marker = MarkerEvaluation._markerlib_evaluate 58 MarkerEvaluation.evaluate_marker = MarkerEvaluation._markerlib_evaluate 59 60 classifiers = [ 61 'Development Status :: 5 - Production/Stable', 62 'Intended Audience :: Developers', 63 'License :: OSI Approved :: MIT License', 64 'Operating System :: OS Independent', 65 'Programming Language :: Python', 66 'Programming Language :: Python :: 2', 67 'Programming Language :: Python :: 2.7', 68 'Programming Language :: Python :: 3', 69 'Programming Language :: Python :: 3.5', 70 'Programming Language :: Python :: 3.6', 71 'Programming Language :: Python :: 3.7', 72 'Programming Language :: Python :: 3.8', 73 'Programming Language :: Python :: Implementation :: CPython', 74 'Programming Language :: Python :: Implementation :: PyPy', 75 'Topic :: Software Development :: Libraries :: Python Modules', 76 'Topic :: Text Processing :: Markup :: HTML' 77 ] 78 79 here = dirname(__file__) 80 with codecs.open(join(here, 'README.rst'), 'r', 'utf8') as readme_file: 81 with codecs.open(join(here, 'CHANGES.rst'), 'r', 'utf8') as changes_file: 82 long_description = readme_file.read() + '\n' + changes_file.read() 83 84 version = None 85 with open(join(here, "html5lib", "__init__.py"), "rb") as init_file: 86 t = ast.parse(init_file.read(), filename="__init__.py", mode="exec") 87 assert isinstance(t, ast.Module) 88 assignments = filter(lambda x: isinstance(x, ast.Assign), t.body) 89 for a in assignments: 90 if (len(a.targets) == 1 and 91 isinstance(a.targets[0], ast.Name) and 92 a.targets[0].id == "__version__" and 93 isinstance(a.value, ast.Str)): 94 version = a.value.s 95 96 setup(name='html5lib', 97 version=version, 98 url='https://github.com/html5lib/html5lib-python', 99 license="MIT License", 100 description='HTML parser based on the WHATWG HTML specification', 101 long_description=long_description, 102 classifiers=classifiers, 103 maintainer='James Graham', 104 maintainer_email='james@hoppipolla.co.uk', 105 packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]), 106 install_requires=[ 107 'six>=1.9', 108 'webencodings', 109 ], 110 python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", 111 extras_require={ 112 # A conditional extra will only install these items when the extra is 113 # requested and the condition matches. 114 "lxml:platform_python_implementation == 'CPython'": ["lxml"], 115 116 # Standard extras, will be installed when the extra is requested. 117 "genshi": ["genshi"], 118 "chardet": ["chardet>=2.2"], 119 120 # The all extra combines a standard extra which will be used anytime 121 # the all extra is requested, and it extends it with a conditional 122 # extra that will be installed whenever the condition matches and the 123 # all extra is requested. 124 "all": ["genshi", "chardet>=2.2"], 125 "all:platform_python_implementation == 'CPython'": ["lxml"], 126 }, 127 )