Update project configuration and dependencies
- Added `.vscode` to `.gitignore` to exclude Visual Studio Code settings. - Updated `pyproject.toml` to include `ruff` for linting and configured its settings. - Modified `uv.lock` to include `ruff` in both optional and development dependencies. - Refactored type hints in several files to use `str | None` for optional parameters. - Cleaned up unused imports and whitespace in various modules for improved code clarity.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from typing import Callable, Type
|
||||
from collections.abc import Callable
|
||||
|
||||
from .base import BaseDevice
|
||||
|
||||
@@ -7,7 +7,7 @@ device_registry = {}
|
||||
|
||||
def register_parser(
|
||||
name: list[str] | str,
|
||||
) -> Callable[[Type[BaseDevice]], Type[BaseDevice]]:
|
||||
) -> Callable[[type[BaseDevice]], type[BaseDevice]]:
|
||||
def wrapper(cls):
|
||||
name_list = []
|
||||
if isinstance(name, str):
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import xml.etree.ElementTree as ET
|
||||
from abc import ABC, abstractmethod
|
||||
from pathlib import Path
|
||||
|
||||
from ttp import ttp
|
||||
|
||||
from oxi.exception import OxiAPIError
|
||||
from oxi.interfaces.contract import Device
|
||||
import xml.etree.ElementTree as ET
|
||||
from oxi.interfaces.contract import Interfaces, System, Vlans
|
||||
from oxi.interfaces.contract import Device, Interfaces, System, Vlans
|
||||
|
||||
|
||||
class BaseDevice(ABC):
|
||||
@@ -40,7 +41,7 @@ class BaseDevice(ABC):
|
||||
|
||||
Raises:
|
||||
ValueError: if raw data cannot be validated by the contract.
|
||||
"""
|
||||
""" # noqa: E501
|
||||
return self.raw.get("vlans", [])
|
||||
|
||||
def interfaces(self) -> list[dict]:
|
||||
@@ -52,7 +53,7 @@ class BaseDevice(ABC):
|
||||
|
||||
Raises:
|
||||
ValueError: if raw data cannot be validated by the contract.
|
||||
"""
|
||||
""" # noqa: E501
|
||||
return self.raw.get("interfaces", [])
|
||||
|
||||
def system(self) -> dict:
|
||||
@@ -82,11 +83,7 @@ class BaseDevice(ABC):
|
||||
|
||||
def _validate_contract(self) -> dict:
|
||||
if self.raw is None:
|
||||
msg = (
|
||||
f"Node {self.name} not found"
|
||||
if self.name
|
||||
else "Node not found"
|
||||
)
|
||||
msg = f"Node {self.name} not found" if self.name else "Node not found"
|
||||
raise OxiAPIError(msg, status_code=404)
|
||||
system_data = self.system()
|
||||
interfaces_data = self._as_list(self.interfaces())
|
||||
@@ -99,8 +96,8 @@ class BaseDevice(ABC):
|
||||
if "vlans" in self._declared_sections:
|
||||
if "vlans" not in self.raw:
|
||||
raise ValueError(
|
||||
f"{self.__class__.__name__}: template '{self.template}' declares optional group "
|
||||
f"'vlans', but TTP did not return it."
|
||||
f"{self.__class__.__name__}: template '{self.template}' "
|
||||
f"declares optional group 'vlans', but TTP did not return it."
|
||||
)
|
||||
vlans_data = self._as_list(self.vlans())
|
||||
result["vlans"] = [Vlans(**item) for item in vlans_data]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from ipaddress import IPv4Address
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
|
||||
@@ -3,5 +3,5 @@ import pkgutil
|
||||
|
||||
package = __package__
|
||||
|
||||
for loader, module_name, is_pkg in pkgutil.iter_modules(__path__):
|
||||
for _, module_name, _ in pkgutil.iter_modules(__path__):
|
||||
importlib.import_module(f"{package}.{module_name}")
|
||||
|
||||
@@ -14,4 +14,4 @@ class H3C(BaseDevice):
|
||||
vlans.append(item)
|
||||
continue
|
||||
vlans.extend({"vlan_id": vlan_id} for vlan_id in vlan_ids)
|
||||
return vlans
|
||||
return vlans
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from ipaddress import ip_interface
|
||||
|
||||
from oxi.interfaces import register_parser
|
||||
from oxi.interfaces.base import BaseDevice
|
||||
from oxi.interfaces.utils import decode_utf
|
||||
|
||||
Reference in New Issue
Block a user