diff --git a/tangostationcontrol/requirements.txt b/tangostationcontrol/requirements.txt index dbcf275517794f9ae19d2c311f954bb8a24777d0..fc06d01e71d930c157dce02091e715a661f0f3a0 100644 --- a/tangostationcontrol/requirements.txt +++ b/tangostationcontrol/requirements.txt @@ -2,6 +2,8 @@ # order of appearance. Changing the order has an impact on the overall # integration process, which may cause wedges in the gate later. -pbr >= 2 +opcua >= 0.98.9 +PyMySQL[rsa] +sqlalchemy GitPython >= 3.1.24 # BSD snmp>=0.1.7 # GPL3 diff --git a/tangostationcontrol/setup.cfg b/tangostationcontrol/setup.cfg index 49c8848906502143b045cd5c6b81afad3b553702..3fea7a30cdb6346e73953d179fe5f8fee437569b 100644 --- a/tangostationcontrol/setup.cfg +++ b/tangostationcontrol/setup.cfg @@ -1,7 +1,6 @@ [metadata] name = tangostationcontrol -;version = attr: tangostationcontrol.__version__ -version = 0.0.1 +version = attr: tangostationcontrol.__version__ summary = LOFAR 2.0 Station Control description_file = README.md @@ -22,21 +21,18 @@ classifier = Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 -[files] -packages=tangostationcontrol +[options] +package_dir= + =./ +packages=find: +python_requires = >=3.6 -;[options] -;package_dir= -; =tangostationcontrol -;packages=find: -; -;[options.packages.find] -;where=tangostationcontrol -; -;[options.entry_points] +[options.packages.find] +where=./ -[entry_points] +[options.entry_points] console_scripts = l2ss-docker-device = tangostationcontrol.devices.docker_device:main l2ss-observation = tangostationcontrol.devices.observation:main @@ -54,4 +50,4 @@ console_scripts = l2ss-parse-statistics-packet = tangostationcontrol.devices.sdp.statistics_packet:main l2ss-random-data = tangostationcontrol.test.devices.random_data:main l2ss-snmp = tangostationcontrol.examples.snmp.snmp:main - l2ss-version = tangostationcontrol.common.lofar_git:main + l2ss-version = tangostationcontrol.common.lofar_version:main diff --git a/tangostationcontrol/setup.py b/tangostationcontrol/setup.py index d3ec3b44fa8631e968870dc49de1cd6c6b14f7c1..6356812fdc2951fff6af9659feca273df06efca3 100644 --- a/tangostationcontrol/setup.py +++ b/tangostationcontrol/setup.py @@ -1,5 +1,7 @@ import setuptools +with open('requirements.txt') as f: + required = f.read().splitlines() + # Requires: setup.cfg -setuptools.setup(setup_requires=['pbr>=2.0.0'], pbr=True) -# setuptools.setup() +setuptools.setup(install_requires=required) diff --git a/tangostationcontrol/tangostationcontrol/__init__.py b/tangostationcontrol/tangostationcontrol/__init__.py index 11f6b43c10463260e829526bd0597e1bb094636e..c6e48f3e8c0b11146b60c5fb7b8b2285fd7124d0 100644 --- a/tangostationcontrol/tangostationcontrol/__init__.py +++ b/tangostationcontrol/tangostationcontrol/__init__.py @@ -1,6 +1,3 @@ -# from tangostationcontrol.common.lofar_git import get_version -# -# __version__ = get_version() +from tangostationcontrol.common.lofar_version import get_version -import pbr.version -__version__ = pbr.version.VersionInfo('tangostationcontrol').version_string() +__version__ = get_version() diff --git a/tangostationcontrol/tangostationcontrol/common/lofar_logging.py b/tangostationcontrol/tangostationcontrol/common/lofar_logging.py index 18e07423d3f86f5de80513c24b0e626e14242c82..be71e4149469fbe772918131e4f0dd28eb28552e 100644 --- a/tangostationcontrol/tangostationcontrol/common/lofar_logging.py +++ b/tangostationcontrol/tangostationcontrol/common/lofar_logging.py @@ -5,7 +5,7 @@ import traceback import socket import time -from .lofar_git import get_version +from .lofar_version import get_version class TangoLoggingHandler(logging.Handler): level_to_device_stream = { diff --git a/tangostationcontrol/tangostationcontrol/common/lofar_git.py b/tangostationcontrol/tangostationcontrol/common/lofar_version.py similarity index 82% rename from tangostationcontrol/tangostationcontrol/common/lofar_git.py rename to tangostationcontrol/tangostationcontrol/common/lofar_version.py index f35d990eedfcae4c53cf1a15db0ebaf9f97fd893..92fe0f5faf7f9b5e1f9738b66c67b5123143f531 100644 --- a/tangostationcontrol/tangostationcontrol/common/lofar_git.py +++ b/tangostationcontrol/tangostationcontrol/common/lofar_version.py @@ -1,9 +1,10 @@ import git import os import functools +import pkg_resources import re -def get_repo(starting_directory: str = os.path.dirname(os.path.abspath(__file__))) -> git.Repo: +def get_repo(starting_directory: str = os.path.dirname(os.path.abspath(__file__)), limit = 10) -> git.Repo: """ Try finding the repository by traversing up the tree. By default, the repository containing this module is returned. @@ -16,9 +17,11 @@ def get_repo(starting_directory: str = os.path.dirname(os.path.abspath(__file__) except git.InvalidGitRepositoryError: pass - # We now have to traverse up the tree - while directory != "/" and os.path.exists(directory): - # Go to parent + # We now have to traverse up the tree up until limit diretories + for i in range(limit): + if directory == "/" or not os.path.exists(directory): + break + directory = os.path.abspath(directory + os.path.sep + "..") try: @@ -26,7 +29,9 @@ def get_repo(starting_directory: str = os.path.dirname(os.path.abspath(__file__) except git.InvalidGitRepositoryError: pass - raise git.InvalidGitRepositoryError("Could not find git repository root in {}".format(starting_directory)) + # Could not find a repo within the limit so return None + return None + @functools.lru_cache(maxsize=None) def get_version(repo: git.Repo = None) -> str: @@ -50,6 +55,14 @@ def get_version(repo: git.Repo = None) -> str: if repo is None: repo = get_repo() + # When we can't find a git repo anymore, we must be packaged. Extract the + # package version directly + if repo is None: + try: + return pkg_resources.require("tangostationcontrol")[0].version + except Exception: + pass + # Filter all tags so that they must match vMAJOR.MINOR.PATCH or # vMAJOR.MINOR.PATCH.BRANCHCOMMIT reg = re.compile(r'^v[0-9](\.[0-9]){2}(\.[a-z]*[0-9]*)?') diff --git a/tangostationcontrol/tangostationcontrol/devices/docker_device.py b/tangostationcontrol/tangostationcontrol/devices/docker_device.py index 1f1fd245ecbf250d4729d5bb76941f9f4893b45b..7d4337b13e0eac5e6277ebdcdacb19a110067a5d 100644 --- a/tangostationcontrol/tangostationcontrol/devices/docker_device.py +++ b/tangostationcontrol/tangostationcontrol/devices/docker_device.py @@ -26,7 +26,7 @@ from tangostationcontrol.clients.docker_client import DockerClient from tangostationcontrol.clients.attribute_wrapper import attribute_wrapper from tangostationcontrol.devices.hardware_device import hardware_device from tangostationcontrol.common.lofar_logging import device_logging_to_python, log_exceptions -from tangostationcontrol.common.lofar_git import get_version +from tangostationcontrol.common.lofar_version import get_version __all__ = ["Docker", "main"] diff --git a/tangostationcontrol/tangostationcontrol/devices/observation.py b/tangostationcontrol/tangostationcontrol/devices/observation.py index 0dbec128dac155fb5243a8ead8f0de0be12dbda4..86a730320a72f0d9bac04cef52fed72ead12a1a8 100644 --- a/tangostationcontrol/tangostationcontrol/devices/observation.py +++ b/tangostationcontrol/tangostationcontrol/devices/observation.py @@ -13,7 +13,7 @@ from time import time from tangostationcontrol.devices.device_decorators import * from tangostationcontrol.common.lofar_logging import device_logging_to_python, log_exceptions -from tangostationcontrol.common.lofar_git import get_version +from tangostationcontrol.common.lofar_version import get_version from json import loads diff --git a/tangostationcontrol/tangostationcontrol/devices/observation_control.py b/tangostationcontrol/tangostationcontrol/devices/observation_control.py index 20bd9f546647833287c239bb5015661cb5850cda..5676a7a183e8b784dd7501c897cefa0c19c041f6 100644 --- a/tangostationcontrol/tangostationcontrol/devices/observation_control.py +++ b/tangostationcontrol/tangostationcontrol/devices/observation_control.py @@ -15,7 +15,7 @@ import time from json import loads from tangostationcontrol.common.lofar_logging import device_logging_to_python, log_exceptions -from tangostationcontrol.common.lofar_git import get_version +from tangostationcontrol.common.lofar_version import get_version from tangostationcontrol.devices.device_decorators import * from tangostationcontrol.devices.observation import Observation diff --git a/tangostationcontrol/tangostationcontrol/devices/recv.py b/tangostationcontrol/tangostationcontrol/devices/recv.py index aa0d098cfdcaae3e62d3d5df3ef5ee88d844e50c..78479ac0e09872ec7aae90f3a4d4a41d990bcea1 100644 --- a/tangostationcontrol/tangostationcontrol/devices/recv.py +++ b/tangostationcontrol/tangostationcontrol/devices/recv.py @@ -22,7 +22,7 @@ import numpy from tangostationcontrol.clients.opcua_client import OPCUAConnection from tangostationcontrol.clients.attribute_wrapper import attribute_wrapper from tangostationcontrol.common.lofar_logging import device_logging_to_python, log_exceptions -from tangostationcontrol.common.lofar_git import get_version +from tangostationcontrol.common.lofar_version import get_version from tangostationcontrol.devices.device_decorators import * from tangostationcontrol.devices.hardware_device import hardware_device diff --git a/tangostationcontrol/tangostationcontrol/devices/sdp/sdp.py b/tangostationcontrol/tangostationcontrol/devices/sdp/sdp.py index dd755853d3cd151fa0db4e6fc36c2c200b980784..71611166b049639b2f058a12aa20c129cfe01e72 100644 --- a/tangostationcontrol/tangostationcontrol/devices/sdp/sdp.py +++ b/tangostationcontrol/tangostationcontrol/devices/sdp/sdp.py @@ -22,7 +22,7 @@ from tangostationcontrol.clients.attribute_wrapper import attribute_wrapper from tangostationcontrol.devices.hardware_device import hardware_device from tangostationcontrol.common.lofar_logging import device_logging_to_python, log_exceptions -from tangostationcontrol.common.lofar_git import get_version +from tangostationcontrol.common.lofar_version import get_version import numpy diff --git a/tangostationcontrol/tangostationcontrol/devices/sdp/statistics.py b/tangostationcontrol/tangostationcontrol/devices/sdp/statistics.py index abb9bddc91873c6fb793fa3be57fac0127981fbb..6da1263ff5ca9438e2d856747e38245c9f8d570d 100644 --- a/tangostationcontrol/tangostationcontrol/devices/sdp/statistics.py +++ b/tangostationcontrol/tangostationcontrol/devices/sdp/statistics.py @@ -24,7 +24,7 @@ from tangostationcontrol.clients.statistics_client import StatisticsClient from tangostationcontrol.clients.opcua_client import OPCUAConnection from tangostationcontrol.clients.attribute_wrapper import attribute_wrapper from tangostationcontrol.devices.hardware_device import hardware_device -from tangostationcontrol.common.lofar_git import get_version +from tangostationcontrol.common.lofar_version import get_version from tangostationcontrol.common.lofar_logging import device_logging_to_python, log_exceptions import logging diff --git a/tangostationcontrol/tangostationcontrol/devices/unb2.py b/tangostationcontrol/tangostationcontrol/devices/unb2.py index 4216374e913daa3e5d3083753ebb10651ddef61e..6824d7b26c8deef76e56ad1ee19fc20e99f34ce1 100644 --- a/tangostationcontrol/tangostationcontrol/devices/unb2.py +++ b/tangostationcontrol/tangostationcontrol/devices/unb2.py @@ -22,7 +22,7 @@ from tangostationcontrol.clients.attribute_wrapper import attribute_wrapper from tangostationcontrol.devices.hardware_device import hardware_device from tangostationcontrol.common.lofar_logging import device_logging_to_python, log_exceptions -from tangostationcontrol.common.lofar_git import get_version +from tangostationcontrol.common.lofar_version import get_version import numpy diff --git a/tangostationcontrol/tangostationcontrol/test/common/test_lofar_git.py b/tangostationcontrol/tangostationcontrol/test/common/test_lofar_git.py index 02700b8d934a9aabc757a909f4f2f46ac43d4616..ff51bafbf85968772d15da7e259072ddf09132e4 100644 --- a/tangostationcontrol/tangostationcontrol/test/common/test_lofar_git.py +++ b/tangostationcontrol/tangostationcontrol/test/common/test_lofar_git.py @@ -10,7 +10,7 @@ import git from unittest import mock -from tangostationcontrol.common import lofar_git +from tangostationcontrol.common import lofar_version from tangostationcontrol.test import base @@ -20,15 +20,15 @@ class TestLofarGit(base.TestCase): def setUp(self): super(TestLofarGit, self).setUp() - # Clear the cache as this function of lofar_git uses LRU decorator + # Clear the cache as this function of lofar_version uses LRU decorator # This is a good demonstration of how unit tests in Python can have # permanent effects, typically fixtures are needed to restore these. - lofar_git.get_version.cache_clear() + lofar_version.get_version.cache_clear() def test_get_version(self): """Test if attributes of get_repo are correctly used by get_version""" - with mock.patch.object(lofar_git, 'get_repo') as m_get_repo: + with mock.patch.object(lofar_version, 'get_repo') as m_get_repo: m_commit = mock.Mock() m_commit.return_value.__str__ = mock.Mock(return_value="123456") m_commit.return_value.iter_items.return_value = [] @@ -43,12 +43,12 @@ class TestLofarGit(base.TestCase): is_dirty=m_is_dirty, head=m_head) # No need for special string equal in Python - self.assertEqual("0.0.0.main123456", lofar_git.get_version()) + self.assertEqual("0.0.0.main123456", lofar_version.get_version()) def test_get_version_tag(self): """Test if get_version determines production_ready for tagged commit""" - with mock.patch.object(lofar_git, 'get_repo') as m_get_repo: + with mock.patch.object(lofar_version, 'get_repo') as m_get_repo: m_commit = mock.Mock() m_commit.return_value.__str__ = mock.Mock(return_value="123456") m_commit.return_value.iter_items.return_value = [] @@ -72,9 +72,9 @@ class TestLofarGit(base.TestCase): active_branch="main", commit=m_commit, tags=[m_tag], is_dirty=m_is_dirty, head=m_head) - self.assertEqual("0.0.3", lofar_git.get_version()) + self.assertEqual("0.0.3", lofar_version.get_version()) - @mock.patch.object(lofar_git, 'get_repo') + @mock.patch.object(lofar_version, 'get_repo') def test_get_version_tag_dirty(self, m_get_repo): """Test if get_version determines dirty tagged commit""" @@ -92,16 +92,16 @@ class TestLofarGit(base.TestCase): is_dirty=m_is_dirty, head=m_head) # No need for special string equal in Python - self.assertEqual("0.0.0.main123456.dirty", lofar_git.get_version()) + self.assertEqual("0.0.0.main123456.dirty", lofar_version.get_version()) def test_catch_repo_error(self): """Test if invalid git directories will raise error""" - with mock.patch.object(lofar_git, 'get_repo') as m_get_repo: + with mock.patch.object(lofar_version, 'get_repo') as m_get_repo: - # Configure lofar_git.get_repo to raise InvalidGitRepositoryError + # Configure lofar_version.get_repo to raise InvalidGitRepositoryError m_get_repo.side_effect = git.InvalidGitRepositoryError # Test that error is raised by get_version self.assertRaises( - git.InvalidGitRepositoryError, lofar_git.get_version) + git.InvalidGitRepositoryError, lofar_version.get_version) diff --git a/tangostationcontrol/tangostationcontrol/version.py b/tangostationcontrol/tangostationcontrol/version.py deleted file mode 100644 index c320dcf0646f140df5a0de5d526e3175106eccb7..0000000000000000000000000000000000000000 --- a/tangostationcontrol/tangostationcontrol/version.py +++ /dev/null @@ -1,6 +0,0 @@ -# version = "v0.0.1" - -import pbr.version - -version_info = pbr.version.VersionInfo('python-watcher') -version_string = version_info.version_string()