trefoil-cli 0.3.0__tar.gz → 1.0.0__tar.gz

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.

Potentially problematic release.


This version of trefoil-cli might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: trefoil-cli
3
- Version: 0.3.0
3
+ Version: 1.0.0
4
4
  Summary: CLI for the trefoil agent server
5
5
  Requires-Python: >=3.10
6
6
  Requires-Dist: pyyaml>=6
@@ -14,6 +14,8 @@ directory of the file that references them.
14
14
  Usage: trefoil <domain> <command> [args]
15
15
 
16
16
  trefoil init [DIR] [--example=NAME]
17
+ trefoil update
18
+ trefoil start-backend [--settings=backend.yml] [--port=8080] [-d]
17
19
  trefoil config package path/to/config.yml [-o bundle.json]
18
20
  trefoil config sync [path/to/config.yml] [--server URL]
19
21
  trefoil agents list
@@ -30,8 +32,11 @@ import argparse
30
32
  import base64
31
33
  import getpass
32
34
  import importlib.metadata
35
+ import importlib.util
33
36
  import json
34
37
  import os
38
+ import shutil
39
+ import subprocess
35
40
  import sys
36
41
  import time
37
42
  import urllib.error
@@ -178,6 +183,52 @@ def cmd_init(args):
178
183
  print(f"next: cd {dest} && trefoil config sync")
179
184
 
180
185
 
186
+ def cmd_update(args):
187
+ # An editable install runs straight from a checkout; reinstalling from PyPI would replace it.
188
+ if Path(__file__).with_name("pyproject.toml").exists():
189
+ sys.exit(f"trefoil: running from a source checkout ({Path(__file__).parent}); "
190
+ "pull and run `make cli` instead")
191
+ # uv-created environments (uv tool install, uv venv) have no pip of their own.
192
+ if importlib.util.find_spec("pip"):
193
+ cmd = [sys.executable, "-m", "pip", "install", "--upgrade", "--force-reinstall", "trefoil-cli"]
194
+ elif shutil.which("uv"):
195
+ cmd = ["uv", "pip", "install", "--python", sys.executable, "--upgrade", "--reinstall", "trefoil-cli"]
196
+ else:
197
+ sys.exit("trefoil: neither pip nor uv is available to reinstall trefoil-cli")
198
+ print(f"trefoil {cli_version()}: {' '.join(cmd)}", file=sys.stderr)
199
+ sys.exit(subprocess.run(cmd).returncode)
200
+
201
+
202
+ def cmd_start_backend(args):
203
+ if not shutil.which("docker"):
204
+ sys.exit("trefoil: docker is not installed or not on PATH")
205
+ cmd = ["docker", "run", "--rm", "--name", args.name, "-p", f"{args.port}:8080",
206
+ "-v", "/var/run/docker.sock:/var/run/docker.sock", "-v", f"{args.volume}:/data"]
207
+ if args.settings:
208
+ path = args.settings.resolve()
209
+ if not path.is_file():
210
+ sys.exit(f"trefoil: {args.settings} is not a file")
211
+ mount = f"/trefoil/settings/{path.name}"
212
+ cmd += ["-v", f"{path}:{mount}:ro", "-e", f"TREFOIL_SETTINGS={mount}"]
213
+ # The server resolves env_file against the settings file and fails if
214
+ # it's missing, so mount it where it will look.
215
+ try:
216
+ env_file = (yaml.safe_load(path.read_text()) or {}).get("env_file")
217
+ except (yaml.YAMLError, AttributeError) as e:
218
+ sys.exit(f"trefoil: {args.settings}: {e}")
219
+ if env_file:
220
+ host = (path.parent / env_file).resolve()
221
+ if not host.is_file():
222
+ sys.exit(f"trefoil: env_file {host} (from {args.settings}) not found")
223
+ target = env_file if os.path.isabs(env_file) else os.path.normpath(f"/trefoil/settings/{env_file}")
224
+ cmd += ["-v", f"{host}:{target}:ro"]
225
+ if args.detach:
226
+ cmd.append("-d")
227
+ cmd.append(args.image)
228
+ print(f"trefoil: {' '.join(cmd)}", file=sys.stderr)
229
+ sys.exit(subprocess.run(cmd).returncode)
230
+
231
+
181
232
  def api_request(server, method, path, body=None, timeout=30, raw=False):
182
233
  """Calls the API and returns the decoded JSON, or the bytes with raw=True."""
183
234
  req = urllib.request.Request(server.rstrip("/") + path, data=body, method=method)
@@ -510,6 +561,21 @@ def main():
510
561
  help="example under examples/ in github.com/alto-se/trefoil (default: echo)")
511
562
  init.set_defaults(func=cmd_init)
512
563
 
564
+ update = domains.add_parser("update", help="reinstall the latest trefoil-cli from PyPI")
565
+ update.set_defaults(func=cmd_update)
566
+
567
+ start_backend = domains.add_parser("start-backend", help="run the trefoil API server image locally with docker")
568
+ start_backend.add_argument("--settings", type=Path, metavar="FILE",
569
+ help="backend settings file (backend.yml) to mount into the container")
570
+ start_backend.add_argument("--port", type=int, default=8080, help="host port to publish (default: 8080)")
571
+ start_backend.add_argument("--image", default="ghcr.io/alto-se/trefoil-api:latest",
572
+ help="API image (default: ghcr.io/alto-se/trefoil-api:latest)")
573
+ start_backend.add_argument("--name", default="trefoil-api", help="container name (default: trefoil-api)")
574
+ start_backend.add_argument("--volume", default="trefoil-data",
575
+ help="docker volume (or host path) for the data dir (default: trefoil-data)")
576
+ start_backend.add_argument("-d", "--detach", action="store_true", help="run in the background")
577
+ start_backend.set_defaults(func=cmd_start_backend)
578
+
513
579
  config = domain("config", "package and upload agent configs")
514
580
  package = config.add_parser("package", help=__doc__.splitlines()[0])
515
581
  package.add_argument("config", type=Path, help="path to config.yml")
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "trefoil-cli"
3
- version = "0.3.0"
3
+ version = "1.0.0"
4
4
  description = "CLI for the trefoil agent server"
5
5
  requires-python = ">=3.10"
6
6
  dependencies = ["pyyaml>=6"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: trefoil-cli
3
- Version: 0.3.0
3
+ Version: 1.0.0
4
4
  Summary: CLI for the trefoil agent server
5
5
  Requires-Python: >=3.10
6
6
  Requires-Dist: pyyaml>=6
File without changes