From 84e5ffa905f1d6fc8161dd901d98b385e7a06fba Mon Sep 17 00:00:00 2001 From: Simon Humpohl <simon.humpohl@rwth-aachen.de> Date: Thu, 16 Nov 2017 11:42:07 +0100 Subject: [PATCH] Dynamic __version__ read Rudimentary is simulator check --- setup.py | 20 +++++++++++++++++++- teawg/__init__.py | 9 +++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5f2c3fd..c4df2f3 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,26 @@ from setuptools import setup +import os +import re + + +def get_version(): + dir_path = os.path.dirname(os.path.realpath(__file__)) + + teawg_init = os.path.join(dir_path, 'teawg', '__init__.py') + + with open(teawg_init, 'r') as version_file: + # https://packaging.python.org/guides/single-sourcing-package-version/ + version_match = re.search(r"^__version__\s+=\s+['\"]([^'\"]*)['\"]", version_file.read(), re.M) + + if version_match: + return version_match.group(1) + else: + raise RuntimeError("Unable to find version string.") + setup( name='pytabor', - version='0.0.1', + version=get_version(), packages=['pytabor', 'teawg'], package_dir={'pytabor': 'pytabor', 'teawg': 'teawg'}, url='', diff --git a/teawg/__init__.py b/teawg/__init__.py index 19c930c..f92fe44 100644 --- a/teawg/__init__.py +++ b/teawg/__init__.py @@ -37,6 +37,8 @@ import time import posixpath from pyvisa.errors import VisaIOError, VI_ERROR_TMO +from pyvisa.resources import TCPIPSocket +from pyvisa.constants import InterfaceType import pytabor @@ -438,6 +440,13 @@ class TEWXAwg(object): '''Get the firmware version ''' return self._fw_ver + @property + def is_simulator(self): + '''True if IP address is localhost''' + if self.visa_inst and self.visa_inst.interface_type == InterfaceType.tcpip: + return '127.0.0.1' in self.visa_inst.resource_name or 'localhost' in self.visa_inst.resource_name + return False + @property def paranoia_level(self): '''Get the (default) paranoia-level -- GitLab