Skip to content

Commit e1d43d4

Browse files
authored
fix: sonar complaint about timestamp (#2152)
* fix: sonar complaint re: _timestamp Move this time-dependent expression out of the class body and into a method. Signed-off-by: degenaro <lou.degenaro@gmail.com> * fix: get_timestamp Signed-off-by: degenaro <lou.degenaro@gmail.com> * fix: don't duplicate code Signed-off-by: degenaro <lou.degenaro@gmail.com> * fix: formatting Signed-off-by: degenaro <lou.degenaro@gmail.com> * fix: run hatch version Signed-off-by: degenaro <lou.degenaro@gmail.com> * fix: workflow caching issues Signed-off-by: degenaro <lou.degenaro@gmail.com> * undo npm change Signed-off-by: degenaro <lou.degenaro@gmail.com> * fix hatch cache issue Signed-off-by: degenaro <lou.degenaro@gmail.com> * fix hatch caching issue Signed-off-by: degenaro <lou.degenaro@gmail.com> --------- Signed-off-by: degenaro <lou.degenaro@gmail.com>
1 parent 7088b3f commit e1d43d4

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

.github/workflows/python-test.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ jobs:
141141
- name: Install hatch
142142
run: |
143143
make develop
144+
- name: Recreate hatch test environment
145+
shell: bash
146+
run: |
147+
hatch env remove hatch-test.py${{ matrix.python-version }} 2>/dev/null || true
148+
hatch env create hatch-test.py${{ matrix.python-version }}
144149
- name: gen OSCAL models
145150
run: |
146151
make gen-oscal
@@ -195,6 +200,11 @@ jobs:
195200
- name: Install hatch
196201
run: |
197202
pip install hatch "virtualenv>=20.26.6,<21" # Pin until hatch supports virtualenv 21.x
203+
- name: Recreate hatch test environment
204+
shell: bash
205+
run: |
206+
hatch env remove hatch-test.py${{ matrix.python-version }} 2>/dev/null || true
207+
hatch env create hatch-test.py${{ matrix.python-version }}
198208
- name: Run tests
199209
if: steps.core-version.outputs.core != 'true'
200210
run: |

trestle/transforms/transformer_factory.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ class TransformerBase(ABC):
2828
"""Abstract base interface for all transformers."""
2929

3030
# the current time for consistent timestamping
31-
_timestamp = datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0).isoformat()
31+
_timestamp = None
32+
33+
def __init__(self) -> None:
34+
"""Initialize the transformer and set timestamp if not already set."""
35+
TransformerBase.get_timestamp()
3236

3337
@staticmethod
3438
def set_timestamp(value: str) -> None:
@@ -39,6 +43,8 @@ def set_timestamp(value: str) -> None:
3943
@staticmethod
4044
def get_timestamp() -> str:
4145
"""Get the default timestamp value."""
46+
if TransformerBase._timestamp is None:
47+
TransformerBase._timestamp = datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0).isoformat()
4248
return TransformerBase._timestamp
4349

4450
@abstractmethod

0 commit comments

Comments
 (0)