• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SpiNNakerManchester / SpiNNMan / 6574804013

19 Oct 2023 12:47PM UTC coverage: 51.937% (+1.2%) from 50.777%
6574804013

Pull #327

github

Christian-B
typing changes
Pull Request #327: Type Annotations and Checking

105 of 1288 branches covered (0.0%)

Branch coverage included in aggregate %.

2375 of 2375 new or added lines in 180 files covered. (100.0%)

4775 of 8108 relevant lines covered (58.89%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.76
/spinnman/model/version_info.py
1
# Copyright (c) 2014 The University of Manchester
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     https://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14

15
import re
1✔
16
import struct
1✔
17
from time import localtime, asctime
1✔
18
from typing import Tuple, cast
1✔
19
from typing_extensions import TypeAlias
1✔
20
from spinnman.exceptions import SpinnmanInvalidParameterException
1✔
21

22
_VERSION_PATTERN = struct.Struct("<BBBBHHI")
1✔
23
_V: TypeAlias = Tuple[int, int, int]
1✔
24

25

26
class VersionInfo(object):
1✔
27
    """
28
    Decodes SC&MP/SARK version information as returned by the SVER command.
29
    """
30
    __slots__ = [
1✔
31
        "_build_date",
32
        "_hardware",
33
        "_name",
34
        "_physical_cpu_id",
35
        "_version_number",
36
        "_version_string",
37
        "_x", "_y", "_p"]
38

39
    def __init__(self, version_data: bytes, offset: int = 0):
1✔
40
        """
41
        :param bytes version_data:
42
            bytes from an SCP packet containing version information
43
        :param int offset:
44
            the offset in the bytes from an SCP packet containing
45
            version information
46
        :raise SpinnmanInvalidParameterException:
47
            If the message does not contain valid version information
48
        """
49
        (self._p, self._physical_cpu_id, self._y, self._x, _,
1✔
50
            version_no, self._build_date) = _VERSION_PATTERN.unpack_from(
51
                memoryview(version_data), offset)
52

53
        version_str = version_data[offset + 12:-1].decode("utf-8")
1✔
54

55
        self._version_number: _V
1✔
56
        if version_no < 0xFFFF:
1!
57
            try:
1✔
58
                self._version_number = (version_no // 100, version_no % 100, 0)
1✔
59
                self._name, self._hardware = version_str.split("/")
1✔
60
                self._version_string = version_str
1✔
61
            except ValueError as exception:
1✔
62
                raise SpinnmanInvalidParameterException(
1✔
63
                    "version_data", version_str,
64
                    f"Incorrect format: {exception}") from exception
65
        else:
66
            name_hardware, _, version = version_str.partition("\0")
×
67
            self._version_string = version
×
68
            matches = re.match(r"(\d+)\.(\d+)\.(\d+)", version)
×
69
            if matches is None:
×
70
                raise SpinnmanInvalidParameterException(
×
71
                    "version", version, "Cannot be parsed")
72
            self._version_number = cast(_V, tuple(
×
73
                map(int, matches.group(1, 2, 3))))
74
            self._name, self._hardware = name_hardware.rstrip("\0").split("/")
×
75

76
    @property
1✔
77
    def name(self) -> str:
1✔
78
        """
79
        The name of the software.
80

81
        :rtype: str
82
        """
83
        return self._name
1✔
84

85
    @property
1✔
86
    def version_number(self) -> _V:
1✔
87
        """
88
        The version number of the software.
89

90
        :rtype: tuple(int, int, int)
91
        """
92
        return self._version_number
1✔
93

94
    @property
1✔
95
    def hardware(self) -> str:
1✔
96
        """
97
        The hardware being run on.
98

99
        :rtype: str
100
        """
101
        return self._hardware
1✔
102

103
    @property
1✔
104
    def x(self) -> int:
1✔
105
        """
106
        The X-coordinate of the chip where the information was obtained.
107

108
        :rtype: int
109
        """
110
        return self._x
1✔
111

112
    @property
1✔
113
    def y(self) -> int:
1✔
114
        """
115
        The Y-coordinate of the chip where the information was obtained.
116

117
        :rtype: int
118
        """
119
        return self._y
1✔
120

121
    @property
1✔
122
    def p(self) -> int:
1✔
123
        """
124
        The processor ID of the processor where the information was obtained.
125

126
        :rtype: int
127
        """
128
        return self._p
1✔
129

130
    @property
1✔
131
    def build_date(self) -> int:
1✔
132
        """
133
        The build date of the software, in seconds since 1st January 1970.
134

135
        :rtype: int
136
        """
137
        return self._build_date
1✔
138

139
    @property
1✔
140
    def version_string(self) -> str:
1✔
141
        """
142
        The version information as text.
143

144
        :rtype: str
145
        """
146
        return self._version_string
1✔
147

148
    def __str__(self) -> str:
1✔
149
        return "[Version: {} {} at {}:{}:{}:{} (built {})]".format(
1✔
150
            self._name, self._version_string, self._hardware, self._x, self._y,
151
            self._p, asctime(localtime(self._build_date)))
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc