Skip to content

Commit 4429fc8

Browse files
committed
update setup.py
1 parent d4ea8a8 commit 4429fc8

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

setup.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
from setuptools import setup
2-
from codecs import open as _open
2+
from codecs import open
33
from os import path
44
import re
55

6+
# Path to local directory
7+
here = path.abspath(path.dirname(__file__))
68

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()
129

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()
1315

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())
1822
if verdata:
19-
data = verdata.group(1)
20-
return data.decode()
23+
return verdata.group(1)
2124
else:
2225
raise RuntimeError("Unable to extract version number")
2326

2427

2528
setup(
2629
name='htmlement',
27-
version=version('htmlement.py'),
30+
version=extract_variable('htmlement.py', '__version__'),
2831
description='Pure-Python HTML parser with ElementTree support.',
29-
long_description=readme(),
32+
long_description=readfile('README.md'),
3033
extras_require={"dev": ["pytest", "pytest-cov"]},
3134
keywords='html html5 parsehtml htmlparser elementtree dom',
3235
classifiers=[

0 commit comments

Comments
 (0)