Skip to content

Commit 42150de

Browse files
committed
add missing types
1 parent 71015e3 commit 42150de

File tree

11 files changed

+44
-37
lines changed

11 files changed

+44
-37
lines changed

resources/scripts/apidocs.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from click import Context
88
from tabulate import tabulate
9+
910
from warnet.cli.main import cli
1011

1112
file_path = Path(os.path.dirname(os.path.abspath(__file__))) / ".." / ".." / "docs" / "warcli.md"

resources/scripts/graphdocs.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pathlib import Path
66

77
from tabulate import tabulate
8+
89
from warnet.cli.util import load_schema
910

1011
graph_schema = load_schema()

src/warnet/cli/bitcoin.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from io import BytesIO
66

77
import click
8+
89
from test_framework.messages import ser_uint256
910
from test_framework.p2p import MESSAGEMAP
1011

@@ -20,14 +21,14 @@ def bitcoin():
2021
@click.argument("node", type=int)
2122
@click.argument("method", type=str)
2223
@click.argument("params", type=str, nargs=-1) # this will capture all remaining arguments
23-
def rpc(node, method, params):
24+
def rpc(node: int, method: str, params: str):
2425
"""
2526
Call bitcoin-cli <method> [params] on <node>
2627
"""
2728
print(_rpc(node, method, params))
2829

2930

30-
def _rpc(node, method, params):
31+
def _rpc(node: int, method: str, params: str):
3132
if params:
3233
cmd = f"kubectl exec warnet-tank-{node} -- bitcoin-cli -regtest -rpcuser='user' -rpcpassword='password' {method} {' '.join(map(str, params))}"
3334
else:
@@ -37,7 +38,7 @@ def _rpc(node, method, params):
3738

3839
@bitcoin.command()
3940
@click.argument("node", type=int, required=True)
40-
def debug_log(node):
41+
def debug_log(node: int):
4142
"""
4243
Fetch the Bitcoin Core debug log from <node>
4344
"""
@@ -49,7 +50,7 @@ def debug_log(node):
4950
@click.argument("pattern", type=str, required=True)
5051
@click.option("--show-k8s-timestamps", is_flag=True, default=False, show_default=True)
5152
@click.option("--no-sort", is_flag=True, default=False, show_default=True)
52-
def grep_logs(pattern, show_k8s_timestamps, no_sort):
53+
def grep_logs(pattern: str, show_k8s_timestamps: bool, no_sort: bool):
5354
"""
5455
Grep combined bitcoind logs using regex <pattern>
5556
"""
@@ -120,7 +121,7 @@ def grep_logs(pattern, show_k8s_timestamps, no_sort):
120121
@click.argument("node_a", type=int, required=True)
121122
@click.argument("node_b", type=int, required=True)
122123
@click.option("--network", default="regtest", show_default=True)
123-
def messages(node_a, node_b, network):
124+
def messages(node_a: int, node_b: int, network: str):
124125
"""
125126
Fetch messages sent between <node_a> and <node_b> in [network]
126127
"""
@@ -154,7 +155,7 @@ def messages(node_a, node_b, network):
154155
print(f"Error fetching messages between nodes {node_a} and {node_b}: {e}")
155156

156157

157-
def get_messages(node_a, node_b, network):
158+
def get_messages(node_a: int, node_b: int, network: str):
158159
"""
159160
Fetch messages from the message capture files
160161
"""
@@ -198,7 +199,7 @@ def get_messages(node_a, node_b, network):
198199

199200
# This function is a hacked-up copy of process_file() from
200201
# Bitcoin Core contrib/message-capture/message-capture-parser.py
201-
def parse_raw_messages(blob, outbound):
202+
def parse_raw_messages(blob: bytes, outbound: bool):
202203
TIME_SIZE = 8
203204
LENGTH_SIZE = 4
204205
MSGTYPE_SIZE = 12
@@ -267,7 +268,7 @@ def parse_raw_messages(blob, outbound):
267268
return messages
268269

269270

