From d16c830f6dd56ce0d2c02d96e4df434c2a1be8bd Mon Sep 17 00:00:00 2001 From: Alex Petrov Date: Fri, 28 Sep 2018 14:50:15 +0200 Subject: [PATCH] Don't execute imports when reading version. Fixes #7 (#8) --- setup.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index f466685..1aaefb0 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,21 @@ #!/usr/bin/env python3 import io import os +import re from setuptools import setup, find_packages -import device_detector + + +def get_version(): + with open('device_detector/__init__.py', 'r') as f: + line = f.readline() + match = re.match(r'__version__ = \'([\d\.]+)\'', line) + + if not match: + raise ImportError("Can't read the version of device_detector") + + version = match.group(1) + return version + here = os.path.abspath(os.path.dirname(__file__)) with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f: @@ -10,7 +23,7 @@ setup( name='device_detector', - version=device_detector.__version__, + version=get_version(), description="Python3 port of matomo's Device Detector", long_description=long_description, author='Dave Burkholder',