Skip to content

Commit

Permalink
Fix #187: store the version at a single place in the tree.
Browse files Browse the repository at this point in the history
  • Loading branch information
gsnedders committed Jul 6, 2015
1 parent 5e3d432 commit 9e91591
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions html5lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@

__all__ = ["HTMLParser", "parse", "parseFragment", "getTreeBuilder",
"getTreeWalker", "serialize"]

# this has to be at the top level, see how setup.py parses this
__version__ = "0.999999-dev"
15 changes: 14 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from distutils.core import setup
import ast
import os
import codecs

Expand Down Expand Up @@ -29,8 +30,20 @@
with codecs.open(os.path.join(current_dir, '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

setup(name='html5lib',
version='0.999999-dev',
version=version,
url='https://github.com/html5lib/html5lib-python',
license="MIT License",
description='HTML parser based on the WHATWG HTML specification',
Expand Down

0 comments on commit 9e91591

Please sign in to comment.