nacho-python 1.0.0__py3-none-any.whl → 1.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
nacho/_version.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """Version information for Nacho."""
2
2
 
3
- __version__ = "1.0.0"
3
+ __version__ = "1.1.1"
nacho/cli/main.py CHANGED
@@ -8,8 +8,9 @@ import ipaddress
8
8
  import json
9
9
  import logging
10
10
  import sys
11
+ from collections.abc import Callable
11
12
  from pathlib import Path
12
- from typing import TYPE_CHECKING, Any, Callable, List, Optional
13
+ from typing import TYPE_CHECKING, Any
13
14
 
14
15
  from nacho import HAS_REMOTE_DEPS, HAS_SCHEMA_DEPS, HAS_SERVER_DEPS
15
16
  from nacho._version import __version__
@@ -47,7 +48,7 @@ def banner() -> str:
47
48
  return f"{BANNER} Lightweight, self-hosted dynamic configuration · v{__version__}\n"
48
49
 
49
50
 
50
- BUILT_IN_TEMPLATES = {
51
+ BUILT_IN_TEMPLATES: dict[str, dict[str, Any]] = {
51
52
  "empty": {},
52
53
  "web-app": {
53
54
  "app": {"name": "web-app", "version": "1.0.0", "port": 3000},
@@ -108,21 +109,21 @@ def require_remote_deps() -> None:
108
109
  raise ImportError("Remote features require: pip install nacho-python[remote]")
109
110
 
110
111
 
111
- def build_client(args: argparse.Namespace, app_name: Optional[str] = None) -> "NachoClient":
112
+ def build_client(args: argparse.Namespace, app_name: str | None = None) -> "NachoClient":
112
113
  """Build the one NachoClient a command uses from --remote/--app-name/--api-key."""
113
114
  require_remote_deps()
114
115
  from nacho.client import NachoClient
115
116
 
116
117
  return NachoClient(
117
118
  args.remote,
118
- app_name=app_name or getattr(args, "app_name", "default"),
119
+ app_name=app_name or getattr(args, "app_name", None) or "default",
119
120
  api_key=args.api_key,
120
121
  )
121
122
 
122
123
 
123
124
  def create_config(
124
- config_path: Optional[str] = None,
125
- schema: Optional[str] = None,
125
+ config_path: str | None = None,
126
+ schema: str | None = None,
126
127
  read_only: bool = False,
127
128
  ) -> Nacho:
128
129
  """Create a Nacho instance for a local config file."""
@@ -670,7 +671,7 @@ def cmd_history_diff(args: argparse.Namespace) -> int:
670
671
  schema_b = client.get_schema()
671
672
  label_b = f"current (revision {revision})"
672
673
 
673
- def as_lines(config: dict) -> List[str]:
674
+ def as_lines(config: dict) -> list[str]:
674
675
  return json.dumps(config, indent=2, sort_keys=True, ensure_ascii=False).splitlines()
675
676
 
676
677
  diff = list(
@@ -729,7 +730,7 @@ def cmd_watch(args: argparse.Namespace) -> int:
729
730
  # ---------------------------------------------------------------------------
730
731
  # Entry point
731
732
  # ---------------------------------------------------------------------------
732
- def main_cli(argv: Optional[List[str]] = None) -> int:
733
+ def main_cli(argv: list[str] | None = None) -> int:
733
734
  """Main CLI entry point."""
734
735
  parser = create_parser()
735
736
  args = parser.parse_args(argv)
nacho/client.py CHANGED
@@ -11,7 +11,7 @@ Requires the ``remote`` extra (``pip install nacho-python[remote]``).
11
11
 
12
12
  from __future__ import annotations
13
13
 
14
- from typing import Any, Dict, List, Optional, Tuple
14
+ from typing import Any
15
15
  from urllib.parse import quote
16
16
 
17
17
  import requests
@@ -34,20 +34,20 @@ class NachoClient:
34
34
  self,
35
35
  url: str,
36
36
  app_name: str = "default",
37
- api_key: Optional[str] = None,
37
+ api_key: str | None = None,
38
38
  timeout: float = _DEFAULT_TIMEOUT,
39
39
  ) -> None:
40
40
  self.base = url.rstrip("/")
41
41
  self.app_name = app_name
42
42
  self.api_key = api_key
43
43
  self.timeout = timeout
44
- self.last_generation: Optional[str] = None
44
+ self.last_generation: str | None = None
45
45
 
46
46
  # ------------------------------------------------------------------
47
47
  # Low-level request plumbing
48
48
  # ------------------------------------------------------------------
49
49
 
50
- def headers(self) -> Dict[str, str]:
50
+ def headers(self) -> dict[str, str]:
51
51
  if self.api_key:
52
52
  return {"Authorization": f"Bearer {self.api_key}"}
53
53
  return {}
@@ -57,9 +57,9 @@ class NachoClient:
57
57
  method: str,
58
58
  path: str,
59
59
  *,
60
- json_body: Optional[Dict[str, Any]] = None,
61
- params: Optional[Dict[str, Any]] = None,
62
- allowed: Tuple[int, ...] = (),
60
+ json_body: dict[str, Any] | None = None,
61
+ params: dict[str, Any] | None = None,
62
+ allowed: tuple[int, ...] = (),
63
63
  ) -> requests.Response:
64
64
  """Perform a request; raise a typed error for any non-2xx status
65
65
  not listed in *allowed*."""
@@ -119,7 +119,7 @@ class NachoClient:
119
119
  self.last_generation = generation
120
120
 
121
121
  @staticmethod
122
- def _revision_from(resp: requests.Response) -> Optional[int]:
122
+ def _revision_from(resp: requests.Response) -> int | None:
123
123
  raw = resp.headers.get("X-Nacho-Revision")
124
124
  return int(raw) if raw and raw.isdigit() else None
125
125
 
@@ -127,10 +127,10 @@ class NachoClient:
127
127
  # System
128
128
  # ------------------------------------------------------------------
129
129
 
130
- def health(self) -> Dict[str, Any]:
130
+ def health(self) -> dict[str, Any]:
131
131
  return self.request("GET", "/health").json()
132
132
 
133
- def convert(self, data: Any, *, from_fmt: str, to_fmt: str) -> Dict[str, Any]:
133
+ def convert(self, data: Any, *, from_fmt: str, to_fmt: str) -> dict[str, Any]:
134
134
  payload = {"data": data, "from": from_fmt, "to": to_fmt}
135
135
  return self.request("POST", "/api/convert", json_body=payload).json()
136
136
 
@@ -138,19 +138,19 @@ class NachoClient:
138
138
  # Apps
139
139
  # ------------------------------------------------------------------
140
140
 
141
- def list_apps(self) -> Dict[str, Dict[str, Any]]:
141
+ def list_apps(self) -> dict[str, dict[str, Any]]:
142
142
  return self.request("GET", "/api/apps").json()["data"]
143
143
 
144
144
  def create_app(
145
145
  self,
146
146
  *,
147
- data: Optional[Any] = None,
147
+ data: Any | None = None,
148
148
  fmt: str = "json",
149
- schema: Optional[Any] = None,
149
+ schema: Any | None = None,
150
150
  schema_format: str = "json",
151
- description: Optional[str] = None,
152
- ) -> Dict[str, Any]:
153
- payload: Dict[str, Any] = {
151
+ description: str | None = None,
152
+ ) -> dict[str, Any]:
153
+ payload: dict[str, Any] = {
154
154
  "name": self.app_name,
155
155
  "data": data if data is not None else {},
156
156
  "format": fmt,
@@ -162,19 +162,19 @@ class NachoClient:
162
162
  payload["description"] = description
163
163
  return self.request("POST", "/api/apps", json_body=payload).json()
164
164
 
165
- def get_app_info(self) -> Dict[str, Any]:
165
+ def get_app_info(self) -> dict[str, Any]:
166
166
  return self.request("GET", self._app()).json()["data"]
167
167
 
168
- def delete_app(self) -> Dict[str, Any]:
168
+ def delete_app(self) -> dict[str, Any]:
169
169
  return self.request("DELETE", self._app()).json()
170
170
 
171
171
  def update_metadata(
172
172
  self,
173
173
  *,
174
- name: Optional[str] = None,
175
- description: Optional[str] = None,
176
- revision: Optional[int] = None,
177
- ) -> Dict[str, Any]:
174
+ name: str | None = None,
175
+ description: str | None = None,
176
+ revision: int | None = None,
177
+ ) -> dict[str, Any]:
178
178
  payload = {
179
179
  k: v
180
180
  for k, v in (("name", name), ("description", description), ("revision", revision))
@@ -186,20 +186,20 @@ class NachoClient:
186
186
  # Config
187
187
  # ------------------------------------------------------------------
188
188
 
189
- def get_config(self) -> Tuple[Dict[str, Any], Optional[int]]:
189
+ def get_config(self) -> tuple[dict[str, Any], int | None]:
190
190
  resp = self.request("GET", self._app("/config"))
191
191
  self._record_generation(resp)
192
192
  return resp.json(), self._revision_from(resp)
193
193
 
194
194
  def put_config(
195
- self, data: Any, *, fmt: str = "json", revision: Optional[int] = None
196
- ) -> Dict[str, Any]:
197
- payload: Dict[str, Any] = {"data": data, "format": fmt}
195
+ self, data: Any, *, fmt: str = "json", revision: int | None = None
196
+ ) -> dict[str, Any]:
197
+ payload: dict[str, Any] = {"data": data, "format": fmt}
198
198
  if revision is not None:
199
199
  payload["revision"] = revision
200
200
  return self.request("PUT", self._app("/config"), json_body=payload).json()
201
201
 
202
- def get_path(self, path: str) -> Tuple[Any, Optional[int]]:
202
+ def get_path(self, path: str) -> tuple[Any, int | None]:
203
203
  resp = self.request("GET", self._app(f"/config/{quote(path, safe='')}"))
204
204
  self._record_generation(resp)
205
205
  return resp.json()["value"], self._revision_from(resp)
@@ -209,17 +209,17 @@ class NachoClient:
209
209
  path: str,
210
210
  value: Any,
211
211
  *,
212
- revision: Optional[int] = None,
212
+ revision: int | None = None,
213
213
  value_type: str = "raw",
214
- ) -> Dict[str, Any]:
215
- payload: Dict[str, Any] = {"value": value, "type": value_type}
214
+ ) -> dict[str, Any]:
215
+ payload: dict[str, Any] = {"value": value, "type": value_type}
216
216
  if revision is not None:
