]> Untitled Git - axy/ft/pacman.git/commitdiff
Better config arg handling
authorAxel Gilliard--Marthey <agilliar@student.42mulhouse.fr>
Tue, 27 Oct 2026 13:27:59 +0000 (14:27 +0100)
committerAxel Gilliard--Marthey <agilliar@student.42mulhouse.fr>
Tue, 27 Oct 2026 13:27:59 +0000 (14:27 +0100)
.gitignore
Makefile
README.md
src/pacman/game/__init__.py

index df4adead7a757b3a20b98ade27e004ea431baee9..1ce533d3dc7458e06431499f228f2ffcdf08844a 100644 (file)
@@ -2,5 +2,4 @@
 .venv
 **/__pycache__
 .ruff_cache
-/pacman
-/*.tgz
+/pacman*
index cda17ce04c35fe325745726baee020a4af179609..d0f1127436070440c2b40617f5a03e38623917f4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -37,5 +37,5 @@ check:
 
 build:
        uv pip compile pyproject.toml -o requirements.txt
-       uv run shiv -o pacman -e pacman:main -r requirements.txt .
-       tar czf "$$(uv version).tgz" pacman config.json
+       uv run shiv -o "$$(uv version)" -e pacman:main -r requirements.txt .
+       tar czf "$$(uv version).tgz" "$$(uv version)" config.json
index aec2b0d358aafb07471edf5611215349e5b52b0b..a07be87f04377ae6076b6cf96fce27473a78593c 100644 (file)
--- a/README.md
+++ b/README.md
@@ -100,4 +100,4 @@ The whole is packaged as an executable for distribution using `shiv`.
 ![Project Management](./Project%20Management.png)
 
 
-![Project Status](./Project%20Status.png)
\ No newline at end of file
+![Project Status](./Project%20Status.png)
index f81c7fdfe96b36805a02de2e190f72a43bd130d3..46a383a0517211b9e786955417db2160a1ce97a6 100644 (file)
@@ -5,6 +5,7 @@ import sys
 from collections.abc import Callable
 from dataclasses import dataclass
 from enum import Enum, auto
+from pathlib import Path
 from typing import cast, override
 
 from mazegenerator import (  # type: ignore[import-untyped, unused-ignore]
@@ -291,13 +292,26 @@ def remove_comments(s: str) -> str:
 
 def load_config(world: World) -> None:
     """Load the configuration json."""
-    if len(sys.argv) != 2:
+    if len(sys.argv) > 2:
         raise Exception(
-            f"Expected exactly 1 argument, got {len(sys.argv) - 1}"
+            f"Expected at most 1 argument, the config, got {len(sys.argv) - 1}"
         )
+    s = Config().model_dump_json()
+    if len(sys.argv) == 1:
+        for path in [
+            str(Path(sys.argv[0]).parent) + "/config.json",
+            "./config.json",
+        ]:
+            try:
+                with open(path) as f:
+                    s = f.read()
+            except Exception:
+                continue
+    else:
+        with open(sys.argv[1]) as f:
+            s = f.read()
 
-    with open(sys.argv[1]) as f:
-        config = Config.model_validate_json(remove_comments(f.read()))
+    config = Config.model_validate_json(remove_comments(s))
     world.spawn_resource(config)