Skip to content

Commit d44346b

Browse files
committed
setup refactor v1.5:
* drop usage of charade - no longer maintained * refactor setup for simplicity
1 parent 44b0bbc commit d44346b

File tree

6 files changed

+24
-41
lines changed

6 files changed

+24
-41
lines changed

README.rst

+2-3
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ functionality:
113113

114114
- ``genshi`` has a treewalker (but not builder); and
115115

116-
- ``charade`` can be used as a fallback when character encoding cannot
117-
be determined; ``chardet``, from which it was forked, can also be used
118-
on Python 2.
116+
- ``chardet`` can be used as a fallback when character encoding cannot
117+
be determined.
119118

120119
- ``ordereddict`` can be used under Python 2.6
121120
(``collections.OrderedDict`` is used instead on later versions) to

debug-info.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"maxsize": sys.maxsize
1313
}
1414

15-
search_modules = ["charade", "chardet", "datrie", "genshi", "html5lib", "lxml", "six"]
15+
search_modules = ["chardet", "datrie", "genshi", "html5lib", "lxml", "six"]
1616
found_modules = []
1717

1818
for m in search_modules:

html5lib/inputstream.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,7 @@ def detectEncoding(self, parseMeta=True, chardet=True):
477477
if encoding is None and chardet:
478478
confidence = "tentative"
479479
try:
480-
try:
481-
from charade.universaldetector import UniversalDetector
482-
except ImportError:
483-
from chardet.universaldetector import UniversalDetector
480+
from chardet.universaldetector import UniversalDetector
484481
buffers = []
485482
detector = UniversalDetector()
486483
while not detector.done:
@@ -496,7 +493,7 @@ def detectEncoding(self, parseMeta=True, chardet=True):
496493
except ImportError:
497494
pass
498495
# If all else fails use the default encoding
499-
if encoding is None:
496+
if not encoding:
500497
confidence = "tentative"
501498
encoding = self.defaultEncoding
502499

html5lib/tests/test_encoding.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,9 @@ def test_encoding():
5454
yield (runPreScanEncodingTest, test[b'data'], test[b'encoding'])
5555

5656
try:
57-
try:
58-
import charade # flake8: noqa
59-
except ImportError:
60-
import chardet # flake8: noqa
57+
import chardet # flake8: noqa
6158
except ImportError:
62-
print("charade/chardet not found, skipping chardet tests")
59+
print("chardet not found, skipping chardet tests")
6360
else:
6461
def test_chardet():
6562
with open(os.path.join(test_dir, "encoding" , "chardet", "test_big5.txt"), "rb") as fp:

requirements-optional.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
# streams.
55
genshi
66

7-
# charade can be used as a fallback in case we are unable to determine
7+
# chardet can be used as a fallback in case we are unable to determine
88
# the encoding of a document.
9-
charade
9+
chardet>2.2
1010

1111
# lxml is supported with its own treebuilder ("lxml") and otherwise
1212
# uses the standard ElementTree support

setup.py

+15-25
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import ast
2-
import os
31
import codecs
4-
5-
from setuptools import setup
2+
from os.path import join, dirname
3+
from setuptools import setup, find_packages
64

75

86
classifiers=[
@@ -23,27 +21,19 @@
2321
'Topic :: Text Processing :: Markup :: HTML'
2422
]
2523

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:
3427
long_description = readme_file.read() + '\n' + changes_file.read()
3528

3629
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
4737

4838
setup(name='html5lib',
4939
version=version,
@@ -54,7 +44,7 @@
5444
classifiers=classifiers,
5545
maintainer='James Graham',
5646
maintainer_email='[email protected]',
57-
packages=packages,
47+
packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]),
5848
install_requires=[
5949
'six',
6050
],
@@ -70,13 +60,13 @@
7060

7161
# Standard extras, will be installed when the extra is requested.
7262
"genshi": ["genshi"],
73-
"charade": ["charade"],
63+
"chardet": ["chardet>=2.2"],
7464

7565
# The all extra combines a standard extra which will be used anytime
7666
# the all extra is requested, and it extends it with a conditional
7767
# extra that will be installed whenever the condition matches and the
7868
# all extra is requested.
79-
"all": ["genshi", "charade"],
69+
"all": ["genshi", "chardet>=2.2"],
8070
"all:python_implementation == 'CPython'": ["datrie", "lxml"],
8171
},
8272
)

0 commit comments

Comments
 (0)