Skip to content

Commit 7b4f414

Browse files
committed
Update antares-python with new settings
1 parent f3210cc commit 7b4f414

File tree

9 files changed

+87
-71
lines changed

9 files changed

+87
-71
lines changed

antares-python/README.md

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ async def main():
115115
async for event in client.subscribe():
116116
if isinstance(event, Track):
117117
print(
118-
f"📍 Track #{event.id} - {event.name} at ({event.lat}, {event.long}) → {event.speed} knots"
118+
f"📍 Track #{event.id} - {event.name} at ({event.lat}, {event.long}) → {event.speed} m/s"
119119
)
120120

121121

@@ -157,11 +157,9 @@ The client supports two configuration methods:
157157
The `.env` file allows you to define environment variables:
158158

159159
```dotenv
160-
ANTARES_HOST=localhost
161-
ANTARES_HTTP_PORT=9000
162-
ANTARES_TCP_PORT=9001
160+
ANTARES_CONTROLLER_BIND_ADDR=0.0.0.0:17394
161+
ANTARES_RADAR_BIND_ADDR=0.0.0.0:17396
163162
ANTARES_TIMEOUT=5.0
164-
ANTARES_AUTH_TOKEN=
165163
```
166164

167165
➡️ See `template.env` for a complete example.
@@ -171,29 +169,42 @@ ANTARES_AUTH_TOKEN=
171169
To configure the client and ships via a TOML file:
172170

173171
```toml
174-
[antares]
175-
host = "localhost"
176-
http_port = 9000
177-
tcp_port = 9001
178-
timeout = 5.0
179-
auth_token = ""
180-
181-
[[antares.ships.stationary]]
182-
initial_position = [50.0, 50.0]
172+
[antares.radar]
173+
bind_addr = "0.0.0.0:17396"
183174

184-
[[antares.ships.random]]
185-
initial_position = [-20.0, 20.0]
186-
max_speed = 10.0
175+
[antares.radar.detector]
176+
range = 1000.0
177+
speed = 0.0
178+
angle = 0.0
179+
start_coordinates = [4.0, -72.0]
187180

188-
[[antares.ships.circle]]
189-
initial_position = [30.0, -30.0]
190-
radius = 20.0
191-
speed = 4.0
181+
[antares.radar.broadcast]
182+
type = "tcp"
192183

193-
[[antares.ships.line]]
184+
[antares.simulation]
185+
emission_interval = 20
186+
controller_bind_addr = "0.0.0.0:17394"
187+
188+
[[antares.simulation.initial_ships]]
189+
type = "line"
194190
initial_position = [0.0, 0.0]
195191
angle = 0.785
196192
speed = 5.0
193+
194+
[[antares.simulation.initial_ships]]
195+
type = "circle"
196+
initial_position = [30.0, -30.0]
197+
radius = 20.0
198+
speed = 4.0
199+
200+
[[antares.simulation.initial_ships]]
201+
type = "random"
202+
initial_position = [-20.0, 20.0]
203+
max_speed = 10.0
204+
205+
[[antares.simulation.initial_ships]]
206+
type = "stationary"
207+
initial_position = [50.0, 50.0]
197208
```
198209

199210
➡️ See `config.example.toml` for a full working example.

antares-python/config.example.toml

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,48 @@
11
# ============================
22
# Antares Simulation Config
3-
# Example TOML configuration
43
# ============================
54

6-
[antares]
7-
host = "localhost"
8-
http_port = 9000
9-
tcp_port = 9001
10-
timeout = 5.0
11-
auth_token = ""
5+
[antares.simulation]
6+
emission_interval = 20
7+
controller_bind_addr = "0.0.0.0:17394"
128

139
# ============================
1410
# Ships to add at startup
1511
# ============================
1612

17-
[[antares.ships.line]]
13+
[[antares.simulation.initial_ships]]
14+
type = "line"
1815
initial_position = [0.0, 0.0]
1916
angle = 0.785 # radians (approx. 45 degrees)
2017
speed = 5.0
2118

22-
[[antares.ships.circle]]
19+
[[antares.simulation.initial_ships]]
20+
type = "circle"
2321
initial_position = [30.0, -30.0]
2422
radius = 20.0
2523
speed = 4.0
2624

27-
[[antares.ships.random]]
25+
[[antares.simulation.initial_ships]]
26+
type = "random"
2827
initial_position = [-20.0, 20.0]
2928
max_speed = 10.0
3029

31-
[[antares.ships.stationary]]
30+
[[antares.simulation.initial_ships]]
31+
type = "stationary"
3232
initial_position = [50.0, 50.0]
33+
34+
# ============================
35+
# Antares Radar Config
36+
# ============================
37+
38+
[antares.radar]
39+
bind_addr = "0.0.0.0:17396"
40+
41+
[antares.radar.detector]
42+
range = 1000.0
43+
speed = 0.0
44+
angle = 0.0
45+
start_coordinates = [4.0, -72.0]
46+
47+
[antares.radar.broadcast]
48+
type = "tcp"

