diff options
Diffstat (limited to 'setup.py')
-rw-r--r-- | setup.py | 36 |
1 files changed, 34 insertions, 2 deletions
@@ -9,14 +9,46 @@ # (C) 2001-2016 Chris Liechti <cliechti@gmx.net> # # SPDX-License-Identifier: BSD-3-Clause +import io +import os +import re try: from setuptools import setup except ImportError: from distutils.core import setup -import serial -version = serial.VERSION + +def read(*names, **kwargs): + """Python 2 and Python 3 compatible text file reading. + + Required for single-sourcing the version string. + """ + with io.open( + os.path.join(os.path.dirname(__file__), *names), + encoding=kwargs.get("encoding", "utf8") + ) as fp: + return fp.read() + + +def find_version(*file_paths): + """ + Search the file for a version string. + + file_path contain string path components. + + Reads the supplied Python module as text without importing it. + """ + version_file = read(*file_paths) + version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", + version_file, re.M) + if version_match: + return version_match.group(1) + raise RuntimeError("Unable to find version string.") + + +version = find_version('serial', '__init__.py') + setup( name="pyserial", |