Skip to content
Snippets Groups Projects
Commit 6e1f849c authored by Jan David Mol's avatar Jan David Mol
Browse files

Merge branch 'L2SS-176-expose-git-version' into 'master'

Resolve L2SS-176 "Expose git version"

Closes L2SS-176

See merge request !35
parents 7f786752 8530e8f3
Branches
Tags
1 merge request!35Resolve L2SS-176 "Expose git version"
......@@ -13,7 +13,7 @@
# PyTango imports
from tango.server import run
from tango.server import device_property
from tango.server import device_property, attribute
from tango import AttrWriteType
# Additional import
......@@ -22,6 +22,7 @@ from util.attribute_wrapper import attribute_wrapper
from util.hardware_device import hardware_device
from util.lofar_logging import device_logging_to_python, log_exceptions
from util.lofar_git import get_version
import numpy
......@@ -64,6 +65,9 @@ class APSCTL(hardware_device):
# ----------
# Attributes
# ----------
version_R = attribute(dtype=str, access=AttrWriteType.READ, fget=lambda self: get_version())
N_unb = 2
N_fpga = 4
N_ddr = 2
......
......@@ -14,7 +14,7 @@
# PyTango imports
from tango import DebugIt
from tango.server import run, command
from tango.server import device_property
from tango.server import device_property, attribute
from tango import AttrWriteType
import numpy
# Additional import
......@@ -25,6 +25,7 @@ from clients.opcua_connection import OPCUAConnection
from util.attribute_wrapper import attribute_wrapper
from util.hardware_device import hardware_device
from util.lofar_logging import device_logging_to_python, log_exceptions
from util.lofar_git import get_version
__all__ = ["PCC", "main"]
......@@ -69,6 +70,7 @@ class PCC(hardware_device):
# ----------
# Attributes
# ----------
version_R = attribute(dtype=str, access=AttrWriteType.READ, fget=lambda self: get_version())
Ant_mask_RW = attribute_wrapper(comms_annotation=["2:PCC", "2:Ant_mask_RW"], datatype=numpy.bool_, dims=(3, 32), access=AttrWriteType.READ_WRITE)
CLK_Enable_PWR_R = attribute_wrapper(comms_annotation=["2:PCC", "2:CLK_Enable_PWR_R"], datatype=numpy.bool_)
CLK_I2C_STATUS_R = attribute_wrapper(comms_annotation=["2:PCC", "2:CLK_I2C_STATUS_R"], datatype=numpy.int64)
......
......@@ -13,7 +13,7 @@
# PyTango imports
from tango.server import run
from tango.server import device_property
from tango.server import device_property, attribute
from tango import AttrWriteType
# Additional import
......@@ -22,6 +22,7 @@ from util.attribute_wrapper import attribute_wrapper
from util.hardware_device import hardware_device
from util.lofar_logging import device_logging_to_python, log_exceptions
from util.lofar_git import get_version
import numpy
......@@ -64,6 +65,9 @@ class SDP(hardware_device):
# ----------
# Attributes
# ----------
version_R = attribute(dtype=str, access=AttrWriteType.READ, fget=lambda self: get_version())
# SDP will switch from fpga_mask_RW to tr_fpga_mask_RW, offer both for now as its a critical flag
tr_fpga_mask_RW = attribute_wrapper(comms_annotation=["2:tr_fpga_mask_RW"], datatype=numpy.bool_, dims=(16,), access=AttrWriteType.READ_WRITE)
fpga_mask_RW = attribute_wrapper(comms_annotation=["2:fpga_mask_RW"], datatype=numpy.bool_, dims=(16,), access=AttrWriteType.READ_WRITE)
......
import git # pip3 install gitpython
import os
from functools import lru_cache
def get_repo(starting_directory: str = os.path.dirname(__file__)) -> git.Repo:
""" Try finding the repository by traversing up the tree.
By default, the repository containing this module is returned.
"""
directory = starting_directory
try:
return git.Repo(directory)
except git.InvalidGitRepositoryError:
pass
# We now have to traverse up the tree
while directory != "/" and os.path.exists(directory):
# Go to parent
directory = os.path.abspath(directory + os.path.sep + "..")
try:
return git.Repo(directory)
except git.InvalidGitRepositoryError:
pass
raise git.InvalidGitRepositoryError("Could not find git repository root in {}".format(starting_directory))
@lru_cache(maxsize=None)
def get_version(repo: git.Repo = None) -> str:
""" Return a version string for the current commit.
There is a practical issue: the repository changes over time, f.e. switching branches with 'git checkout'. We want
to know the version that is running in memory, not the one that is on disk.
As a work-around, we cache the version information, in that it is at least consistent. It is up to the caller
to request the version early enough.
The version string is one of:
- <tag>
- <branch> [<commit>]
In both cases, a "*" prefix indicates this code is not production ready. Code is considered production ready if
it is a tag and there are no local modifications.
"""
if repo is None:
repo = get_repo()
branch = repo.active_branch
commit = repo.commit()
tags = { tag.commit: tag for tag in repo.tags }
if commit in tags:
commit_str = "{}".format(tags[commit])
production_ready = True
else:
commit_str = "{} [{}]".format(branch, commit)
production_ready = False
if repo.is_dirty():
production_ready = False
return "{}{}".format("*" if not production_ready else "", commit_str)
# at least cache the current repo version immediately
try:
_ = get_version()
except:
pass
if __name__ == "__main__":
print(get_version())
This diff is collapsed.
FROM nexus.engageska-portugal.pt/ska-docker/tango-itango:latest
RUN sudo apt-get update && sudo apt-get install -y git && sudo apt-get clean
COPY lofar-requirements.txt /lofar-requirements.txt
RUN sudo pip3 install -r /lofar-requirements.txt
......
opcua >= 0.98.9
astropy
python-logstash-async
gitpython
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment