Skip to content

Commit 34815a2

Browse files
committed
Package updates & linter/typing fixes
- Removed empty config.cfg hack (it was an ancient workaround for a problem that no longer exists) - Updated ruff formatter config to format as python3.12 (the version of python used by the project) - Fixed some outdated readme text - Upgraded mypy version - Fixed type hint complaints from mypy - Updated pytest & pytest plugin versions (fixes several noisy deprecation warnings)
1 parent 65f34f3 commit 34815a2

File tree

147 files changed

+672
-725
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+672
-725
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
*<p style="text-align: center;">DataOps Observability is part of DataKitchen's Open Source Data Observability. DataOps Observability monitors every data journey from data source to customer value, from any team development environment into production, across every tool, team, environment, and customer so that problems are detected, localized, and understood immediately.</p>*
77

8-
[![DatKitchen Open Source Data Observability](https://datakitchen.io/wp-content/uploads/2024/04/both-products.png)](https://datakitchen.storylane.io/share/g01ss0plyamz)
8+
[![DataKitchen Open Source Data Observability](https://datakitchen.io/wp-content/uploads/2024/04/both-products.png)](https://datakitchen.storylane.io/share/g01ss0plyamz)
99
[Interactive Product Tour](https://datakitchen.storylane.io/share/g01ss0plyamz)
1010

1111
## Developer Setup
@@ -100,9 +100,7 @@ We enforce the use of certain linting tools. To not get caught by the build-syst
100100

101101
The following hooks are enabled in pre-commit:
102102

103-
- `black`: The black formatter is enforced on the project. We use a basic configuration. Ideally this should solve any and all
104-
formatting questions we might encounter.
105-
- `isort`: the isort import-sorter is enforced on the project. We use it with the `black` profile.
103+
- `ruff`: Handles code formatting, import sorting, and linting
106104

107105
To enable pre-commit from within your virtual environment, simply run:
108106

agent_api/config/defaults.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
"""
66

77
import os
8-
from typing import Optional
98

109
# Flask specific settings: https://flask.palletsprojects.com/en/latest/config/#builtin-configuration-values
1110
from common.entities import Service
1211

13-
PROPAGATE_EXCEPTIONS: Optional[bool] = None
14-
SERVER_NAME: Optional[str] = os.environ.get("AGENT_API_HOSTNAME") # Use flask defaults if none set
12+
PROPAGATE_EXCEPTIONS: bool | None = None
13+
SERVER_NAME: str | None = os.environ.get("AGENT_API_HOSTNAME") # Use flask defaults if none set
1514
USE_X_SENDFILE: bool = False # If we serve files enable this in production settings when webserver support configured
1615

1716
# Application settings

agent_api/config/local.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Optional
2-
31
# Flask specific settings: https://flask.palletsprojects.com/en/latest/config/#builtin-configuration-values
4-
PROPAGATE_EXCEPTIONS: Optional[bool] = True
2+
PROPAGATE_EXCEPTIONS: bool | None = True
53
SECRET_KEY: str = "NOT_VERY_SECRET"

agent_api/config/minikube.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Optional
2-
31
# Flask specific settings: https://flask.palletsprojects.com/en/latest/config/#builtin-configuration-values
4-
TESTING: Optional[bool] = True
2+
TESTING: bool | None = True
53
SECRET_KEY: str = "NOT_VERY_SECRET"

agent_api/endpoints/v1/heartbeat.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
2-
from datetime import datetime, timezone
2+
from datetime import datetime, UTC
33
from http import HTTPStatus
4-
from typing import Optional, Union, cast
4+
from typing import Union, cast
55
from uuid import UUID
66

77
from flask import Response, g, make_response
@@ -23,7 +23,7 @@ def _update_or_create(
2323
version: str,
2424
project_id: Union[str, UUID],
2525
latest_heartbeat: datetime,
26-
latest_event_timestamp: Optional[datetime],
26+
latest_event_timestamp: datetime | None,
2727
) -> None:
2828
try:
2929
agent = Agent.select().where(Agent.key == key, Agent.tool == tool, Agent.project_id == project_id).get()
@@ -57,7 +57,7 @@ class Heartbeat(BaseView):
5757

5858
def post(self) -> Response:
5959
data = self.parse_body(schema=HeartbeatSchema())
60-
data["latest_heartbeat"] = datetime.now(tz=timezone.utc)
60+
data["latest_heartbeat"] = datetime.now(tz=UTC)
6161
data["project_id"] = g.project.id
6262
_update_or_create(**data)
6363
return make_response("", HTTPStatus.NO_CONTENT)

agent_api/tests/integration/v1_endpoints/test_heartbeat.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime, timezone
1+
from datetime import datetime, timezone, UTC
22
from http import HTTPStatus
33

44
import pytest
@@ -9,7 +9,7 @@
99

1010
@pytest.mark.integration
1111
def test_agent_heartbeat(client, database_ctx, headers):
12-
last_event_timestamp = datetime(2023, 10, 20, 4, 42, 42, tzinfo=timezone.utc)
12+
last_event_timestamp = datetime(2023, 10, 20, 4, 42, 42, tzinfo=UTC)
1313
data = {
1414
"key": "test-key",
1515
"tool": "test-tool",
@@ -35,7 +35,7 @@ def test_agent_heartbeat_no_event_timestamp(client, database_ctx, headers):
3535

3636
@pytest.mark.integration
3737
def test_agent_heartbeat_update(client, database_ctx, headers):
38-
last_event_timestamp = datetime(2023, 10, 20, 4, 42, 42, tzinfo=timezone.utc)
38+
last_event_timestamp = datetime(2023, 10, 20, 4, 42, 42, tzinfo=UTC)
3939
data = {
4040
"key": "test-key",
4141
"tool": "test-tool",
@@ -47,7 +47,7 @@ def test_agent_heartbeat_update(client, database_ctx, headers):
4747
assert HTTPStatus.NO_CONTENT == response_1.status_code, response_1.json
4848

4949
# The latest_event_timestamp should be older than "now"
50-
now = datetime.now(timezone.utc)
50+
now = datetime.now(UTC)
5151
agent_1 = Agent.select().get()
5252
assert agent_1.latest_heartbeat < now
5353
assert agent_1.status == AgentStatus.ONLINE
@@ -62,7 +62,7 @@ def test_agent_heartbeat_update(client, database_ctx, headers):
6262

6363
@pytest.mark.integration
6464
def test_agent_heartbeat_existing_update(client, database_ctx, headers):
65-
last_event_timestamp = datetime(2023, 10, 20, 4, 42, 42, tzinfo=timezone.utc)
65+
last_event_timestamp = datetime(2023, 10, 20, 4, 42, 42, tzinfo=UTC)
6666
data_1 = {
6767
"key": "test-key",
6868
"tool": "test-tool",
@@ -79,7 +79,7 @@ def test_agent_heartbeat_existing_update(client, database_ctx, headers):
7979

8080
data_2 = data_1.copy()
8181
data_2["version"] = "12.0.3"
82-
data_2["latest_event_timestamp"] = datetime(2023, 10, 20, 4, 44, 44, tzinfo=timezone.utc).isoformat()
82+
data_2["latest_event_timestamp"] = datetime(2023, 10, 20, 4, 44, 44, tzinfo=UTC).isoformat()
8383

8484
response_2 = client.post("/agent/v1/heartbeat", json=data_2, headers=headers)
8585
assert HTTPStatus.NO_CONTENT == response_2.status_code, response_2.json

cli/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from argparse import ArgumentParser
55
from logging.config import dictConfig
66
from pathlib import Path
7-
from typing import Any, Optional
7+
from typing import Any
88
from collections.abc import Callable
99

1010
from log_color import ColorFormatter, ColorStripper
@@ -80,7 +80,7 @@ def __init__(self, **kwargs: Any) -> None:
8080
LOG.info("#g<\u2714> Established #c<%s> connection to #c<%s>", DB.obj.__class__.__name__, DB.obj.database)
8181

8282

83-
def logging_init(*, level: str, logfile: Optional[str] = None) -> None:
83+
def logging_init(*, level: str, logfile: str | None = None) -> None:
8484
"""Given the log level and an optional logging file location, configure all logging."""
8585
# Don't bother with a file handler if we're not logging to a file
8686
handlers = ["console", "filehandler"] if logfile else ["console"]

cli/entry_points/database_schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import re
22
from argparse import ArgumentParser
3-
from typing import Any, Optional
3+
from typing import Any
44
from re import Pattern
55
from collections.abc import Iterable
66

@@ -19,7 +19,7 @@ class MysqlPrintDatabase(MySQLDatabase):
1919
def __init__(self) -> None:
2020
super().__init__("")
2121

22-
def execute_sql(self, sql: str, params: Optional[Iterable[Any]] = None, commit: Optional[bool] = None) -> None:
22+
def execute_sql(self, sql: str, params: Iterable[Any] | None = None, commit: bool | None = None) -> None:
2323
if params:
2424
raise Exception(f"Params are not expected to be needed to run DDL SQL, but found {params}")
2525
if match := self._create_table_re.match(sql):

cli/entry_points/gen_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import time
88
from argparse import Action, ArgumentParser, Namespace
99
from datetime import datetime
10-
from typing import Any, Optional, Union
10+
from typing import Any, Union
1111
from collections.abc import Sequence
1212

1313
from requests_extensions import get_session
@@ -90,7 +90,7 @@ def __call__(
9090
parser: ArgumentParser,
9191
namespace: Namespace,
9292
values: Union[str, Sequence[Any], None],
93-
option_string: Optional[str] = None,
93+
option_string: str | None = None,
9494
) -> None:
9595
event_data = {}
9696
remove_fields = []

cli/entry_points/graph_schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
from argparse import ArgumentParser
44
from pathlib import Path
5+
from typing import Any
56

67
from jinja2 import Environment, FileSystemLoader
78
from peewee import Field, ForeignKeyField, ManyToManyField, Model
@@ -54,7 +55,7 @@ def subcmd_entry_point(self) -> None:
5455
dot_parts = [head.render({})]
5556

5657
# Initial context/config
57-
model_context = []
58+
model_context: list[dict[str, Any]] = []
5859

5960
LOG.info("#m<Graphing models...>")
6061
for name, model in model_map.items():

0 commit comments

Comments
 (0)