Skip to content

Commit f3f7535

Browse files
committed
WIP
1 parent 6124fab commit f3f7535

File tree

20 files changed

+57
-59
lines changed

20 files changed

+57
-59
lines changed

.hooks/pre-push

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,14 @@ dirname $(git ls-files "$repository_path/*/setup.py") | xargs -I {} isort --src-
9595
python_files=$(git ls-files '*.py')
9696

9797
echo "Running black.."
98-
echo $python_files
9998
black ${black_extra_args} $python_files
10099

101100
# do not run the rest of the script if running for fixing
102101
[ "$fixing" = true ] && exit 0
103102

104103
# Faster than pylint to check for issues
105104
echo "Running ruff.."
106-
ruff $python_files
105+
ruff check $python_files
107106

108107
echo "Running pylint.."
109108
pylint $python_files

core/libs/commonwealth/src/commonwealth/settings/bases/pydantic_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def load(self, file_path: pathlib.Path) -> None:
8282

8383
# Copy new content to settings class
8484
try:
85-
new = self.parse_obj(result)
85+
new = self.model_validate(result)
8686
self.__dict__.update(new.__dict__)
8787
except ValidationError as e:
8888
raise BadSettingsFile(f"Settings file contains invalid data: {e}") from e

core/pyproject.toml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,15 @@ disable_error_code = [
106106
]
107107

108108
[tool.ruff]
109-
ignore = [
110-
"A003", # BuiltinAttributeShadowing: Unnecessary restriction (not a source of confusion)
111-
"E501", # LineTooLong: Let black take care of
112-
"F401", # UnusedImport: We are using pylint 'ignore' comments for it
113-
"F821", # UndefinedName: We are using pylint 'ignore' comments for it
114-
"F841", # UnusedVariable: We are using pylint 'ignore' comments for it
115-
"E402", # ModuleImportNotAtTopOfFile: noqa doesn't work and this is required at some places
116-
]
109+
[tool.ruff.lint]
110+
ignore = [
111+
"A003", # BuiltinAttributeShadowing: Unnecessary restriction (not a source of confusion)
112+
"E501", # LineTooLong: Let black take care of
113+
"F401", # UnusedImport: We are using pylint 'ignore' comments for it
114+
"F821", # UndefinedName: We are using pylint 'ignore' comments for it
115+
"F841", # UnusedVariable: We are using pylint 'ignore' comments for it
116+
"E402", # ModuleImportNotAtTopOfFile: noqa doesn't work and this is required at some places
117+
]
117118

118119
[tool.pylint]
119120
[tool.pylint.master]
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
# pylint: disable=W0406
1+
# pylint: disable=import-self
22
from .app import application
3-
4-
__all__ = ["application"]
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# pylint: disable=W0406
1+
# pylint: disable=import-self
22
from .endpoints import endpoints_router_v1
33
from .index import index_router_v1
4-
5-
__all__ = ["endpoints_router_v1", "index_router_v1"]
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pylint: disable=W0406
21
from .index import index_router_v2
32

43
__all__ = ["index_router_v2"]

core/services/ardupilot_manager/mavlink_proxy/Endpoint.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Any, Dict, Iterable, Optional, Type
33

44
import validators
5-
from pydantic import constr, root_validator
5+
from pydantic import constr, model_validator
66
from pydantic.dataclasses import dataclass
77

88

@@ -32,10 +32,17 @@ class Endpoint:
3232
enabled: Optional[bool] = True
3333
overwrite_settings: Optional[bool] = False
3434

35-
@root_validator
35+
@model_validator(mode="before")
3636
@classmethod
3737
def is_mavlink_endpoint(cls: Type["Endpoint"], values: Any) -> Any:
38-
connection_type, place, argument = (values.get("connection_type"), values.get("place"), values.get("argument"))
38+
if isinstance(values, dict):
39+
connection_type, place, argument = (
40+
values.get("connection_type"),
41+
values.get("place"),
42+
values.get("argument"),
43+
)
44+
else:
45+
return values
3946

4047
if connection_type in [
4148
EndpointType.UDPServer,

core/services/cable_guy/api/manager.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import re
44
import subprocess
55
import time
6-
from ipaddress import ip_network, IPv4Address
6+
from ipaddress import ip_network, IPv4Address, IPv6Address
77
from socket import AddressFamily
88
from typing import Any, Dict, List, Optional, Set, Tuple, cast
99

@@ -685,11 +685,14 @@ def _parse_route(
685685
net = "0.0.0.0/0" if raw_route["family"] == AddressFamily.AF_INET else "::/0"
686686
else:
687687
net = f"{raw_destination}/{raw_prefixlen}"
688-
destination = IPvAnyNetwork(ip_network(net))
688+
destination = ip_network(net)
689689

690690
# Parse gateway
691691
gateway = (
692-
self.__class__._normalize_gateway(destination, IPvAnyAddress(raw_gateway))
692+
self.__class__._normalize_gateway(
693+
destination,
694+
IPv4Address(raw_gateway) if raw_route["family"] == AddressFamily.AF_INET else IPv6Address(raw_gateway),
695+
)
693696
if raw_gateway is not None
694697
else None
695698
)

core/services/cable_guy/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file is used to define general configurations for the app
22

3+
from ipaddress import ip_network
34
from typedefs import AddressMode, InterfaceAddress, NetworkInterface, Route
4-
from pydantic import IPvAnyNetwork
55

66
SERVICE_NAME = "cable-guy"
77

@@ -15,7 +15,7 @@
1515
],
1616
routes=[
1717
Route(
18-
destination=str(IPvAnyNetwork("224.0.0.0/4")),
18+
destination=str(ip_network("224.0.0.0/4")),
1919
gateway=None,
2020
priority=None,
2121
managed=True,

core/services/cable_guy/typedefs.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from enum import Enum
2-
from ipaddress import ip_network
3-
from typing import List, Optional
4-
5-
from pydantic import BaseModel, IPvAnyAddress, IPvAnyNetwork
2+
from ipaddress import ip_network, ip_address, IPv4Network, IPv6Network, IPv4Address, IPv6Address
3+
from typing import List, Optional, Union
4+
from pydantic import BaseModel
65

76

87
class AddressMode(str, Enum):
@@ -53,24 +52,24 @@ def __hash__(self) -> int:
5352

5453
# TODO: Remove this once we update self.destination type
5554
@property
56-
def destination_parsed(self) -> IPvAnyNetwork:
57-
return IPvAnyNetwork(self.destination)
55+
def destination_parsed(self) -> Union[IPv4Network, IPv6Network]:
56+
return ip_network(self.destination)
5857

5958
# TODO: Remove this once we update self.destination type
6059
@destination_parsed.setter
61-
def destination_parsed(self, ip: IPvAnyNetwork) -> None:
60+
def destination_parsed(self, ip: Union[IPv4Network, IPv6Network]) -> None:
6261
self.destination = str(ip)
6362

6463
# TODO: Remove this once we update self.next_hop type
6564
@property
66-
def next_hop_parsed(self) -> Optional[IPvAnyAddress]:
65+
def next_hop_parsed(self) -> Optional[Union[IPv4Address, IPv6Address]]:
6766
if self.gateway is None:
6867
return None
69-
return IPvAnyAddress(self.gateway)
68+
return ip_address(self.gateway)
7069

7170
# TODO: Remove this once we update self.next_hop type
7271
@next_hop_parsed.setter
73-
def next_hop_parsed(self, ip: Optional[IPvAnyAddress]) -> None:
72+
def next_hop_parsed(self, ip: Optional[Union[IPv4Address, IPv6Address]]) -> None:
7473
self.gateway = str(ip) if ip else None
7574

7675
@property

0 commit comments

Comments
 (0)