270-
def to_jsonable(obj):
271+
def to_jsonable(obj: str):
271272
HASH_INTS = [
272273
"blockhash",
273274
"block_hash",

src/warnet/cli/k8s.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
import json
2-
import yaml
32
import tempfile
43
from importlib.resources import files
54
from pathlib import Path
6-
from typing import Any, Dict
75

6+
import yaml
87
from kubernetes import client, config
8+
from kubernetes.client.models import CoreV1Event, V1PodList
99
from kubernetes.dynamic import DynamicClient
1010

1111
from .process import stream_command
1212

1313
WAR_MANIFESTS = files("manifests")
1414

1515

16-
def get_static_client():
16+
def get_static_client() -> CoreV1Event:
1717
config.load_kube_config()
1818
return client.CoreV1Api()
1919

2020

21-
def get_dynamic_client():
21+
def get_dynamic_client() -> DynamicClient:
2222
config.load_kube_config()
2323
return DynamicClient(client.ApiClient())
2424

2525

26-
def get_pods():
26+
def get_pods() -> V1PodList:
2727
sclient = get_static_client()
2828
return sclient.list_namespaced_pod("warnet")
2929

3030

31-
def get_mission(mission):
31+
def get_mission(mission: str) -> list[V1PodList]:
3232
pods = get_pods()
3333
crew = []
3434
for pod in pods.items:
@@ -37,15 +37,15 @@ def get_mission(mission):
3737
return crew
3838

3939

40-
def get_edges():
40+
def get_edges() -> any:
4141
sclient = get_static_client()
4242
configmap = sclient.read_namespaced_config_map(name="edges", namespace="warnet")
4343
return json.loads(configmap.data["data"])
4444

4545

4646
def create_kubernetes_object(
47-
kind: str, metadata: Dict[str, Any], spec: Dict[str, Any] = None
48-
) -> Dict[str, Any]:
47+
kind: str, metadata: dict[str, any], spec: dict[str, any] = None
48+
) -> dict[str, any]:
4949
obj = {
5050
"apiVersion": "v1",
5151
"kind": kind,
@@ -60,7 +60,7 @@ def create_namespace() -> dict:
6060
return {"apiVersion": "v1", "kind": "Namespace", "metadata": {"name": "warnet"}}
6161

6262

63-
def set_kubectl_context(namespace: str):
63+
def set_kubectl_context(namespace: str) -> bool:
6464
"""
6565
Set the default kubectl context to the specified namespace.
6666
"""
@@ -73,7 +73,7 @@ def set_kubectl_context(namespace: str):
7373
return result
7474

7575

76-
def deploy_base_configurations():
76+
def deploy_base_configurations() -> bool:
7777
base_configs = [
7878
"namespace.yaml",
7979
"rbac-config.yaml",
@@ -87,12 +87,12 @@ def deploy_base_configurations():
8787
return True
8888

8989

90-
def apply_kubernetes_yaml(yaml_file: str):
90+
def apply_kubernetes_yaml(yaml_file: str) -> bool:
9191
command = f"kubectl apply -f {yaml_file}"
9292
return stream_command(command)
9393

9494

95-
def apply_kubernetes_yaml_obj(yaml_obj: str):
95+
def apply_kubernetes_yaml_obj(yaml_obj: str) -> None:
9696
with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as temp_file:
9797
yaml.dump(yaml_obj, temp_file)
9898
temp_file_path = temp_file.name
@@ -103,11 +103,11 @@ def apply_kubernetes_yaml_obj(yaml_obj: str):
103103
Path(temp_file_path).unlink()
104104

105105

106-
def delete_namespace(namespace: str):
106+
def delete_namespace(namespace: str) -> bool:
107107
command = f"kubectl delete namespace {namespace} --ignore-not-found"
108108
return stream_command(command)
109109

110110

111-
def delete_pod(pod_name: str):
111+
def delete_pod(pod_name: str) -> bool:
112112
command = f"kubectl delete pod {pod_name}"
113113
return stream_command(command)

src/warnet/cli/namespaces.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def deploy(namespaces: str):
3737
for n in names:
3838
if not n.startswith("warnet-"):
3939
print(
40-
f"Failled to create namespace: {n}. Namespaces must start with a 'warnet-' prefix."
40+
f"Failed to create namespace: {n}. Namespaces must start with a 'warnet-' prefix."
4141
)
4242

4343
# deploy namespaces

src/warnet/cli/network.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def network():
3434

3535

3636
class Edge:
37-
def __init__(self, src: str, dst: str, data: Dict[str, Any]):
37+
def __init__(self, src: str, dst: str, data: dict[str, any]):
3838
self.src = src
3939
self.dst = dst
4040
self.data = data
@@ -43,7 +43,7 @@ def to_dict(self):
4343
return {"src": self.src, "dst": self.dst, "data": self.data}
4444

4545

46-
def edges_from_network_file(network_file: Dict[str, Any]) -> List[Edge]:
46+
def edges_from_network_file(network_file: dict[str, any]) -> list[Edge]:
4747
edges = []
4848
for node in network_file["nodes"]:
4949
if "connect" in node:
@@ -52,7 +52,7 @@ def edges_from_network_file(network_file: Dict[str, Any]) -> List[Edge]:
5252
return edges
5353

5454

55-
def create_edges_map(network_file: Dict[str, Any]):
55+
def create_edges_map(network_file: dict[str, any]):
5656
edges = []
5757
for edge in edges_from_network_file(network_file):
5858
edges.append(edge.to_dict())
@@ -149,7 +149,7 @@ def logs(follow: bool):
149149

150150
@network.command()
151151
def connected():
152-
"""Determine if all p2p conenctions defined in graph are established"""
152+
"""Determine if all p2p connections defined in graph are established"""
153153
print(_connected())
154154

155155

src/warnet/cli/process.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import subprocess
22

33

4-
def run_command(command) -> str:
4+
def run_command(command: str) -> str:
55
result = subprocess.run(
66
command, shell=True, capture_output=True, text=True, executable="/bin/bash"
77
)
@@ -10,7 +10,7 @@ def run_command(command) -> str:
1010
return result.stdout
1111

1212

13-
def stream_command(command, env=None) -> bool:
13+
def stream_command(command: str, env=None) -> bool:
1414
process = subprocess.Popen(
1515
["/bin/bash", "-c", command],
1616
stdout=subprocess.PIPE,

src/warnet/cli/scenarios.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from rich import print
1212
from rich.console import Console
1313
from rich.table import Table
14+
1415
from warnet import scenarios as SCENARIOS
1516

1617
from .k8s import apply_kubernetes_yaml, create_namespace, get_mission
@@ -51,7 +52,7 @@ def _available():
5152
@scenarios.command(context_settings={"ignore_unknown_options": True})
5253
@click.argument("scenario", type=str)
5354
@click.argument("additional_args", nargs=-1, type=click.UNPROCESSED)
54-
def run(scenario, additional_args):
55+
def run(scenario: str, additional_args: tuple[str]):
5556
"""
5657
Run <scenario> from the Warnet Test Framework with optional arguments
5758
"""
@@ -69,7 +70,7 @@ def run(scenario, additional_args):
6970
@scenarios.command(context_settings={"ignore_unknown_options": True})
7071
@click.argument("scenario_path", type=str)
7172
@click.argument("additional_args", nargs=-1, type=click.UNPROCESSED)
72-
def run_file(scenario_path, additional_args):
73+
def run_file(scenario_path: str, additional_args: tuple[str]):
7374
"""
7475
Run <scenario_path> from the Warnet Test Framework with optional arguments
7576
"""
@@ -79,7 +80,7 @@ def run_file(scenario_path, additional_args):
7980
return run_scenario(scenario_path, additional_args)
8081

8182

82-
def run_scenario(scenario_path, additional_args):
83+
def run_scenario(scenario_path: str, additional_args: tuple[str]):
8384
if not os.path.exists(scenario_path):
8485
raise Exception(f"Scenario file not found at {scenario_path}.")
8586

@@ -119,7 +120,7 @@ def run_scenario(scenario_path, additional_args):
119120
"apiVersion": "v1",
120121
"kind": "ConfigMap",
121122
"metadata": {
122-
"name": "scnaeriopy",
123+
"name": "scenariopy",
123124
"namespace": "warnet",
124125
},
125126
"data": {"scenario.py": scenario_text},
@@ -146,7 +147,7 @@ def run_scenario(scenario_path, additional_args):
146147
"subPath": "warnet.json",
147148
},
148149
{
149-
"name": "scnaeriopy",
150+
"name": "scenariopy",
150151
"mountPath": "scenario.py",
151152
"subPath": "scenario.py",
152153
},
@@ -155,7 +156,7 @@ def run_scenario(scenario_path, additional_args):
155156
],
156157
"volumes": [
157158
{"name": "warnetjson", "configMap": {"name": "warnetjson"}},
158-
{"name": "scnaeriopy", "configMap": {"name": "scnaeriopy"}},
159+
{"name": "scenariopy", "configMap": {"name": "scenariopy"}},
159160
],
160161
},
161162
},
@@ -188,6 +189,6 @@ def active():
188189
console.print(table)
189190

190191

191-
def _active():
192+
def _active() -> list[str]:
192193
commanders = get_mission("commander")
193194
return [{"commander": c.metadata.name, "status": c.status.phase.lower()} for c in commanders]

test/data/scenario_p2p_interface.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
# The base class exists inside the commander container
55
from commander import Commander
6+
67
from test_framework.messages import CInv, msg_getdata
78
from test_framework.p2p import P2PInterface
89

test/ln_test.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pathlib import Path
66

77
from test_base import TestBase
8+
89
from warnet.services import ServiceType
910

1011

test/scenarios_test.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pathlib import Path
55

66
from test_base import TestBase
7+
78
from warnet.cli.k8s import delete_pod
89
from warnet.cli.scenarios import _active as scenarios_active
910
from warnet.cli.scenarios import _available as scenarios_available

0 commit comments

Comments
 (0)