Skip to content

Commit b766d46

Browse files
committed
Replace pendumum with whenever
1 parent 6b333ec commit b766d46

File tree

17 files changed

+353
-257
lines changed

17 files changed

+353
-257
lines changed

backend/infrahub/core/diff/model/path.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from neo4j.graph import Node as Neo4jNode
2121
from neo4j.graph import Path as Neo4jPath
2222
from neo4j.graph import Relationship as Neo4jRelationship
23-
from pendulum import Interval
23+
from whenever import TimeDelta
2424

2525
from infrahub.graphql.initialization import GraphqlContext
2626

@@ -417,7 +417,7 @@ def __hash__(self) -> int:
417417
return hash(self.uuid)
418418

419419
@property
420-
def time_range(self) -> Interval:
420+
def time_range(self) -> TimeDelta:
421421
return self.to_time.obj - self.from_time.obj
422422

423423
def update_metadata(
@@ -447,7 +447,7 @@ def __hash__(self) -> int:
447447
return hash(self.uuid)
448448

449449
@property
450-
def time_range(self) -> Interval:
450+
def time_range(self) -> TimeDelta:
451451
return self.to_time.obj - self.from_time.obj
452452

453453
def get_nodes_without_parents(self) -> set[EnrichedDiffNode]:

backend/infrahub/core/timestamp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
from infrahub_sdk.timestamp import Timestamp as BaseTimestamp
66

77
if TYPE_CHECKING:
8-
from pendulum.datetime import DateTime
8+
from datetime import datetime
99

1010

1111
class Timestamp(BaseTimestamp):
12-
async def to_graphql(self, *args: Any, **kwargs: Any) -> DateTime: # noqa: ARG002
13-
return self.obj
12+
async def to_graphql(self, *args: Any, **kwargs: Any) -> datetime: # noqa: ARG002
13+
return self.to_datetime()
1414

1515
def get_query_filter_path(self, rel_name: str = "r") -> tuple[str, dict]:
1616
"""

backend/infrahub/graphql/queries/diff/tree.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def to_diff_node(self, enriched_node: EnrichedDiffNode, graphql_context: Graphql
193193
label=enriched_node.label,
194194
status=enriched_node.action,
195195
parent=parent,
196-
last_changed_at=enriched_node.changed_at.obj if enriched_node.changed_at else None,
196+
last_changed_at=enriched_node.changed_at.to_datetime() if enriched_node.changed_at else None,
197197
path_identifier=enriched_node.path_identifier,
198198
attributes=diff_attributes,
199199
relationships=diff_relationships,
@@ -219,7 +219,7 @@ def to_diff_attribute(
219219
diff_prop.conflict = None
220220
return DiffAttribute(
221221
name=enriched_attribute.name,
222-
last_changed_at=enriched_attribute.changed_at.obj,
222+
last_changed_at=enriched_attribute.changed_at.to_datetime(),
223223
status=enriched_attribute.action,
224224
path_identifier=enriched_attribute.path_identifier,
225225
properties=diff_properties,
@@ -241,7 +241,9 @@ def to_diff_relationship(
241241
return DiffRelationship(
242242
name=enriched_relationship.name,
243243
label=enriched_relationship.label,
244-
last_changed_at=enriched_relationship.changed_at.obj if enriched_relationship.changed_at else None,
244+
last_changed_at=enriched_relationship.changed_at.to_datetime()
245+
if enriched_relationship.changed_at
246+
else None,
245247
status=enriched_relationship.action,
246248
cardinality=enriched_relationship.cardinality,
247249
path_identifier=enriched_relationship.path_identifier,
@@ -263,7 +265,7 @@ def to_diff_relationship_element(
263265
enriched_conflict=enriched_element.conflict, graphql_context=graphql_context
264266
)
265267
return DiffSingleRelationship(
266-
last_changed_at=enriched_element.changed_at.obj,
268+
last_changed_at=enriched_element.changed_at.to_datetime(),
267269
status=enriched_element.action,
268270
peer_id=enriched_element.peer_id,
269271
peer_label=enriched_element.peer_label,
@@ -287,7 +289,7 @@ def to_diff_property(
287289
)
288290
return DiffProperty(
289291
property_type=enriched_property.property_type.value,
290-
last_changed_at=enriched_property.changed_at.obj,
292+
last_changed_at=enriched_property.changed_at.to_datetime(),
291293
previous_value=enriched_property.previous_value,
292294
new_value=enriched_property.new_value,
293295
previous_label=enriched_property.previous_label,
@@ -306,13 +308,13 @@ def to_diff_conflict(
306308
uuid=enriched_conflict.uuid,
307309
base_branch_action=enriched_conflict.base_branch_action,
308310
base_branch_value=enriched_conflict.base_branch_value,
309-
base_branch_changed_at=enriched_conflict.base_branch_changed_at.obj
311+
base_branch_changed_at=enriched_conflict.base_branch_changed_at.to_datetime()
310312
if enriched_conflict.base_branch_changed_at
311313
else None,
312314
base_branch_label=enriched_conflict.base_branch_label,
313315
diff_branch_action=enriched_conflict.diff_branch_action,
314316
diff_branch_value=enriched_conflict.diff_branch_value,
315-
diff_branch_changed_at=enriched_conflict.diff_branch_changed_at.obj
317+
diff_branch_changed_at=enriched_conflict.diff_branch_changed_at.to_datetime()
316318
if enriched_conflict.diff_branch_changed_at
317319
else None,
318320
diff_branch_label=enriched_conflict.diff_branch_label,
@@ -426,7 +428,10 @@ async def resolve(
426428
# take the one with the longest duration that covers multiple branches
427429
enriched_diff = sorted(
428430
enriched_diffs,
429-
key=lambda d: (d.base_branch_name != d.diff_branch_name, d.to_time.obj - d.from_time.obj),
431+
key=lambda d: (
432+
d.base_branch_name != d.diff_branch_name,
433+
d.to_time.to_datetime() - d.from_time.to_datetime(),
434+
),
430435
reverse=True,
431436
)[0]
432437
else:
@@ -485,8 +490,8 @@ async def summary(
485490
diff_tree_summary = DiffTreeSummary(
486491
base_branch=base_branch.name,
487492
diff_branch=diff_branch.name,
488-
from_time=summary.from_time.obj,
489-
to_time=summary.to_time.obj,
493+
from_time=summary.from_time.to_datetime(),
494+
to_time=summary.to_time.to_datetime(),
490495
**summary.model_dump(exclude={"from_time", "to_time"}),
491496
)
492497
full_fields = await extract_fields(info.field_nodes[0].selection_set)

backend/infrahub/task_manager/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ def from_filters(
167167
) -> InfrahubEventFilter:
168168
occurred_filter = {}
169169
if since:
170-
occurred_filter["since"] = Timestamp(since.isoformat()).obj
170+
occurred_filter["since"] = Timestamp(since.isoformat()).to_datetime()
171171

172172
if until:
173-
occurred_filter["until"] = Timestamp(until.isoformat()).obj
173+
occurred_filter["until"] = Timestamp(until.isoformat()).to_datetime()
174174

175175
if occurred_filter:
176176
filters = cls(occurred=EventOccurredFilter(**occurred_filter))

backend/tests/integration/user_workflows/test_user_worflow.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import pendulum
21
import pytest
32
from deepdiff import DeepDiff
3+
from whenever import Instant
44

55
from infrahub.database import InfrahubDatabase
66
from infrahub.graphql.manager import GraphQLSchemaManager
@@ -251,7 +251,7 @@ async def test_query_all_devices(self, test_client, integration_helper):
251251
if device["node"]["name"]["value"] == "spine1":
252252
state.data["spine1_id"] = device["node"]["id"]
253253
# Initialize the start time
254-
state.data["time_start"] = pendulum.now(tz="UTC")
254+
state.data["time_start"] = Instant.now()
255255

256256
async def test_query_spine1_loobpack0(self, test_client, integration_helper):
257257
"""
@@ -374,7 +374,7 @@ async def test_update_intf_description_branch1(
374374

375375
assert intfs[0]["node"]["description"]["value"] == new_description
376376

377-
state.data["time_after_intf_update_branch1"] = pendulum.now("UTC").to_iso8601_string()
377+
state.data["time_after_intf_update_branch1"] = Instant.now().format_common_iso()
378378

379379
async def test_update_intf_description_main(self, test_client, integration_helper):
380380
"""
@@ -781,7 +781,7 @@ async def test_query_spine1_lo0_at_start_time(self, test_client, integration_hel
781781
"intf_name": intf_name,
782782
},
783783
},
784-
params={"at": state.data["time_start"].to_iso8601_string()},
784+
params={"at": state.data["time_start"].format_common_iso()},
785785
headers=headers,
786786
)
787787
assert response.status_code == 200

0 commit comments

Comments
 (0)