Skip to content

Commit 9e91591

Browse files
committed
Fix #187: store the version at a single place in the tree.
1 parent 5e3d432 commit 9e91591

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

html5lib/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@
2020

2121
__all__ = ["HTMLParser", "parse", "parseFragment", "getTreeBuilder",
2222
"getTreeWalker", "serialize"]
23+
24+
# this has to be at the top level, see how setup.py parses this
2325
__version__ = "0.999999-dev"

setup.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from distutils.core import setup
2+
import ast
23
import os
34
import codecs
45

@@ -29,8 +30,20 @@
2930
with codecs.open(os.path.join(current_dir, 'CHANGES.rst'), 'r', 'utf8') as changes_file:
3031
long_description = readme_file.read() + '\n' + changes_file.read()
3132

33+
version = None
34+
with open(os.path.join("html5lib", "__init__.py"), "rb") as init_file:
35+
t = ast.parse(init_file.read(), filename="__init__.py", mode="exec")
36+
assert isinstance(t, ast.Module)
37+
assignments = filter(lambda x: isinstance(x, ast.Assign), t.body)
38+
for a in assignments:
39+
if (len(a.targets) == 1 and
40+
isinstance(a.targets[0], ast.Name) and
41+
a.targets[0].id == "__version__" and
42+
isinstance(a.value, ast.Str)):
43+
version = a.value.s
44+
3245
setup(name='html5lib',
33-
version='0.999999-dev',
46+
version=version,
3447
url='https://github.com/html5lib/html5lib-python',
3548
license="MIT License",
3649
description='HTML parser based on the WHATWG HTML specification',

0 commit comments

Comments
 (0)