|
1 | 1 | from setuptools import setup |
2 | | -from codecs import open as _open |
| 2 | +from codecs import open |
3 | 3 | from os import path |
4 | 4 | import re |
5 | 5 |
|
| 6 | +# Path to local directory |
| 7 | +here = path.abspath(path.dirname(__file__)) |
6 | 8 |
|
7 | | -def readme(): |
8 | | - # Get the long description from the README file |
9 | | - readme_file = path.join(path.abspath(path.dirname(__file__)), "README.rst") |
10 | | - with _open(readme_file, "rb", encoding='utf-8') as opened_file: |
11 | | - return opened_file.read() |
12 | 9 |
|
| 10 | +def readfile(filename): # type: (str) -> str |
| 11 | + """Get the long description from the README file""" |
| 12 | + readme_file = path.join(here, filename) |
| 13 | + with open(readme_file, "r", encoding="utf-8") as stream: |
| 14 | + return stream.read() |
13 | 15 |
|
14 | | -def version(name): |
15 | | - with open(name, 'rb') as opened: |
16 | | - search_refind = b'__version__ = ["\'](\d+\.\d+\.\d+)["\']' |
17 | | - verdata = re.search(search_refind, opened.read()) |
| 16 | + |
| 17 | +def extract_variable(filename, variable): # type: (str, str) -> str |
| 18 | + """Extract the version number from a python file that contains the '__version__' variable.""" |
| 19 | + with open(filename, "r", encoding="utf8") as stream: |
| 20 | + search_refind = r'{} = ["\'](\d+\.\d+\.\d+)["\']'.format(variable) |
| 21 | + verdata = re.search(search_refind, stream.read()) |
18 | 22 | if verdata: |
19 | | - data = verdata.group(1) |
20 | | - return data.decode() |
| 23 | + return verdata.group(1) |
21 | 24 | else: |
22 | 25 | raise RuntimeError("Unable to extract version number") |
23 | 26 |
|
24 | 27 |
|
25 | 28 | setup( |
26 | 29 | name='htmlement', |
27 | | - version=version('htmlement.py'), |
| 30 | + version=extract_variable('htmlement.py', '__version__'), |
28 | 31 | description='Pure-Python HTML parser with ElementTree support.', |
29 | | - long_description=readme(), |
| 32 | + long_description=readfile('README.md'), |
30 | 33 | extras_require={"dev": ["pytest", "pytest-cov"]}, |
31 | 34 | keywords='html html5 parsehtml htmlparser elementtree dom', |
32 | 35 | classifiers=[ |
|
0 commit comments