From eef2517480eba331789021e8ad0fdc668707403b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Mon, 8 Apr 2024 12:28:53 +0200 Subject: [PATCH] apply formatting with current black/isort versions --- fmt.sh | 10 ++++++++-- src/capport/database.py | 6 +++--- src/capport/stats.py | 10 +++++----- src/capport/utils/nft_socket.py | 8 +++++--- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/fmt.sh b/fmt.sh index 9b9a5bb..1f53e6c 100755 --- a/fmt.sh +++ b/fmt.sh @@ -3,5 +3,11 @@ self=$(dirname "$(readlink -f "$0")") cd "${self}" -python3 -m black src -python3 -m isort src +if [ -d venv ]; then + python=venv/bin/python3 +else + python=python3 +fi + +"${python}" -m black src +"${python}" -m isort src diff --git a/src/capport/database.py b/src/capport/database.py index 9a26458..d769331 100644 --- a/src/capport/database.py +++ b/src/capport/database.py @@ -142,9 +142,9 @@ class Database: self._macs: dict[cptypes.MacAddress, MacEntry] = {} self._state_filename = state_filename self._changed_since_last_cleanup = False - self._send_changes: trio.MemorySendChannel[ - capport.comm.message.MacStates | list[capport.comm.message.MacStates], - ] | None = None + self._send_changes: ( + trio.MemorySendChannel[capport.comm.message.MacStates | list[capport.comm.message.MacStates],] | None + ) = None @contextlib.asynccontextmanager async def make_changes(self) -> typing.AsyncGenerator[PendingUpdates, None]: diff --git a/src/capport/stats.py b/src/capport/stats.py index 55ba4cc..8ac0c60 100644 --- a/src/capport/stats.py +++ b/src/capport/stats.py @@ -28,8 +28,8 @@ class MetricPrinter: self._now_str = "" labels = [] if self.args.instance: - labels.append(f"captive_instance=\"{self.args.instance}\"") - labels.append(f"interface=\"{self.args.interface}\"") + labels.append(f'captive_instance="{self.args.instance}"') + labels.append(f'interface="{self.args.interface}"') self._label_str = "{" + ",".join(labels) + "}" def print_metric(self, *, name: str, mtype: str, value: typing.Any, help: str | None = None): @@ -56,7 +56,7 @@ async def amain(args: CliArguments): unique_ipv6 = set() async with capport.utils.ipneigh.connect() as ipn: ipn.ip.strict_check = True - async for (mac, addr) in ipn.dump_neighbors(args.interface): + async for mac, addr in ipn.dump_neighbors(args.interface): if mac in captive_allowed_entries: seen_allowed_entries.add(mac) unique_clients.add(mac) @@ -101,13 +101,13 @@ async def amain(args: CliArguments): total_ipv6, help="Number of IPv6 addresses seen in neighbor cache", ) - with open('/proc/sys/net/netfilter/nf_conntrack_count') as f: + with open("/proc/sys/net/netfilter/nf_conntrack_count") as f: printer.print_gauge( "nf_conntrack_count", int(f.readline()), help="Conntrack count", ) - with open('/proc/sys/net/netfilter/nf_conntrack_max') as f: + with open("/proc/sys/net/netfilter/nf_conntrack_max") as f: printer.print_gauge( "nf_conntrack_max", int(f.readline()), diff --git a/src/capport/utils/nft_socket.py b/src/capport/utils/nft_socket.py index 8dec352..f0e6c2e 100644 --- a/src/capport/utils/nft_socket.py +++ b/src/capport/utils/nft_socket.py @@ -67,9 +67,11 @@ def _build(msg_class: type[_NlMsgBase], /, attrs: dict = {}, header: dict = {}, # support passing nested attributes as dicts of subattributes (or lists of those) if prime["nla_array"]: value = [ - _build(nla_class, attrs=elem) - if not isinstance(elem, pyroute2.netlink.nlmsg_base) and isinstance(elem, dict) - else elem + ( + _build(nla_class, attrs=elem) + if not isinstance(elem, pyroute2.netlink.nlmsg_base) and isinstance(elem, dict) + else elem + ) for elem in value ] elif not isinstance(value, pyroute2.netlink.nlmsg_base) and isinstance(value, dict):