Skip to content

Commit 0a48455

Browse files
committed
Merge remote-tracking branch 'origin/SpiNNcloud_merge' into SpiNNcloud_merge
2 parents d511119 + b2b20c2 commit 0a48455

6 files changed

Lines changed: 70 additions & 27 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ SpiNNUtils
77
This provides basic utility functions and classes to other parts of SpiNNaker's
88
tooling. Nothing in here knows anything about SpiNNaker functionality.
99

10-
1110
`spinn_utilities.abstract_base`
1211
-------------------------------
1312
Provides a simplified (and faster) version of the standard Python Abstract

spinn_utilities/data/utils_data_view.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
SimulatorShutdownException, UnexpectedStateChange)
2525
from spinn_utilities.executable_finder import ExecutableFinder
2626
from spinn_utilities.log import FormatAdapter
27+
from spinn_utilities import logger_utils
2728
from spinn_utilities.make_tools.log_sqllite_database import LogSqlLiteDatabase
2829
from .data_status import DataStatus
2930
from .reset_status import ResetStatus
@@ -783,7 +784,8 @@ def get_log_database_path(cls, database_key: str) -> Optional[str]:
783784
if 'RUNNER_ENVIRONMENT' in os.environ:
784785
raise ValueError(f"No logs database found for {database_key=}")
785786
else:
786-
logger.error(f"No logs database found for {database_key=}")
787+
logger_utils.error_once(
788+
logger, f"No logs database found for {database_key=}")
787789
return None
788790
return cls.__data._log_database_paths[database_key]
789791

spinn_utilities/make_tools/file_converter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ def convert(self, src_dir: str, dest_dir: str, file_name: str) -> None:
118118
if not os.path.exists(dest_dir):
119119
os.makedirs(dest_dir)
120120
destination = os.path.join(dest_dir, file_name)
121+
if os.path.exists(destination):
122+
if os.path.getmtime(destination) > os.path.getmtime(self._src):
123+
# Destination is newer than source so skip
124+
return
121125
directory_id = self._log_database.get_directory_id(src_dir, dest_dir)
122126
self._log_file_id = self._log_database.get_file_id(
123127
directory_id, file_name)