217
217
  payload["revision"] = revision
218
218
  return self.request(
219
219
  "PUT", self._app(f"/config/{quote(path, safe='')}"), json_body=payload
220
220
  ).json()
221
221
 
222
- def delete_path(self, path: str, *, revision: Optional[int] = None) -> Dict[str, Any]:
222
+ def delete_path(self, path: str, *, revision: int | None = None) -> dict[str, Any]:
223
223
  params = {"revision": revision} if revision is not None else None
224
224
  return self.request(
225
225
  "DELETE", self._app(f"/config/{quote(path, safe='')}"), params=params
@@ -229,22 +229,22 @@ class NachoClient:
229
229
  # Schema
230
230
  # ------------------------------------------------------------------
231
231
 
232
- def get_schema(self) -> Optional[Dict[str, Any]]:
232
+ def get_schema(self) -> dict[str, Any] | None:
233
233
  return self.request("GET", self._app("/schema")).json()["data"]
234
234
 
235
235
  def put_schema(
236
236
  self,
237
- schema: Optional[Any],
237
+ schema: Any | None,
238
238
  *,
239
239
  fmt: str = "json",
240
- revision: Optional[int] = None,
241
- ) -> Dict[str, Any]:
242
- payload: Dict[str, Any] = {"schema": schema, "schema_format": fmt}
240
+ revision: int | None = None,
241
+ ) -> dict[str, Any]:
242
+ payload: dict[str, Any] = {"schema": schema, "schema_format": fmt}
243
243
  if revision is not None:
