|
1 |
| -import ast |
2 |
| -import os |
3 | 1 | import codecs
|
4 |
| - |
5 |
| -from setuptools import setup |
| 2 | +from os.path import join, dirname |
| 3 | +from setuptools import setup, find_packages |
6 | 4 |
|
7 | 5 |
|
8 | 6 | classifiers=[
|
|
23 | 21 | 'Topic :: Text Processing :: Markup :: HTML'
|
24 | 22 | ]
|
25 | 23 |
|
26 |
| -packages = ['html5lib'] + ['html5lib.'+name |
27 |
| - for name in os.listdir(os.path.join('html5lib')) |
28 |
| - if os.path.isdir(os.path.join('html5lib', name)) and |
29 |
| - not name.startswith('.') and name != 'tests'] |
30 |
| - |
31 |
| -current_dir = os.path.dirname(__file__) |
32 |
| -with codecs.open(os.path.join(current_dir, 'README.rst'), 'r', 'utf8') as readme_file: |
33 |
| - with codecs.open(os.path.join(current_dir, 'CHANGES.rst'), 'r', 'utf8') as changes_file: |
| 24 | +here = dirname(__file__) |
| 25 | +with codecs.open(join(here, 'README.rst'), 'r', 'utf8') as readme_file: |
| 26 | + with codecs.open(join(here, 'CHANGES.rst'), 'r', 'utf8') as changes_file: |
34 | 27 | long_description = readme_file.read() + '\n' + changes_file.read()
|
35 | 28 |
|
36 | 29 | version = None
|
37 |
| -with open(os.path.join("html5lib", "__init__.py"), "rb") as init_file: |
38 |
| - t = ast.parse(init_file.read(), filename="__init__.py", mode="exec") |
39 |
| - assert isinstance(t, ast.Module) |
40 |
| - assignments = filter(lambda x: isinstance(x, ast.Assign), t.body) |
41 |
| - for a in assignments: |
42 |
| - if (len(a.targets) == 1 and |
43 |
| - isinstance(a.targets[0], ast.Name) and |
44 |
| - a.targets[0].id == "__version__" and |
45 |
| - isinstance(a.value, ast.Str)): |
46 |
| - version = a.value.s |
| 30 | +with open(join(here, 'html5lib', '__init__.py')) as fp: |
| 31 | + for line in fp: |
| 32 | + _locals = {} |
| 33 | + if line.startswith('__version__'): |
| 34 | + exec(line, None, _locals) |
| 35 | + version = _locals['__version__'] |
| 36 | + break |
47 | 37 |
|
48 |
| -setup(name='html5lib', |
49 |
| - version=version, |
50 |
| - url='https://github.com/html5lib/html5lib-python', |
51 |
| - license="MIT License", |
52 |
| - description='HTML parser based on the WHATWG HTML specification', |
53 |
| - long_description=long_description, |
54 |
| - classifiers=classifiers, |
55 |
| - maintainer='James Graham', |
56 |
| - maintainer_email='[email protected]', |
57 |
| - packages=packages, |
58 |
| - install_requires=[ |
59 |
| - 'six', |
60 |
| - ], |
61 |
| - extras_require={ |
62 |
| - # A empty extra that only has a conditional marker will be |
63 |
| - # unconditonally installed when the condition matches. |
64 |
| - ":python_version == '2.6'": ["ordereddict"], |
| 38 | +setup( |
| 39 | + name='html5lib', |
| 40 | + version=version, |
| 41 | + url='https://github.com/html5lib/html5lib-python', |
| 42 | + license="MIT License", |
| 43 | + description='HTML parser based on the WHATWG HTML specification', |
| 44 | + long_description=long_description, |
| 45 | + classifiers=classifiers, |
| 46 | + maintainer='James Graham', |
| 47 | + maintainer_email='[email protected]', |
| 48 | + packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]), |
| 49 | + install_requires=[ |
| 50 | + 'six', |
| 51 | + ], |
| 52 | + extras_require={ |
| 53 | + # A empty extra that only has a conditional marker will be |
| 54 | + # unconditonally installed when the condition matches. |
| 55 | + ":python_version == '2.6'": ["ordereddict"], |
65 | 56 |
|
66 |
| - # A conditional extra will only install these items when the extra is |
67 |
| - # requested and the condition matches. |
68 |
| - "datrie:python_implementation == 'CPython'": ["datrie"], |
69 |
| - "lxml:python_implementation == 'CPython'": ["lxml"], |
| 57 | + # A conditional extra will only install these items when the extra is |
| 58 | + # requested and the condition matches. |
| 59 | + "datrie:python_implementation == 'CPython'": ["datrie"], |
| 60 | + "lxml:python_implementation == 'CPython'": ["lxml"], |
70 | 61 |
|
71 |
| - # Standard extras, will be installed when the extra is requested. |
72 |
| - "genshi": ["genshi"], |
73 |
| - "charade": ["charade"], |
| 62 | + # Standard extras, will be installed when the extra is requested. |
| 63 | + "genshi": ["genshi"], |
| 64 | + "chardet": ["chardet>=2.2"], |
74 | 65 |
|
75 |
| - # The all extra combines a standard extra which will be used anytime |
76 |
| - # the all extra is requested, and it extends it with a conditional |
77 |
| - # extra that will be installed whenever the condition matches and the |
78 |
| - # all extra is requested. |
79 |
| - "all": ["genshi", "charade"], |
80 |
| - "all:python_implementation == 'CPython'": ["datrie", "lxml"], |
81 |
| - }, |
82 |
| - ) |
| 66 | + # The all extra combines a standard extra which will be used anytime |
| 67 | + # the all extra is requested, and it extends it with a conditional |
| 68 | + # extra that will be installed whenever the condition matches and the |
| 69 | + # all extra is requested. |
| 70 | + "all": ["genshi", "chardet>=2.2"], |
| 71 | + "all:python_implementation == 'CPython'": ["datrie", "lxml"], |
| 72 | + }, |
| 73 | +) |
0 commit comments