diff options
author | zsquareplusc <cliechti@gmx.net> | 2016-06-17 22:38:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-17 22:38:58 +0200 |
commit | cd88ecb80acf2e5e966edaf5de57cedc058b7090 (patch) | |
tree | 3a99da2745856b9c0449e23f07d14f73a6d39dfc | |
parent | 6ea336f4714299506b7582edea0e335e56f5dc3b (diff) | |
parent | a31f9ac4bb260d119cf972c170e5438db3985862 (diff) | |
download | pyserial-git-cd88ecb80acf2e5e966edaf5de57cedc058b7090.tar.gz |
Merge pull request #130 from rob-smallshire/single_source_version
Avoids setup.py having to import the serial package.
-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", |