244
244
  payload["revision"] = revision
245
245
  return self.request("PUT", self._app("/schema"), json_body=payload).json()
246
246
 
247
- def validate(self, data: Any, *, fmt: str = "json") -> Dict[str, Any]:
247
+ def validate(self, data: Any, *, fmt: str = "json") -> dict[str, Any]:
248
248
  payload = {"data": data, "format": fmt}
249
249
  return self.request("POST", self._app("/validate"), json_body=payload).json()
250
250
 
@@ -252,14 +252,14 @@ class NachoClient:
252
252
  # History
253
253
  # ------------------------------------------------------------------
254
254
 
255
- def list_history(self) -> List[Dict[str, Any]]:
255
+ def list_history(self) -> list[dict[str, Any]]:
256
256
  return self.request("GET", self._app("/history")).json()["data"]
257
257
 
258
- def get_history_snapshot(self, revision: int) -> Dict[str, Any]:
258
+ def get_history_snapshot(self, revision: int) -> dict[str, Any]:
259
259
  return self.request("GET", self._app(f"/history/{revision}")).json()["data"]
260
260
 
261
- def rollback(self, revision: int, *, expected_revision: Optional[int] = None) -> Dict[str, Any]:
262
- payload: Dict[str, Any] = {"revision": revision}
261
+ def rollback(self, revision: int, *, expected_revision: int | None = None) -> dict[str, Any]:
262
+ payload: dict[str, Any] = {"revision": revision}
263
263
  if expected_revision is not None:
264
264
  payload["expected_revision"] = expected_revision
265
265
  return self.request("POST", self._app("/rollback"), json_body=payload).json()