spinn_utilities/ranged/abstract_list.py

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -518,11 +518,16 @@ def __add__(self, other: Union[float, AbstractList[float]]
518518
:raises TypeError:
519519
"""
520520
if isinstance(other, AbstractList):
521-
d_operation: Callable[[Any, float], float] = lambda x, y: x + y
522-
return DualList(
523-
left=self, right=other, operation=d_operation)
521+
522+
def d_operation(x: Any, y: float) -> float:
523+
return x + y
524+
525+
return DualList(left=self, right=other, operation=d_operation)
524526
if is_number(other):
525-
s_operation: Callable[[Any], float] = lambda x: x + other
527+
528+
def s_operation(x: Any) -> float:
529+
return x + other
530+
526531
return SingleList(a_list=self, operation=s_operation)
527532
raise TypeError("__add__ operation only supported for other "
528533
"RangedLists and numerical Values")
@@ -540,11 +545,16 @@ def __sub__(self, other: Union[float, AbstractList[float]]
540545
:raises TypeError:
541546
"""
542547
if isinstance(other, AbstractList):
543-
d_operation: Callable[[Any, float], float] = lambda x, y: x - y
544-
return DualList(
545-
left=self, right=other, operation=d_operation)
548+
549+
def d_operation(x: Any, y: float) -> float:
550+
return x - y
551+
552+
return DualList(left=self, right=other, operation=d_operation)
546553
if is_number(other):
547-
s_operation: Callable[[Any], float] = lambda x: x - other
554+
555+
def s_operation(x: Any) -> float:
556+
return x - other
557+
548558
return SingleList(a_list=self, operation=s_operation)
549559
raise TypeError("__sub__ operation only supported for other "
550560
"RangedLists and numerical Values")
@@ -562,11 +572,16 @@ def __mul__(self, other: Union[float, AbstractList[float]]
562572
:raises TypeError:
563573
"""
564574
if isinstance(other, AbstractList):
565-
d_operation: Callable[[Any, float], float] = lambda x, y: x * y
566-
return DualList(
567-
left=self, right=other, operation=d_operation)
575+
576+
def d_operation(x: Any, y: float) -> float:
577+
return x * y
578+
579+
return DualList(left=self, right=other, operation=d_operation)
568580
if is_number(other):
569-
s_operation: Callable[[Any], float] = lambda x: x * other
581+
582+
def s_operation(x: Any) -> float:
583+
return x * other
584+
570585
return SingleList(a_list=self, operation=s_operation)
571586
raise TypeError("__mul__ operation only supported for other "
572587
"RangedLists and numerical Values")
@@ -585,13 +600,18 @@ def __truediv__(self, other: Union[float, AbstractList[float]]
585600
:raises TypeError:
586601
"""
587602
if isinstance(other, AbstractList):
588-
d_operation: Callable[[Any, float], float] = lambda x, y: x / y
589-
return DualList(
590-
left=self, right=other, operation=d_operation)
603+
604+
def d_operation(x: Any, y: float) -> float:
605+
return x / y
606+
607+
return DualList(left=self, right=other, operation=d_operation)
591608
if is_number(other):
592609
if _is_zero(other):
593610
raise ZeroDivisionError()
594-
s_operation: Callable[[Any], float] = lambda x: x / other
611+
612+
def s_operation(x: Any) -> float:
613+
return x / other
614+
595615
return SingleList(a_list=self, operation=s_operation)
596616
raise TypeError("__truediv__ operation only supported for other "
597617
"RangedLists and numerical Values")
@@ -607,19 +627,25 @@ def __floordiv__(self, other: Union[float, AbstractList[float]]
607627
:raises TypeError:
608628
"""
609629
if isinstance(other, AbstractList):
610-
d_operation: Callable[[Any, float], int] = lambda x, y: int(x // y)
611-
return DualList(
612-
left=self, right=other, operation=d_operation)
630+
631+
def d_operation(x: Any, y: float) -> int:
632+
return int(x // y)
633+
634+
return DualList(left=self, right=other, operation=d_operation)
613635
if is_number(other):
614636
if _is_zero(other):
615637
raise ZeroDivisionError()
616-
s_operation: Callable[[Any], int] = lambda x: int(x / other)
638+
639+
def s_operation(x: Any) -> int:
640+
return int(x / other)
641+
617642
return SingleList(a_list=self, operation=s_operation)
618-
raise TypeError("__floordiv__ operation only supported for other "
619-
"RangedLists and numerical Values")
643+
raise TypeError(
644+
"__floordiv__ operation only supported for other "
645+
"RangedLists and numerical Values"
646+
)
620647

621-
def apply_operation(
622-
self, operation: Callable[[T], U]) -> AbstractList[U]:
648+
def apply_operation(self, operation: Callable[[T], U]) -> AbstractList[U]:
623649
"""
624650
Applies a function on the list to create a new one.
625651
The values of the new list are created on the fly so any changes

unittests/make_tools/test_file_convert.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import os
1616
import pytest
17+
from pathlib import Path
1718
import sys
1819
import tempfile
1920
import unittest
@@ -39,9 +40,10 @@ def test_convert(self) -> None:
3940
file_name = "weird,file.c"
4041
src = os.path.join(path, "mock_src")
4142
dest = os.path.join(path, "modified_src")
42-
file_converter.convert(src, dest, file_name)
4343
src_f = os.path.join(src, file_name)
4444
dest_f = os.path.join(dest, file_name)
45+
Path(src_f).touch()
46+
file_converter.convert(src, dest, file_name)
4547
src_lines = sum(1 for line in open(src_f))
4648
modified_lines = sum(1 for line in open(dest_f))
4749
self.assertEqual(src_lines, modified_lines)
@@ -99,6 +101,7 @@ def test_split_fail(self) -> None:
99101
src = os.path.join(path, "mistakes")
100102
dest = os.path.join(path, "modified_src")
101103
try:
104+
Path(src, "bad_comma.c").touch()
102105
file_converter.convert(src, dest, "bad_comma.c")
103106
assert False
104107
except Exception as ex1:
@@ -116,6 +119,7 @@ def test_format_fail(self) -> None:
116119
src = os.path.join(path, "mistakes")
117120
dest = os.path.join(path, "modified_src")
118121
try:
122+
Path(src, "bad_format.c").touch()
119123
file_converter.convert(src, dest, "bad_format.c")
120124
assert False
121125
except Exception as ex1:
@@ -131,6 +135,7 @@ def test_unclosed_log(self) -> None:
131135
src = os.path.join(path, "mistakes")
132136
dest = os.path.join(path, "modified_src")
133137
try:
138+
Path(src, "unclosed.c").touch()
134139
file_converter.convert(src, dest, "unclosed.c")
135140
assert False
136141
except Exception as ex1:
@@ -149,6 +154,7 @@ def test_semi(self) -> None:
149154
src = os.path.join(path, "mistakes")
150155
dest = os.path.join(path, "modified_src")
151156
try:
157+
Path(src, "semi.c").touch()
152158
file_converter.convert(src, dest, "semi.c")
153159
assert False
154160
except Exception as ex1:
@@ -167,6 +173,7 @@ def test_open(self) -> None:
167173
src = os.path.join(path, "mistakes")
168174
dest = os.path.join(path, "modified_src")
169175
try:
176+
Path(src, "open.c").touch()
170177
file_converter.convert(src, dest, "open.c")
171178
assert False
172179
except Exception as ex1:
@@ -184,6 +191,7 @@ def test_too_few(self) -> None:
184191
src = os.path.join(path, "mistakes")
185192
dest = os.path.join(path, "modified_src")
186193
try:
194+
Path(src, "too_few.c").touch()
187195
file_converter.convert(src, dest, "too_few.c")
188196
assert False
189197
except Exception as ex1:
@@ -203,6 +211,7 @@ def test_too_many(self) -> None:
203211
src = os.path.join(path, "mistakes")
204212
dest = os.path.join(path, "modified_src")
205213
try:
214+
Path(src, "too_many.c").touch()
206215
file_converter.convert(src, dest, "too_many.c")
207216
assert False
208217
except Exception as ex1:

unittests/make_tools/test_replacer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import math
3030
import os
3131
import pytest
32+
import shutil
3233
import tempfile
3334
import unittest
3435

@@ -49,6 +50,8 @@ def setUpClass(cls) -> None:
4950
global logs_database
5051
src = os.path.join(PATH, "mock_src")
5152
dest = os.path.join(PATH, "modified_src")
53+
if os.path.exists(dest):
54+
shutil.rmtree(dest)
5255
logs_database = convert(src, dest, PATH, "R")
5356

5457
@pytest.mark.xdist_group(name="mock_src")

0 commit comments

Comments
 (0)