antares-python/main.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@ async def main() -> None:
1111
"""
1212

1313
# Initialize the Antares client
14-
client = AntaresClient(
15-
host="localhost",
16-
http_port=9000,
17-
tcp_port=9001,
18-
timeout=5.0,
19-
auth_token="my_secret_auth_token",
20-
)
14+
client = AntaresClient()
2115

2216
# Add ships
2317
ships = [
@@ -36,7 +30,7 @@ async def main() -> None:
3630
try:
3731
async for track in client.subscribe():
3832
print(
39-
f"📍 Track #{track.id} - {track.name} @ ({track.lat}, {track.long}) → {track.speed} knots" # noqa: E501
33+
f"📍 Track #{track.id} - {track.name} @ ({track.lat}, {track.long}) → {track.speed} m/s" # noqa: E501
4034
)
4135
except KeyboardInterrupt:
4236
print("\n🛑 Subscription interrupted by user.")

antares-python/pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ dependencies = [
1717
]
1818

1919
[project.optional-dependencies]
20-
dev = ["pytest-asyncio>=0.26.0"]
20+
dev = [
21+
"taskipy==1.14.1",
22+
"build==1.2.2.post1",
23+
"mypy==1.15.0",
24+
"pytest==8.3.5",
25+
"pytest-cov==6.1.1",
26+
"pytest-mock==3.14.0",
27+
"pytest-asyncio>=0.26.0",
28+
"ruff==0.11.8",
29+
]
2130

2231
[project.scripts]
2332
antares-cli = "antares.cli:app"

antares-python/src/antares/cli.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ async def _sub() -> None:
150150
try:
151151
async for event in client.subscribe():
152152
if json_output:
153-
typer.echo(json.dumps(event))
153+
typer.echo(event.model_dump_json())
154154
else:
155-
console.print_json(data=event)
155+
console.print(f"[info]Received event: {event}")
156156
logger.debug("Received event: %s", event)
157157
except SubscriptionError as e:
158158
handle_error(str(e), code=3, json_output=json_output)
@@ -183,11 +183,9 @@ def build_client(config_path: str | None, verbose: bool, json_output: bool) -> A
183183
if verbose:
184184
console.print(f"[info]Using settings: {settings.model_dump()}")
185185
return AntaresClient(
186-
host=settings.host,
187-
http_port=settings.http_port,
188-
tcp_port=settings.tcp_port,
186+
controller_bind_addr=settings.controller_bind_addr,
187+
radar_bind_addr=settings.radar_bind_addr,
189188
timeout=settings.timeout,
190-
auth_token=settings.auth_token,
191189
)
192190
except Exception as e:
193191
handle_error(f"Failed to load configuration: {e}", code=1, json_output=json_output)

antares-python/src/antares/client/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ def __init__(
2525
# Merge provided arguments with environment/.env via AntaresSettings
2626
self._settings = AntaresSettings(**filtered_kwargs)
2727

28-
base_url = f"http://{self._settings.host}:{self._settings.http_port}"
28+
base_url = f"http://{self._settings.controller_bind_addr}"
29+
host, tcp_port = self._settings.radar_bind_addr.split(":")
2930
self._rest = RestClient(
3031
base_url=base_url,
3132
timeout=self._settings.timeout,
32-
auth_token=self._settings.auth_token,
3333
)
3434
self._tcp = TCPSubscriber(
35-
host=self._settings.host,
36-
port=self._settings.tcp_port,
35+
host=host,
36+
port=int(tcp_port),
3737
)
3838

3939
def reset_simulation(self) -> None:

antares-python/src/antares/client/rest.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class RestClient:
99
Internal client for interacting with the Antares simulation REST API.
1010
"""
1111

12-
def __init__(self, base_url: str, timeout: float = 5.0, auth_token: str | None = None) -> None:
12+
def __init__(self, base_url: str, timeout: float = 5.0) -> None:
1313
"""
1414
Initializes the REST client.
1515
@@ -20,7 +20,6 @@ def __init__(self, base_url: str, timeout: float = 5.0, auth_token: str | None =
2020
"""
2121
self.base_url = base_url.rstrip("/")
2222
self.timeout = timeout
23-
self.headers = {"Authorization": f"Bearer {auth_token}"} if auth_token else {}
2423

2524
def reset_simulation(self) -> None:
2625
"""
@@ -29,7 +28,6 @@ def reset_simulation(self) -> None:
2928
try:
3029
response = httpx.post(
3130
f"{self.base_url}/simulation/reset",
32-
headers=self.headers,
3331
timeout=self.timeout,
3432
)
3533
response.raise_for_status()
@@ -49,7 +47,6 @@ def add_ship(self, ship: ShipConfig) -> None:
4947
response = httpx.post(
5048
f"{self.base_url}/simulation/ships",
5149
json=ship.model_dump(),
52-
headers=self.headers,
5350
timeout=self.timeout,
5451
)
5552
response.raise_for_status()

antares-python/src/antares/config.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ class AntaresSettings(BaseSettings):
77
Supports environment variables and `.env` file loading.
88
"""
99

10-
host: str = "localhost"
11-
http_port: int = 9000
12-
tcp_port: int = 9001
10+
controller_bind_addr: str = "0.0.0.0:17394"
11+
radar_bind_addr: str = "0.0.0.0:17396"
1312
timeout: float = 5.0
14-
auth_token: str | None = None
1513

1614
model_config = SettingsConfigDict(
1715
env_file=".env",

antares-python/template.env

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,11 @@
66
# cp template.env .env
77
# ========================
88

9-
# Host where the Antares simulation engine is running
10-
ANTARES_HOST=localhost
9+
# Controller bind address
10+
ANTARES_CONTROLLER_BIND_ADDR=0.0.0.0:17394
1111

12-
# Port for the HTTP API
13-
ANTARES_HTTP_PORT=9000
14-
15-
# Port for the TCP stream
16-
ANTARES_TCP_PORT=9001
12+
# Radar bind address
13+
ANTARES_RADAR_BIND_ADDR=0.0.0.0:17396
1714

1815
# Request timeout in seconds
1916
ANTARES_TIMEOUT=5.0
20-
21-
# Optional: Authentication token for the API
22-
# Leave empty if not required
23-
ANTARES_AUTH_TOKEN=

0 commit comments

Comments
 (0)