Skip to content

setup refactor v1.5 #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,8 @@ functionality:

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

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

- ``ordereddict`` can be used under Python 2.6
(``collections.OrderedDict`` is used instead on later versions) to
Expand Down
2 changes: 1 addition & 1 deletion debug-info.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"maxsize": sys.maxsize
}

search_modules = ["charade", "chardet", "datrie", "genshi", "html5lib", "lxml", "six"]
search_modules = ["chardet", "datrie", "genshi", "html5lib", "lxml", "six"]
found_modules = []

for m in search_modules:
Expand Down
7 changes: 2 additions & 5 deletions html5lib/inputstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,7 @@ def detectEncoding(self, parseMeta=True, chardet=True):
if encoding is None and chardet:
confidence = "tentative"
try:
try:
from charade.universaldetector import UniversalDetector
except ImportError:
from chardet.universaldetector import UniversalDetector
from chardet.universaldetector import UniversalDetector
buffers = []
detector = UniversalDetector()
while not detector.done:
Expand All @@ -490,7 +487,7 @@ def detectEncoding(self, parseMeta=True, chardet=True):
except ImportError:
pass
# If all else fails use the default encoding
if encoding is None:
if not encoding:
confidence = "tentative"
encoding = lookupEncoding(self.defaultEncoding)

Expand Down
7 changes: 2 additions & 5 deletions html5lib/tests/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,9 @@ def test_encoding():
yield (runPreScanEncodingTest, test[b'data'], test[b'encoding'])

try:
try:
import charade # flake8: noqa
except ImportError:
import chardet # flake8: noqa
import chardet # flake8: noqa
except ImportError:
print("charade/chardet not found, skipping chardet tests")
print("chardet not found, skipping chardet tests")
else:
def test_chardet():
with open(os.path.join(test_dir, "encoding" , "chardet", "test_big5.txt"), "rb") as fp:
Expand Down
4 changes: 2 additions & 2 deletions requirements-optional.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# streams.
genshi

# charade can be used as a fallback in case we are unable to determine
# chardet can be used as a fallback in case we are unable to determine
# the encoding of a document.
charade
chardet>2.2

# lxml is supported with its own treebuilder ("lxml") and otherwise
# uses the standard ElementTree support
Expand Down
46 changes: 18 additions & 28 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import ast
import os
import codecs

from setuptools import setup
from os.path import join, dirname
from setuptools import setup, find_packages


classifiers=[
Expand All @@ -22,27 +20,19 @@
'Topic :: Text Processing :: Markup :: HTML'
]

packages = ['html5lib'] + ['html5lib.'+name
for name in os.listdir(os.path.join('html5lib'))
if os.path.isdir(os.path.join('html5lib', name)) and
not name.startswith('.') and name != 'tests']

current_dir = os.path.dirname(__file__)
with codecs.open(os.path.join(current_dir, 'README.rst'), 'r', 'utf8') as readme_file:
with codecs.open(os.path.join(current_dir, 'CHANGES.rst'), 'r', 'utf8') as changes_file:
here = dirname(__file__)
with codecs.open(join(here, 'README.rst'), 'r', 'utf8') as readme_file:
with codecs.open(join(here, 'CHANGES.rst'), 'r', 'utf8') as changes_file:
long_description = readme_file.read() + '\n' + changes_file.read()

version = None
with open(os.path.join("html5lib", "__init__.py"), "rb") as init_file:
t = ast.parse(init_file.read(), filename="__init__.py", mode="exec")
assert isinstance(t, ast.Module)
assignments = filter(lambda x: isinstance(x, ast.Assign), t.body)
for a in assignments:
if (len(a.targets) == 1 and
isinstance(a.targets[0], ast.Name) and
a.targets[0].id == "__version__" and
isinstance(a.value, ast.Str)):
version = a.value.s
with open(join(here, 'html5lib', '__init__.py')) as fp:
for line in fp:
_locals = {}
if line.startswith('__version__'):
exec(line, None, _locals)
version = _locals['__version__']
break

setup(name='html5lib',
version=version,
Expand All @@ -53,7 +43,7 @@
classifiers=classifiers,
maintainer='James Graham',
maintainer_email='[email protected]',
packages=packages,
packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]),
install_requires=[
'six',
'webencodings',
Expand All @@ -65,18 +55,18 @@

# A conditional extra will only install these items when the extra is
# requested and the condition matches.
"datrie:python_implementation == 'CPython'": ["datrie"],
"lxml:python_implementation == 'CPython'": ["lxml"],
"datrie:platform_python_implementation == 'CPython'": ["datrie"],
"lxml:platform_python_implementation == 'CPython'": ["lxml"],

# Standard extras, will be installed when the extra is requested.
"genshi": ["genshi"],
"charade": ["charade"],
"chardet": ["chardet>=2.2"],

# The all extra combines a standard extra which will be used anytime
# the all extra is requested, and it extends it with a conditional
# extra that will be installed whenever the condition matches and the
# all extra is requested.
"all": ["genshi", "charade"],
"all:python_implementation == 'CPython'": ["datrie", "lxml"],
"all": ["genshi", "chardet>=2.2"],
"all:platform_python_implementation == 'CPython'": ["datrie", "lxml"],
},
)