Skip to content

Commit a15a808

Browse files
authored
Merge pull request #5820 from opsmill/dga-20250223-pendulum-whenever
Replace pendulum with whenever
2 parents 1dafac2 + e149a20 commit a15a808

File tree

21 files changed

+362
-264
lines changed

21 files changed

+362
-264
lines changed

backend/infrahub/core/attribute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import netaddr
99
import ujson
10-
from infrahub_sdk.timestamp import TimestampFormatError
10+
from infrahub_sdk.exceptions import TimestampFormatError
1111
from infrahub_sdk.utils import is_valid_url
1212
from infrahub_sdk.uuidt import UUIDT
1313
from pydantic import BaseModel, Field

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

Lines changed: 5 additions & 5 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,8 +417,8 @@ def __hash__(self) -> int:
417417
return hash(self.uuid)
418418

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

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

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

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

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/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from fastapi.responses import RedirectResponse
1515
from fastapi.staticfiles import StaticFiles
1616
from fastapi.templating import Jinja2Templates
17-
from infrahub_sdk.timestamp import TimestampFormatError
17+
from infrahub_sdk.exceptions import TimestampFormatError
1818
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
1919
from opentelemetry.trace import Span
2020
from pydantic import ValidationError

backend/infrahub/task_manager/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,10 @@ def from_filters(
180180
) -> InfrahubEventFilter:
181181
occurred_filter = {}
182182
if since:
183-
occurred_filter["since"] = Timestamp(since.isoformat()).obj
183+
occurred_filter["since"] = Timestamp(since.isoformat()).to_datetime()
184184

185185
if until:
186-
occurred_filter["until"] = Timestamp(until.isoformat()).obj
186+
occurred_filter["until"] = Timestamp(until.isoformat()).to_datetime()
187187

188188
if occurred_filter:
189189
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)