| 1 |
|
| 2 |
import ast |
| 3 |
import codecs |
| 4 |
import sys |
| 5 |
|
| 6 |
from os.path import join, dirname |
| 7 |
from setuptools import setup, find_packages, __version__ as setuptools_version |
| 8 |
|
| •9 |
try: |
| 10 |
import pkg_resources |
| 11 |
from pkg_resources import parse_version |
| 12 |
except ImportError: |
| 13 |
pkg_resources = None |
| 14 |
|
| 15 |
try: |
| 16 |
import _markerlib.markers |
| 17 |
except ImportError: |
| 18 |
_markerlib = None |
| 19 |
|
| 20 |
|
| 21 |
# _markerlib.default_environment() obtains its data from _VARS |
| 22 |
# and wraps it in another dict, but _markerlib_evaluate writes |
| 23 |
# to the dict while it is iterating the keys, causing an error |
| 24 |
# on Python 3 only. |
| 25 |
# Replace _markerlib.default_environment to return a custom dict |
| 26 |
# that has all the necessary markers, and ignores any writes. |
| 27 |
|
| 28 |
class Python3MarkerDict(dict): |
| 29 |
|
| 30 |
def __setitem__(self, key, value): |
| 31 |
pass |
| 32 |
|
| 33 |
def pop(self, i=-1): |
| 34 |
return self[i] |
| 35 |
|
| 36 |
|
| 37 |
if _markerlib and sys.version_info[0] == 3: |
| 38 |
env = _markerlib.markers._VARS |
| 39 |
for key in list(env.keys()): |
| 40 |
new_key = key.replace('.', '_') |
| 41 |
if new_key != key: |
| 42 |
env[new_key] = env[key] |
| 43 |
|
| 44 |
_markerlib.markers._VARS = Python3MarkerDict(env) |
| 45 |
|
| 46 |
def default_environment(): |
| 47 |
return _markerlib.markers._VARS |
| 48 |
|
| 49 |
_markerlib.default_environment = default_environment |
| 50 |
|
| 51 |
# Avoid the very buggy pkg_resources.parser, which doesn't consistently |
| 52 |
# recognise the markers needed by this setup.py |
| 53 |
# Change this to setuptools 20.10.0 to support all markers. |
| 54 |
if pkg_resources: |
| 55 |
if parse_version(setuptools_version) < parse_version('18.5'): |
| 56 |
MarkerEvaluation = pkg_resources.MarkerEvaluation |
| 57 |
|
| 58 |
del pkg_resources.parser |
| 59 |
pkg_resources.evaluate_marker = MarkerEvaluation._markerlib_evaluate |
| 60 |
MarkerEvaluation.evaluate_marker = MarkerEvaluation._markerlib_evaluate |
| 61 |
|
| 62 |
classifiers = [ |
| 63 |
'Development Status :: 5 - Production/Stable', |
| 64 |
'Intended Audience :: Developers', |
| 65 |
'License :: OSI Approved :: MIT License', |
| 66 |
'Operating System :: OS Independent', |
| 67 |
'Programming Language :: Python', |
| 68 |
'Programming Language :: Python :: 3', |
| 69 |
'Programming Language :: Python :: 3.8', |
| 70 |
'Programming Language :: Python :: 3.9', |
| 71 |
'Programming Language :: Python :: 3.10', |
| 72 |
'Programming Language :: Python :: 3.11', |
| 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.Constant)): |
| 94 |
version = str(a.value.value) |
| 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='[email protected]', |
| 105 |
packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]), |
| 106 |
install_requires=[], |
| 107 |
python_requires=">=3.8", |
| 108 |
extras_require={ |
| 109 |
# A conditional extra will only install these items when the extra is |
| 110 |
# requested and the condition matches. |
| 111 |
"lxml:platform_python_implementation == 'CPython'": ["lxml>=3.4.0"], |
| 112 |
|
| 113 |
# Standard extras, will be installed when the extra is requested. |
| 114 |
"genshi": ["genshi>=0.7.1"], |
| 115 |
"chardet": ["chardet>=2.2.1"], |
| 116 |
|
| 117 |
# The all extra combines a standard extra which will be used anytime |
| 118 |
# the all extra is requested, and it extends it with a conditional |
| 119 |
# extra that will be installed whenever the condition matches and the |
| 120 |
# all extra is requested. |
| 121 |
"all": ["genshi>=0.7.1", "chardet>=2.2.1"], |
| 122 |
"all:platform_python_implementation == 'CPython'": ["lxml>=3.4.0"], |
| 123 |
}, |
| 124 |
) |