8000 Merge pull request #107 from pypt/module_version_constant · kingking888/python-readability@dca6e21 · GitHub
[go: up one dir, main page]

Skip to content

Commit dca6e21

Browse files
authored
Merge pull request buriy#107 from pypt/module_version_constant
Add __version__ constant to __init__.py, read it in setup.py
2 parents 5215ab6 + 0233936 commit dca6e21

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

readability/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
__version__ = "0.7"
2+
13
from .readability import Document

setup.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/usr/bin/env python
2+
23
from __future__ import print_function
3-
from setuptools import setup, find_packages
4+
import codecs
5+
import os
6+
import re
7+
from setuptools import setup
48
import sys
59

610
lxml_requirement = "lxml"
@@ -12,9 +16,29 @@
1216
print("Using lxml<2.4")
1317
lxml_requirement = "lxml<2.4"
1418

19+
20+
# Adapted from https://github.com/pypa/pip/blob/master/setup.py
21+
def find_version(*file_paths):
22+
here = os.path.abspath(os.path.dirname(__file__))
23+
24+
# Intentionally *not* adding an encoding option to open, See:
25+
# https://github.com/pypa/virtualenv/issues/201#issuecomment-3145690
26+
with codecs.open(os.path.join(here, *file_paths), 'r') as fp:
27+
version_file = fp.read()
28+
version_match = re.search(
29+
r"^__version__ = ['\"]([^'\"]*)['\"]",
30+
version_file,
31+
re.M,
32+
)
33+
if version_match:
34+
return version_match.group(1)
35+
36+
raise RuntimeError("Unable to find version string.")
37+
38+
1539
setup(
1640
name="readability-lxml",
17-
version="0.7",
41+
version=find_version("readability", "__init__.py"),
1842
author="Yuri Baburov",
1943
author_email="burchik@gmail.com",
2044
description="fast html to text parser (article readability tool) with python3 support",

0 commit comments

Comments
 (0)
0