xgic-wagtail-cli 0.1.0__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.
- xgic/cli/wagtail/__init__.py +5 -0
- xgic/cli/wagtail/commands/__init__.py +1 -0
- xgic/cli/wagtail/commands/dev.py +99 -0
- xgic/cli/wagtail/commands/info.py +34 -0
- xgic/cli/wagtail/commands/schema.py +23 -0
- xgic/cli/wagtail/commands/setup.py +12 -0
- xgic/cli/wagtail/config.py +112 -0
- xgic/cli/wagtail/env_helpers.py +69 -0
- xgic/cli/wagtail/plugin.py +89 -0
- xgic/cli/wagtail/project.py +268 -0
- xgic/cli/wagtail/schema.py +62 -0
- xgic_wagtail_cli-0.1.0.dist-info/METADATA +148 -0
- xgic_wagtail_cli-0.1.0.dist-info/RECORD +17 -0
- xgic_wagtail_cli-0.1.0.dist-info/WHEEL +4 -0
- xgic_wagtail_cli-0.1.0.dist-info/entry_points.txt +2 -0
- xgic_wagtail_cli-0.1.0.dist-info/licenses/LICENSE +202 -0
- xgic_wagtail_cli-0.1.0.dist-info/licenses/NOTICE +8 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Wagtail CLI command handlers."""
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""``xgic wagtail dev`` — foreground Django/Wagtail runserver."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import signal
|
|
7
|
+
import socket
|
|
8
|
+
import subprocess
|
|
9
|
+
import sys
|
|
10
|
+
import time
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from xgic.cli.app import CommandContext
|
|
14
|
+
from xgic.cli.utils.output import print_info, print_warning
|
|
15
|
+
from xgic.cli.wagtail.project import is_wagtail_project_complete
|
|
16
|
+
|
|
17
|
+
_SIGINT_EXIT_CODES = {130, -signal.SIGINT, 128 + signal.SIGINT}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _wait_for_postgres(host: str, port: int, timeout: float = 60.0) -> bool:
|
|
21
|
+
deadline = time.monotonic() + timeout
|
|
22
|
+
while time.monotonic() < deadline:
|
|
23
|
+
try:
|
|
24
|
+
with socket.create_connection((host, port), 2.0):
|
|
25
|
+
return True
|
|
26
|
+
except OSError:
|
|
27
|
+
time.sleep(0.5)
|
|
28
|
+
return False
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _manage_py(root: Path) -> Path:
|
|
32
|
+
return root / "manage.py"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def run_dev(ctx: CommandContext) -> int:
|
|
36
|
+
"""Migrate (idempotent) and run ``manage.py runserver 0.0.0.0:8000``."""
|
|
37
|
+
quiet = bool(getattr(ctx.args, "quiet", False))
|
|
38
|
+
root = Path.cwd()
|
|
39
|
+
if not is_wagtail_project_complete(root):
|
|
40
|
+
print_warning(
|
|
41
|
+
"No Wagtail site in this workspace. Run: xgic wagtail setup"
|
|
42
|
+
)
|
|
43
|
+
return 2
|
|
44
|
+
|
|
45
|
+
manage = _manage_py(root)
|
|
46
|
+
host = os.environ.get("POSTGRES_HOST", "postgres")
|
|
47
|
+
port = int(os.environ.get("POSTGRES_PORT", "5432"))
|
|
48
|
+
if not _wait_for_postgres(host, port):
|
|
49
|
+
print_warning(
|
|
50
|
+
f"PostgreSQL is not reachable at {host}:{port}. "
|
|
51
|
+
"Start Compose postgres, then retry: xgic wagtail dev"
|
|
52
|
+
)
|
|
53
|
+
return 1
|
|
54
|
+
|
|
55
|
+
python = sys.executable
|
|
56
|
+
if not quiet:
|
|
57
|
+
print_info("Running: python manage.py migrate --noinput")
|
|
58
|
+
migrate = subprocess.run(
|
|
59
|
+
[python, str(manage), "migrate", "--noinput"],
|
|
60
|
+
cwd=str(root),
|
|
61
|
+
check=False,
|
|
62
|
+
)
|
|
63
|
+
if migrate.returncode != 0:
|
|
64
|
+
print_warning("migrate failed. Fix the database, then retry: xgic wagtail dev")
|
|
65
|
+
return int(migrate.returncode)
|
|
66
|
+
|
|
67
|
+
bind = os.environ.get("WAGTAIL_DEV_BIND", "0.0.0.0:8000")
|
|
68
|
+
if not quiet:
|
|
69
|
+
print_info(f"Launching: python manage.py runserver {bind}")
|
|
70
|
+
print_info("Stop with Ctrl+C.")
|
|
71
|
+
|
|
72
|
+
try:
|
|
73
|
+
proc = subprocess.Popen(
|
|
74
|
+
[python, str(manage), "runserver", bind],
|
|
75
|
+
cwd=str(root),
|
|
76
|
+
stdin=sys.stdin,
|
|
77
|
+
stdout=sys.stdout,
|
|
78
|
+
stderr=sys.stderr,
|
|
79
|
+
)
|
|
80
|
+
except OSError as exc:
|
|
81
|
+
print_warning(f"Could not start runserver: {exc}")
|
|
82
|
+
return 1
|
|
83
|
+
|
|
84
|
+
try:
|
|
85
|
+
returncode = int(proc.wait())
|
|
86
|
+
except KeyboardInterrupt:
|
|
87
|
+
proc.send_signal(signal.SIGINT)
|
|
88
|
+
try:
|
|
89
|
+
returncode = int(proc.wait(timeout=15))
|
|
90
|
+
except subprocess.TimeoutExpired:
|
|
91
|
+
proc.kill()
|
|
92
|
+
proc.wait(timeout=5)
|
|
93
|
+
returncode = 130
|
|
94
|
+
|
|
95
|
+
if returncode in _SIGINT_EXIT_CODES:
|
|
96
|
+
if not quiet:
|
|
97
|
+
print_info("Development server stopped by user (Ctrl+C).")
|
|
98
|
+
return 0
|
|
99
|
+
return returncode
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""``xgic wagtail info`` — module status."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
|
|
8
|
+
from xgic.cli.utils.output import print_info, print_success
|
|
9
|
+
from xgic.cli.wagtail import __version__
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def run_info(ctx: argparse.Namespace) -> int:
|
|
13
|
+
"""Print Wagtail CLI module identity and capabilities."""
|
|
14
|
+
args = getattr(ctx, "args", ctx)
|
|
15
|
+
payload = {
|
|
16
|
+
"module": "xgic.cli.wagtail",
|
|
17
|
+
"package": "xgic-wagtail-cli",
|
|
18
|
+
"version": __version__,
|
|
19
|
+
"status": "experimental",
|
|
20
|
+
"commands": ["info", "setup", "schema", "dev"],
|
|
21
|
+
"repository": "https://github.com/xgic/wagtail-cli",
|
|
22
|
+
"template": "https://github.com/xgic/wagtail",
|
|
23
|
+
"producer": "https://github.com/xgic/wagtail-dev",
|
|
24
|
+
}
|
|
25
|
+
if getattr(args, "json", False):
|
|
26
|
+
print(json.dumps(payload, indent=2))
|
|
27
|
+
return 0
|
|
28
|
+
|
|
29
|
+
print_success(f"XGIC Wagtail CLI {__version__} (experimental)")
|
|
30
|
+
print_info("Namespace: xgic.cli.wagtail")
|
|
31
|
+
print_info("Repo: https://github.com/xgic/wagtail-cli")
|
|
32
|
+
print_info("Commands: info, setup, schema, dev")
|
|
33
|
+
print_info("Template: https://github.com/xgic/wagtail")
|
|
34
|
+
return 0
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""``xgic wagtail schema`` — write create-wagtail-config JSON Schema."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from xgic.cli.app import CommandContext
|
|
8
|
+
from xgic.cli.utils.output import print_success, print_warning
|
|
9
|
+
from xgic.cli.wagtail.config import DEFAULT_SCHEMA_FILE
|
|
10
|
+
from xgic.cli.wagtail.schema import write_schema
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def run_schema(ctx: CommandContext) -> int:
|
|
14
|
+
"""Write JSON Schema for create-wagtail-config.json."""
|
|
15
|
+
override = getattr(ctx.args, "output", None)
|
|
16
|
+
path = Path(override) if override else DEFAULT_SCHEMA_FILE
|
|
17
|
+
try:
|
|
18
|
+
written = write_schema(path)
|
|
19
|
+
except OSError as exc:
|
|
20
|
+
print_warning(f"Could not write {path}: {exc}")
|
|
21
|
+
return 1
|
|
22
|
+
print_success(f"Wrote {written} (IntelliSense for create-wagtail-config.json)")
|
|
23
|
+
return 0
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""``xgic wagtail setup`` — ensure Wagtail site with PostgreSQL."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from xgic.cli.app import CommandContext
|
|
6
|
+
from xgic.cli.wagtail.project import ensure_wagtail_project
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def run_setup(ctx: CommandContext) -> int:
|
|
10
|
+
"""Idempotent Wagtail project ensure (PostgreSQL default)."""
|
|
11
|
+
quiet = bool(getattr(ctx.args, "quiet", False))
|
|
12
|
+
return ensure_wagtail_project(quiet=quiet)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""Wagtail product defaults and create-wagtail-config.json readers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
DEFAULT_CONFIG_FILE = Path(".devcontainer/create-wagtail-config.json")
|
|
11
|
+
DEFAULT_SCHEMA_FILE = Path(".devcontainer/create-wagtail-config.schema.json")
|
|
12
|
+
DEFAULT_COMPOSE_FILE = Path(".devcontainer/docker-compose.yml")
|
|
13
|
+
DEFAULT_PROJECT_NAME = "mysite"
|
|
14
|
+
DEFAULT_COMPOSE_PROJECT = "xgic-wagtail"
|
|
15
|
+
DEFAULT_DB_ADAPTER = "postgres"
|
|
16
|
+
DEFAULT_DB_NAME = "wagtail"
|
|
17
|
+
DEFAULT_DB_USER = "wagtail"
|
|
18
|
+
ALLOWED_DB_ADAPTERS = frozenset({DEFAULT_DB_ADAPTER})
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _is_compose_safe_name(name: str) -> bool:
|
|
22
|
+
if not name or not name[0].isalnum():
|
|
23
|
+
return False
|
|
24
|
+
return all(c.isalnum() or c in "_-" for c in name) and len(name) <= 63
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def load_create_wagtail_config(
|
|
28
|
+
config_path: Path = DEFAULT_CONFIG_FILE,
|
|
29
|
+
) -> dict[str, Any]:
|
|
30
|
+
"""Load create-wagtail-config.json or return XGIC defaults."""
|
|
31
|
+
defaults: dict[str, Any] = {
|
|
32
|
+
"projectName": DEFAULT_PROJECT_NAME,
|
|
33
|
+
"composeProjectName": DEFAULT_COMPOSE_PROJECT,
|
|
34
|
+
"dbAdapter": DEFAULT_DB_ADAPTER,
|
|
35
|
+
"dbName": DEFAULT_DB_NAME,
|
|
36
|
+
"dbUser": DEFAULT_DB_USER,
|
|
37
|
+
}
|
|
38
|
+
if not config_path.is_file():
|
|
39
|
+
return defaults
|
|
40
|
+
try:
|
|
41
|
+
data = json.loads(config_path.read_text(encoding="utf-8"))
|
|
42
|
+
except (json.JSONDecodeError, OSError):
|
|
43
|
+
return defaults
|
|
44
|
+
if not isinstance(data, dict):
|
|
45
|
+
return defaults
|
|
46
|
+
for key, value in data.items():
|
|
47
|
+
if key == "$schema":
|
|
48
|
+
continue
|
|
49
|
+
if value is not None:
|
|
50
|
+
defaults[key] = value
|
|
51
|
+
return defaults
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def get_project_name(config: dict[str, Any] | None = None) -> str:
|
|
55
|
+
"""Return Django/Wagtail project package name."""
|
|
56
|
+
cfg = config if config is not None else load_create_wagtail_config()
|
|
57
|
+
name = cfg.get("projectName")
|
|
58
|
+
if isinstance(name, str) and name.strip():
|
|
59
|
+
return name.strip()
|
|
60
|
+
return DEFAULT_PROJECT_NAME
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def get_db_adapter(config: dict[str, Any] | None = None) -> str:
|
|
64
|
+
"""Return database adapter (XGIC default: postgres)."""
|
|
65
|
+
cfg = config if config is not None else load_create_wagtail_config()
|
|
66
|
+
adapter = str(cfg.get("dbAdapter") or DEFAULT_DB_ADAPTER).strip().lower()
|
|
67
|
+
if adapter in {"postgresql", "psql"}:
|
|
68
|
+
return DEFAULT_DB_ADAPTER
|
|
69
|
+
return adapter or DEFAULT_DB_ADAPTER
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def get_db_config(config: dict[str, Any] | None = None) -> tuple[str, str]:
|
|
73
|
+
"""Return ``(dbName, dbUser)``."""
|
|
74
|
+
cfg = config if config is not None else load_create_wagtail_config()
|
|
75
|
+
db_name = str(cfg.get("dbName") or DEFAULT_DB_NAME).strip() or DEFAULT_DB_NAME
|
|
76
|
+
db_user = str(cfg.get("dbUser") or DEFAULT_DB_USER).strip() or DEFAULT_DB_USER
|
|
77
|
+
return db_name, db_user
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def get_compose_project_name(config: dict[str, Any] | None = None) -> str:
|
|
81
|
+
"""Return Docker Compose project name.
|
|
82
|
+
|
|
83
|
+
Precedence: ``XGIC_COMPOSE_PROJECT``, config ``composeProjectName``,
|
|
84
|
+
Compose file ``name:``, then ``DEFAULT_COMPOSE_PROJECT``.
|
|
85
|
+
"""
|
|
86
|
+
env_name = os.environ.get("XGIC_COMPOSE_PROJECT", "").strip().lower()
|
|
87
|
+
if env_name and _is_compose_safe_name(env_name):
|
|
88
|
+
return env_name
|
|
89
|
+
cfg = config if config is not None else load_create_wagtail_config()
|
|
90
|
+
named = str(cfg.get("composeProjectName") or "").strip().lower()
|
|
91
|
+
if named and _is_compose_safe_name(named):
|
|
92
|
+
return named
|
|
93
|
+
compose_name = _compose_name_from_file(DEFAULT_COMPOSE_FILE)
|
|
94
|
+
if compose_name:
|
|
95
|
+
return compose_name
|
|
96
|
+
return DEFAULT_COMPOSE_PROJECT
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _compose_name_from_file(compose_path: Path) -> str | None:
|
|
100
|
+
if not compose_path.is_file():
|
|
101
|
+
return None
|
|
102
|
+
try:
|
|
103
|
+
for line in compose_path.read_text(encoding="utf-8").splitlines():
|
|
104
|
+
stripped = line.strip()
|
|
105
|
+
if stripped.startswith("#") or not stripped.startswith("name:"):
|
|
106
|
+
continue
|
|
107
|
+
raw = stripped.split(":", 1)[1].strip().strip("\"'")
|
|
108
|
+
if raw and _is_compose_safe_name(raw.lower()):
|
|
109
|
+
return raw.lower()
|
|
110
|
+
except OSError:
|
|
111
|
+
return None
|
|
112
|
+
return None
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""Compose ``.devcontainer/.env`` helpers for Wagtail + PostgreSQL."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from xgic.cli.wagtail.config import (
|
|
9
|
+
DEFAULT_CONFIG_FILE,
|
|
10
|
+
get_db_config,
|
|
11
|
+
load_create_wagtail_config,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
ENV_FILE = Path(".devcontainer/.env")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def parse_dotenv(content: str) -> dict[str, str]:
|
|
18
|
+
"""Parse KEY=value assignments from .env text (last key wins)."""
|
|
19
|
+
values: dict[str, str] = {}
|
|
20
|
+
for line in content.splitlines():
|
|
21
|
+
stripped = line.strip()
|
|
22
|
+
if not stripped or stripped.startswith("#") or "=" not in stripped:
|
|
23
|
+
continue
|
|
24
|
+
key, _, value = stripped.partition("=")
|
|
25
|
+
key = key.strip()
|
|
26
|
+
if not key:
|
|
27
|
+
continue
|
|
28
|
+
values[key] = value.strip().strip('"').strip("'")
|
|
29
|
+
return values
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def generate_env_content(
|
|
33
|
+
*,
|
|
34
|
+
config: dict[str, Any] | None = None,
|
|
35
|
+
preserve: dict[str, str] | None = None,
|
|
36
|
+
) -> str:
|
|
37
|
+
"""Return compose .env content for PostgreSQL.
|
|
38
|
+
|
|
39
|
+
First-run uses a stable local password when none is preserved so an
|
|
40
|
+
already-started Compose Postgres with the template default still matches.
|
|
41
|
+
"""
|
|
42
|
+
cfg = config if config is not None else load_create_wagtail_config()
|
|
43
|
+
db_name, db_user = get_db_config(cfg)
|
|
44
|
+
kept = preserve or {}
|
|
45
|
+
password = kept.get("POSTGRES_PASSWORD") or "wagtail"
|
|
46
|
+
return (
|
|
47
|
+
f"POSTGRES_USER={db_user}\n"
|
|
48
|
+
f"POSTGRES_PASSWORD={password}\n"
|
|
49
|
+
f"POSTGRES_DB={db_name}\n"
|
|
50
|
+
f"PGUSER={db_user}\n"
|
|
51
|
+
f"PGDATABASE={db_name}\n"
|
|
52
|
+
f"POSTGRES_HOST=postgres\n"
|
|
53
|
+
f"POSTGRES_PORT=5432\n"
|
|
54
|
+
f"DATABASE_URL=postgres://{db_user}:{password}@postgres:5432/{db_name}\n"
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def ensure_devcontainer_env(
|
|
59
|
+
*,
|
|
60
|
+
config_path: Path = DEFAULT_CONFIG_FILE,
|
|
61
|
+
env_file: Path = ENV_FILE,
|
|
62
|
+
) -> bool:
|
|
63
|
+
"""Create ``.devcontainer/.env`` when missing. Return True if written."""
|
|
64
|
+
if env_file.is_file():
|
|
65
|
+
return False
|
|
66
|
+
cfg = load_create_wagtail_config(config_path)
|
|
67
|
+
env_file.parent.mkdir(parents=True, exist_ok=True)
|
|
68
|
+
env_file.write_text(generate_env_content(config=cfg), encoding="utf-8")
|
|
69
|
+
return True
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""Register ``xgic.cli.wagtail`` subcommands on the core ``xgic`` CLI.
|
|
2
|
+
|
|
3
|
+
Product commands live under the ``wagtail`` group::
|
|
4
|
+
|
|
5
|
+
xgic wagtail
|
|
6
|
+
xgic wagtail info
|
|
7
|
+
xgic wagtail setup
|
|
8
|
+
xgic wagtail schema
|
|
9
|
+
xgic wagtail dev
|
|
10
|
+
xgic wagtail --help
|
|
11
|
+
|
|
12
|
+
Missing ACTION prints full usage (not a short argparse required-args error).
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import argparse
|
|
18
|
+
|
|
19
|
+
from xgic.cli.wagtail.commands.dev import run_dev
|
|
20
|
+
from xgic.cli.wagtail.commands.info import run_info
|
|
21
|
+
from xgic.cli.wagtail.commands.schema import run_schema
|
|
22
|
+
from xgic.cli.wagtail.commands.setup import run_setup
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def register(
|
|
26
|
+
subparsers: argparse._SubParsersAction[argparse.ArgumentParser],
|
|
27
|
+
) -> None:
|
|
28
|
+
"""Entry point: ``xgic.cli.commands`` → Wagtail product commands."""
|
|
29
|
+
wagtail = subparsers.add_parser(
|
|
30
|
+
"wagtail",
|
|
31
|
+
help="Wagtail product commands",
|
|
32
|
+
description="Wagtail CMS commands for the modular XGIC CLI.",
|
|
33
|
+
)
|
|
34
|
+
wagtail_sub = wagtail.add_subparsers(
|
|
35
|
+
dest="wagtail_command",
|
|
36
|
+
help="Wagtail action",
|
|
37
|
+
metavar="ACTION",
|
|
38
|
+
required=False,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
def _missing_action(_args: argparse.Namespace) -> int:
|
|
42
|
+
wagtail.print_help()
|
|
43
|
+
return 2
|
|
44
|
+
|
|
45
|
+
wagtail.set_defaults(func=_missing_action)
|
|
46
|
+
|
|
47
|
+
info = wagtail_sub.add_parser(
|
|
48
|
+
"info",
|
|
49
|
+
help="Show Wagtail CLI module version and status",
|
|
50
|
+
)
|
|
51
|
+
info.add_argument(
|
|
52
|
+
"--json",
|
|
53
|
+
action="store_true",
|
|
54
|
+
help="Output as JSON",
|
|
55
|
+
)
|
|
56
|
+
info.set_defaults(func=run_info)
|
|
57
|
+
|
|
58
|
+
setup = wagtail_sub.add_parser(
|
|
59
|
+
"setup",
|
|
60
|
+
help="Ensure Wagtail site with PostgreSQL (idempotent)",
|
|
61
|
+
)
|
|
62
|
+
setup.add_argument(
|
|
63
|
+
"--quiet",
|
|
64
|
+
action="store_true",
|
|
65
|
+
help="Suppress non-error output",
|
|
66
|
+
)
|
|
67
|
+
setup.set_defaults(func=run_setup)
|
|
68
|
+
|
|
69
|
+
schema = wagtail_sub.add_parser(
|
|
70
|
+
"schema",
|
|
71
|
+
help="Write create-wagtail-config JSON Schema (editor IntelliSense)",
|
|
72
|
+
)
|
|
73
|
+
schema.add_argument(
|
|
74
|
+
"--output",
|
|
75
|
+
metavar="PATH",
|
|
76
|
+
help="Override schema output path",
|
|
77
|
+
)
|
|
78
|
+
schema.set_defaults(func=run_schema)
|
|
79
|
+
|
|
80
|
+
dev = wagtail_sub.add_parser(
|
|
81
|
+
"dev",
|
|
82
|
+
help="Migrate and run the Wagtail/Django development server",
|
|
83
|
+
)
|
|
84
|
+
dev.add_argument(
|
|
85
|
+
"--quiet",
|
|
86
|
+
action="store_true",
|
|
87
|
+
help="Suppress non-error output",
|
|
88
|
+
)
|
|
89
|
+
dev.set_defaults(func=run_dev)
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"""Idempotent Wagtail project ensure (PostgreSQL default)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
import shutil
|
|
9
|
+
import subprocess
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from xgic.cli.utils.output import print_info, print_success, print_warning
|
|
14
|
+
from xgic.cli.wagtail.config import (
|
|
15
|
+
ALLOWED_DB_ADAPTERS,
|
|
16
|
+
DEFAULT_CONFIG_FILE,
|
|
17
|
+
DEFAULT_DB_ADAPTER,
|
|
18
|
+
DEFAULT_SCHEMA_FILE,
|
|
19
|
+
get_db_adapter,
|
|
20
|
+
get_project_name,
|
|
21
|
+
load_create_wagtail_config,
|
|
22
|
+
)
|
|
23
|
+
from xgic.cli.wagtail.env_helpers import ensure_devcontainer_env
|
|
24
|
+
from xgic.cli.wagtail.schema import write_schema
|
|
25
|
+
|
|
26
|
+
POSTGRES_DATABASES_BLOCK = """DATABASES = {
|
|
27
|
+
"default": {
|
|
28
|
+
"ENGINE": "django.db.backends.postgresql",
|
|
29
|
+
"NAME": os.environ.get("POSTGRES_DB", "wagtail"),
|
|
30
|
+
"USER": os.environ.get("POSTGRES_USER", "wagtail"),
|
|
31
|
+
"PASSWORD": os.environ.get("POSTGRES_PASSWORD", ""),
|
|
32
|
+
"HOST": os.environ.get("POSTGRES_HOST", "postgres"),
|
|
33
|
+
"PORT": os.environ.get("POSTGRES_PORT", "5432"),
|
|
34
|
+
"CONN_MAX_AGE": 600,
|
|
35
|
+
}
|
|
36
|
+
}"""
|
|
37
|
+
|
|
38
|
+
_DATABASES_RE = re.compile(
|
|
39
|
+
r"DATABASES\s*=\s*\{(?:[^{}]|\{[^{}]*\})*\}",
|
|
40
|
+
re.DOTALL,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def is_wagtail_project_complete(root: Path | None = None) -> bool:
|
|
45
|
+
"""Return True when ``manage.py`` and a Django settings package exist."""
|
|
46
|
+
base = Path.cwd() if root is None else root
|
|
47
|
+
if not (base / "manage.py").is_file():
|
|
48
|
+
return False
|
|
49
|
+
return find_settings_base(base) is not None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def find_settings_base(root: Path | None = None) -> Path | None:
|
|
53
|
+
"""Locate ``settings/base.py`` under the workspace (skip virtualenvs)."""
|
|
54
|
+
base = Path.cwd() if root is None else root
|
|
55
|
+
skip = {".venv", "venv", "node_modules", ".git"}
|
|
56
|
+
for path in base.rglob("settings/base.py"):
|
|
57
|
+
if skip.intersection(path.relative_to(base).parts):
|
|
58
|
+
continue
|
|
59
|
+
return path
|
|
60
|
+
return None
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def ensure_import_os(text: str) -> str:
|
|
64
|
+
"""Ensure ``import os`` is present in a Django settings module."""
|
|
65
|
+
if re.search(r"(?m)^import os\s*$", text):
|
|
66
|
+
return text
|
|
67
|
+
if re.search(r"(?m)^from pathlib import Path\s*$", text):
|
|
68
|
+
return re.sub(
|
|
69
|
+
r"(?m)^(from pathlib import Path\s*)$",
|
|
70
|
+
r"\1\nimport os",
|
|
71
|
+
text,
|
|
72
|
+
count=1,
|
|
73
|
+
)
|
|
74
|
+
return "import os\n" + text
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def patch_databases(text: str) -> tuple[str, bool]:
|
|
78
|
+
"""Replace SQLite DATABASES with env-driven PostgreSQL. Return (text, changed)."""
|
|
79
|
+
if 'django.db.backends.postgresql' in text and "os.environ.get(\"POSTGRES_DB\"" in text:
|
|
80
|
+
return text, False
|
|
81
|
+
match = _DATABASES_RE.search(text)
|
|
82
|
+
if match is None:
|
|
83
|
+
return text, False
|
|
84
|
+
updated = text[: match.start()] + POSTGRES_DATABASES_BLOCK + text[match.end() :]
|
|
85
|
+
updated = ensure_import_os(updated)
|
|
86
|
+
return updated, updated != text
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
# Inserted into the generated project's settings/base.py INSTALLED_APPS,
|
|
90
|
+
# immediately before django.contrib.admin (Wagtail start template).
|
|
91
|
+
_POSTGRES_APP_INSERT = (
|
|
92
|
+
'"django.contrib.postgres", '
|
|
93
|
+
"# Wagtail postgres search (SearchVectorField / GinIndex)\n"
|
|
94
|
+
' "django.contrib.admin"'
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def ensure_postgres_installed_apps(text: str) -> tuple[str, bool]:
|
|
99
|
+
"""Insert ``django.contrib.postgres`` into generated ``INSTALLED_APPS``.
|
|
100
|
+
|
|
101
|
+
**Where:** ``<project>/settings/base.py`` created by ``wagtail start``,
|
|
102
|
+
in the Django contrib block, immediately before ``django.contrib.admin``.
|
|
103
|
+
Not added to the thin GitHub template itself.
|
|
104
|
+
|
|
105
|
+
**Why:** Wagtail's default database search backend on PostgreSQL uses
|
|
106
|
+
``SearchVectorField`` and ``GinIndex``. Without this app, ``migrate``
|
|
107
|
+
fails with ``postgres.E005``. The stock ``wagtail start`` template omits
|
|
108
|
+
it because it defaults to SQLite.
|
|
109
|
+
"""
|
|
110
|
+
if "django.contrib.postgres" in text:
|
|
111
|
+
return text, False
|
|
112
|
+
needle = '"django.contrib.admin"'
|
|
113
|
+
if needle not in text:
|
|
114
|
+
return text, False
|
|
115
|
+
updated = text.replace(needle, _POSTGRES_APP_INSERT, 1)
|
|
116
|
+
return updated, updated != text
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def patch_settings_base(settings_base: Path) -> bool:
|
|
120
|
+
"""Patch generated ``settings/base.py``: PostgreSQL DATABASES + INSTALLED_APPS."""
|
|
121
|
+
original = settings_base.read_text(encoding="utf-8")
|
|
122
|
+
updated, db_changed = patch_databases(original)
|
|
123
|
+
updated, apps_changed = ensure_postgres_installed_apps(updated)
|
|
124
|
+
if not db_changed and not apps_changed:
|
|
125
|
+
return False
|
|
126
|
+
settings_base.write_text(updated, encoding="utf-8")
|
|
127
|
+
return True
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def remove_generated_docker_files(root: Path) -> list[str]:
|
|
131
|
+
"""Remove Wagtail start Dockerfile artifacts (template consumes GHCR)."""
|
|
132
|
+
removed: list[str] = []
|
|
133
|
+
for name in ("Dockerfile", ".dockerignore"):
|
|
134
|
+
path = root / name
|
|
135
|
+
if path.is_file():
|
|
136
|
+
path.unlink()
|
|
137
|
+
removed.append(name)
|
|
138
|
+
return removed
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def default_config_document(project_name: str) -> dict[str, Any]:
|
|
142
|
+
"""Return a new create-wagtail-config.json document."""
|
|
143
|
+
return {
|
|
144
|
+
"$schema": "./create-wagtail-config.schema.json",
|
|
145
|
+
"projectName": project_name,
|
|
146
|
+
"composeProjectName": "xgic-wagtail",
|
|
147
|
+
"dbAdapter": DEFAULT_DB_ADAPTER,
|
|
148
|
+
"dbName": "wagtail",
|
|
149
|
+
"dbUser": "wagtail",
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def ensure_config_file(
|
|
154
|
+
path: Path = DEFAULT_CONFIG_FILE,
|
|
155
|
+
*,
|
|
156
|
+
project_name: str | None = None,
|
|
157
|
+
) -> bool:
|
|
158
|
+
"""Write create-wagtail-config.json when missing. Return True if written."""
|
|
159
|
+
if path.is_file():
|
|
160
|
+
return False
|
|
161
|
+
name = project_name or get_project_name()
|
|
162
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
163
|
+
path.write_text(
|
|
164
|
+
json.dumps(default_config_document(name), indent=2) + "\n",
|
|
165
|
+
encoding="utf-8",
|
|
166
|
+
)
|
|
167
|
+
return True
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def run_wagtail_start(project_name: str, dest: Path) -> int:
|
|
171
|
+
"""Run ``wagtail start <name> .`` in *dest*. Return process exit code."""
|
|
172
|
+
exe = shutil.which("wagtail")
|
|
173
|
+
if exe is None:
|
|
174
|
+
print_warning(
|
|
175
|
+
"wagtail is not on PATH. Reopen in the Dev Container image "
|
|
176
|
+
"(ghcr.io/xgic/wagtail-dev) or install Wagtail 8.0."
|
|
177
|
+
)
|
|
178
|
+
return 1
|
|
179
|
+
result = subprocess.run(
|
|
180
|
+
[exe, "start", project_name, "."],
|
|
181
|
+
cwd=str(dest),
|
|
182
|
+
check=False,
|
|
183
|
+
)
|
|
184
|
+
return int(result.returncode)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def ensure_wagtail_project(
|
|
188
|
+
*,
|
|
189
|
+
quiet: bool = False,
|
|
190
|
+
root: Path | None = None,
|
|
191
|
+
) -> int:
|
|
192
|
+
"""Idempotent first-run: config, env, wagtail start, PostgreSQL settings."""
|
|
193
|
+
base = Path.cwd() if root is None else root
|
|
194
|
+
orig = Path.cwd()
|
|
195
|
+
os.chdir(base)
|
|
196
|
+
try:
|
|
197
|
+
return _ensure_wagtail_project(quiet=quiet, root=base)
|
|
198
|
+
finally:
|
|
199
|
+
os.chdir(orig)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _ensure_wagtail_project(*, quiet: bool, root: Path) -> int:
|
|
203
|
+
cfg = load_create_wagtail_config(root / DEFAULT_CONFIG_FILE)
|
|
204
|
+
adapter = get_db_adapter(cfg)
|
|
205
|
+
if adapter not in ALLOWED_DB_ADAPTERS:
|
|
206
|
+
print_warning(
|
|
207
|
+
f"dbAdapter {adapter!r} is not supported. "
|
|
208
|
+
"XGIC default is PostgreSQL (set dbAdapter to 'postgres')."
|
|
209
|
+
)
|
|
210
|
+
return 1
|
|
211
|
+
|
|
212
|
+
project_name = get_project_name(cfg)
|
|
213
|
+
wrote_schema = False
|
|
214
|
+
schema_path = root / DEFAULT_SCHEMA_FILE
|
|
215
|
+
if not schema_path.is_file():
|
|
216
|
+
write_schema(schema_path)
|
|
217
|
+
wrote_schema = True
|
|
218
|
+
wrote_config = ensure_config_file(
|
|
219
|
+
root / DEFAULT_CONFIG_FILE,
|
|
220
|
+
project_name=project_name,
|
|
221
|
+
)
|
|
222
|
+
wrote_env = ensure_devcontainer_env(
|
|
223
|
+
config_path=root / DEFAULT_CONFIG_FILE,
|
|
224
|
+
env_file=root / ".devcontainer" / ".env",
|
|
225
|
+
)
|
|
226
|
+
if not quiet:
|
|
227
|
+
if wrote_schema:
|
|
228
|
+
print_info(f"Wrote {DEFAULT_SCHEMA_FILE}")
|
|
229
|
+
if wrote_config:
|
|
230
|
+
print_info(f"Wrote {DEFAULT_CONFIG_FILE}")
|
|
231
|
+
if wrote_env:
|
|
232
|
+
print_info("Wrote .devcontainer/.env (Compose Postgres credentials)")
|
|
233
|
+
|
|
234
|
+
if is_wagtail_project_complete(root):
|
|
235
|
+
settings_base = find_settings_base(root)
|
|
236
|
+
changed = patch_settings_base(settings_base) if settings_base else False
|
|
237
|
+
if not quiet:
|
|
238
|
+
if changed:
|
|
239
|
+
print_success("Django DATABASES now use Compose PostgreSQL.")
|
|
240
|
+
else:
|
|
241
|
+
print_success("Wagtail project already present (PostgreSQL settings).")
|
|
242
|
+
return 0
|
|
243
|
+
|
|
244
|
+
if not quiet:
|
|
245
|
+
print_info(f"Running: wagtail start {project_name} .")
|
|
246
|
+
rc = run_wagtail_start(project_name, root)
|
|
247
|
+
if rc != 0:
|
|
248
|
+
return rc
|
|
249
|
+
|
|
250
|
+
removed = remove_generated_docker_files(root)
|
|
251
|
+
if removed and not quiet:
|
|
252
|
+
print_info(
|
|
253
|
+
"Removed generated "
|
|
254
|
+
+ ", ".join(removed)
|
|
255
|
+
+ " (template consumes ghcr.io/xgic/wagtail-dev)."
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
settings_base = find_settings_base(root)
|
|
259
|
+
if settings_base is None:
|
|
260
|
+
print_warning("wagtail start finished but settings/base.py was not found.")
|
|
261
|
+
return 1
|
|
262
|
+
patch_settings_base(settings_base)
|
|
263
|
+
if not quiet:
|
|
264
|
+
print_success(
|
|
265
|
+
"Wagtail site scaffolded with PostgreSQL "
|
|
266
|
+
"(POSTGRES_HOST=postgres). Next: python manage.py migrate"
|
|
267
|
+
)
|
|
268
|
+
return 0
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""JSON Schema for ``create-wagtail-config.json`` (editor IntelliSense)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from xgic.cli.wagtail.config import DEFAULT_SCHEMA_FILE
|
|
9
|
+
|
|
10
|
+
WAGTAIL_CONFIG_SCHEMA: dict[str, object] = {
|
|
11
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
12
|
+
"title": "XGIC Wagtail create-wagtail-config",
|
|
13
|
+
"description": (
|
|
14
|
+
"Workspace config for xgic wagtail setup. "
|
|
15
|
+
"XGIC default database is PostgreSQL. SQLite is not supported."
|
|
16
|
+
),
|
|
17
|
+
"type": "object",
|
|
18
|
+
"additionalProperties": False,
|
|
19
|
+
"required": ["projectName", "dbAdapter"],
|
|
20
|
+
"properties": {
|
|
21
|
+
"$schema": {"type": "string"},
|
|
22
|
+
"projectName": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"pattern": "^[A-Za-z][A-Za-z0-9_]*$",
|
|
25
|
+
"description": (
|
|
26
|
+
"Django project package name passed to `wagtail start` "
|
|
27
|
+
"(letters, digits, underscore)."
|
|
28
|
+
),
|
|
29
|
+
"examples": ["mysite", "website"],
|
|
30
|
+
},
|
|
31
|
+
"composeProjectName": {
|
|
32
|
+
"type": "string",
|
|
33
|
+
"pattern": "^[a-z0-9][a-z0-9_-]{0,62}$",
|
|
34
|
+
"description": "Docker Compose project name for this workspace.",
|
|
35
|
+
"examples": ["xgic-wagtail"],
|
|
36
|
+
},
|
|
37
|
+
"dbAdapter": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"enum": ["postgres"],
|
|
40
|
+
"description": "Database adapter. XGIC default and only supported value is postgres.",
|
|
41
|
+
},
|
|
42
|
+
"dbName": {
|
|
43
|
+
"type": "string",
|
|
44
|
+
"minLength": 1,
|
|
45
|
+
"description": "PostgreSQL database name (Compose POSTGRES_DB).",
|
|
46
|
+
"examples": ["wagtail"],
|
|
47
|
+
},
|
|
48
|
+
"dbUser": {
|
|
49
|
+
"type": "string",
|
|
50
|
+
"minLength": 1,
|
|
51
|
+
"description": "PostgreSQL role (Compose POSTGRES_USER / PGUSER).",
|
|
52
|
+
"examples": ["wagtail"],
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def write_schema(path: Path = DEFAULT_SCHEMA_FILE) -> Path:
|
|
59
|
+
"""Write the schema JSON file and return the path."""
|
|
60
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
61
|
+
path.write_text(json.dumps(WAGTAIL_CONFIG_SCHEMA, indent=2) + "\n", encoding="utf-8")
|
|
62
|
+
return path
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: xgic-wagtail-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: XGIC CLI Wagtail module - Wagtail product commands (xgic.cli.wagtail).
|
|
5
|
+
Project-URL: Homepage, https://github.com/xgic/wagtail-cli
|
|
6
|
+
Project-URL: Repository, https://github.com/xgic/wagtail-cli
|
|
7
|
+
Project-URL: Issues, https://github.com/xgic/wagtail-cli/issues
|
|
8
|
+
Project-URL: Documentation, https://github.com/xgic/wagtail-cli#readme
|
|
9
|
+
Project-URL: Changelog, https://github.com/xgic/wagtail-cli/releases
|
|
10
|
+
Author: XGIC
|
|
11
|
+
License: Apache-2.0
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
License-File: NOTICE
|
|
14
|
+
Keywords: cli,cms,django,wagtail,xgic
|
|
15
|
+
Classifier: Development Status :: 3 - Alpha
|
|
16
|
+
Classifier: Environment :: Console
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.14
|
|
25
|
+
Requires-Dist: rich>=13.7
|
|
26
|
+
Requires-Dist: xgic-cli>=0.2.1
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: ruff>=0.4.0; extra == 'dev'
|
|
31
|
+
Provides-Extra: test
|
|
32
|
+
Requires-Dist: pytest>=8.0.0; extra == 'test'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# XGIC Wagtail CLI
|
|
36
|
+
|
|
37
|
+
[](LICENSE)
|
|
38
|
+
[](https://github.com/xgic/wagtail-cli/actions/workflows/ci.yml)
|
|
39
|
+
[](https://pypi.org/project/xgic-wagtail-cli/)
|
|
40
|
+
[](https://www.python.org/)
|
|
41
|
+
[](https://github.com/xgic/wagtail-cli/releases)
|
|
42
|
+
[](https://github.com/xgic/wagtail-dev/releases)
|
|
43
|
+
[](https://github.com/users/xgic/packages/container/package/wagtail-dev)
|
|
44
|
+
|
|
45
|
+
**Wagtail product commands for the modular [XGIC CLI](https://github.com/xgic/cli)—ops under
|
|
46
|
+
`xgic wagtail …`.**
|
|
47
|
+
|
|
48
|
+
Namespace: **`xgic.cli.wagtail`** · Console group: **`xgic wagtail …`** · Brand: **XGIC CLI only**
|
|
49
|
+
([ADR-0005](https://github.com/xgic/ai/blob/main/docs/adr/0005-modular-xgic-cli-and-retirement-of-xde.md))
|
|
50
|
+
|
|
51
|
+
Standards hub: [xgic/ai](https://github.com/xgic/ai) ·
|
|
52
|
+
[README standards](https://github.com/xgic/ai/blob/main/docs/readme-standards.md) ·
|
|
53
|
+
Default CMS: [ADR-0006](https://github.com/xgic/ai/blob/main/docs/adr/0006-adopt-wagtail.md)
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Vision
|
|
58
|
+
|
|
59
|
+
Wagtail is the default CMS for new XGIC work. This module owns the **Wagtail product**
|
|
60
|
+
namespace under `xgic` so humans and agents share one command map. The thin site
|
|
61
|
+
template lives in [xgic/wagtail](https://github.com/xgic/wagtail); the Dev Container
|
|
62
|
+
**producer** (`ghcr.io/xgic/wagtail-dev`) lives in [xgic/wagtail-dev](https://github.com/xgic/wagtail-dev).
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Why this module exists
|
|
67
|
+
|
|
68
|
+
| Benefit | Detail |
|
|
69
|
+
|---------|--------|
|
|
70
|
+
| **Domain clarity** | Nested under `xgic wagtail`—no clash with core or other CMS modules |
|
|
71
|
+
| **Composable stack** | Depends on `xgic-cli` only |
|
|
72
|
+
| **Usage UX** | Missing ACTION prints **full usage**, matching top-level `xgic` |
|
|
73
|
+
| **AI + human parity** | Same command map in README and [AGENTS.md](AGENTS.md) |
|
|
74
|
+
| **Open-source rigor** | Apache-2.0, Python 3.14+, RC → TestPyPI → PyPI |
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Ecosystem
|
|
79
|
+
|
|
80
|
+
| Package / repo | Role |
|
|
81
|
+
|----------------|------|
|
|
82
|
+
| [xgic/cli](https://github.com/xgic/cli) | Thin core framework (`xgic`) |
|
|
83
|
+
| **This repo** | Wagtail product module (`xgic.cli.wagtail`) |
|
|
84
|
+
| [xgic/wagtail-dev](https://github.com/xgic/wagtail-dev) | Official image pins + contributor Compose |
|
|
85
|
+
| [xgic/wagtail](https://github.com/xgic/wagtail) | End-user site **template** |
|
|
86
|
+
|
|
87
|
+
Architecture: [ADR-0001](https://github.com/xgic/ai/blob/main/docs/adr/0001-xgic-gitlab-architecture-and-repository-naming.md)
|
|
88
|
+
· [ADR-0005](https://github.com/xgic/ai/blob/main/docs/adr/0005-modular-xgic-cli-and-retirement-of-xde.md)
|
|
89
|
+
· [ADR-0006](https://github.com/xgic/ai/blob/main/docs/adr/0006-adopt-wagtail.md).
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Quick start
|
|
94
|
+
|
|
95
|
+
### Development (editable)
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
uv pip install -e ../cli
|
|
99
|
+
uv pip install -e ".[dev]"
|
|
100
|
+
xgic wagtail
|
|
101
|
+
xgic wagtail info
|
|
102
|
+
xgic wagtail setup
|
|
103
|
+
xgic wagtail dev
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
`xgic wagtail` with no action prints full usage and exits `2`.
|
|
107
|
+
`xgic wagtail dev` waits for PostgreSQL, runs `migrate --noinput`, then
|
|
108
|
+
`python manage.py runserver 0.0.0.0:8000`. Requires a site from `setup`.
|
|
109
|
+
`xgic wagtail setup` is idempotent: config JSON, Compose `.env`, `wagtail start` when missing, Django `DATABASES` on **PostgreSQL**, and `django.contrib.postgres` in the generated `<project>/settings/base.py` `INSTALLED_APPS` (immediately before `django.contrib.admin`, for Wagtail search `SearchVectorField` / `GinIndex`). SQLite is not an XGIC default. The thin GitHub template does not vendor that settings file.
|
|
110
|
+
|
|
111
|
+
### Install (PyPI)
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
uv pip install "xgic-cli>=0.2.1" "xgic-wagtail-cli>=0.1.0"
|
|
115
|
+
xgic wagtail --help
|
|
116
|
+
xgic wagtail info
|
|
117
|
+
xgic wagtail setup
|
|
118
|
+
xgic wagtail dev
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
PyPI publish follows the hub
|
|
122
|
+
[python-package-release.md](https://github.com/xgic/ai/blob/main/docs/python-package-release.md)
|
|
123
|
+
path (RC → TestPyPI → PyPI).
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Commands
|
|
128
|
+
|
|
129
|
+
| Command | Purpose |
|
|
130
|
+
|---------|---------|
|
|
131
|
+
| `xgic wagtail` | Full usage (missing ACTION) |
|
|
132
|
+
| `xgic wagtail info` | Module identity (`--json` for machine output) |
|
|
133
|
+
| `xgic wagtail setup [--quiet]` | First-run: config JSON, `.devcontainer/.env`, `wagtail start` if needed, PostgreSQL `DATABASES` + `django.contrib.postgres` in generated `settings/base.py` |
|
|
134
|
+
| `xgic wagtail schema [--output PATH]` | Write JSON Schema for `create-wagtail-config.json` (IntelliSense) |
|
|
135
|
+
| `xgic wagtail --help` | Same usage listing |
|
|
136
|
+
|
|
137
|
+
`dbAdapter` is **postgres** only. Dev-server helpers remain planned.
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Contributing
|
|
142
|
+
|
|
143
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). Human review in the GitHub UI before merge.
|
|
144
|
+
Labels required. Public-safe content only.
|
|
145
|
+
|
|
146
|
+
## License
|
|
147
|
+
|
|
148
|
+
Apache License 2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
xgic/cli/wagtail/__init__.py,sha256=FBXwZDIZ16Iaug4upMCvRueghYG8TuhemkD6LgC2F6c,104
|
|
2
|
+
xgic/cli/wagtail/config.py,sha256=IkeKgRi87ER0mzAkKfSoa3VB8pn4HmaLxxpIUhwDQEU,4088
|
|
3
|
+
xgic/cli/wagtail/env_helpers.py,sha256=HD5v3kF2M4t8V8g1cJf_hwnqHIUKTEoSZYkmMU_cC2I,2159
|
|
4
|
+
xgic/cli/wagtail/plugin.py,sha256=pCV4rJdpGSupPzUTKoyNpKYJaZFoOFPQuxQVBniuxhI,2387
|
|
5
|
+
xgic/cli/wagtail/project.py,sha256=J0rnhtWcCCJdLf28Jx71qXwCtoKMdd-0tCKXy7e8RbQ,8955
|
|
6
|
+
xgic/cli/wagtail/schema.py,sha256=e_U5ZJXaYN01lwpRiTS8bOm-rx-7G0gKTu7hrdWfOPA,2144
|
|
7
|
+
xgic/cli/wagtail/commands/__init__.py,sha256=bH-Z7dLseNZPFZ1mWCufp6zZWX6-Kz0lDL66BqQn0Fs,36
|
|
8
|
+
xgic/cli/wagtail/commands/dev.py,sha256=QzLjVmlPfD5PN4MfrHMIPBorw4X_3A-mQHEUKnxJSDs,2976
|
|
9
|
+
xgic/cli/wagtail/commands/info.py,sha256=t69q4tHIkck6Rpr-we53CcIEC5vznlNsKmhUTm1-TPs,1157
|
|
10
|
+
xgic/cli/wagtail/commands/schema.py,sha256=XlehTr9V8VS90SEQ5T6977sGhnalKLk2SJmvYeR6MkM,807
|
|
11
|
+
xgic/cli/wagtail/commands/setup.py,sha256=a825GWjsabUiCNXJ-BrfJ_1WNCOfz6OSUjqN5u65zQ0,417
|
|
12
|
+
xgic_wagtail_cli-0.1.0.dist-info/METADATA,sha256=TSUngguJwMUPm0Te079D3g1WaHs4Esq3fUGqIFiwxRA,6332
|
|
13
|
+
xgic_wagtail_cli-0.1.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
14
|
+
xgic_wagtail_cli-0.1.0.dist-info/entry_points.txt,sha256=gS09xQPHkyNcE2gtUSWFta-prxSvNfXzx9ziOz7q5bE,63
|
|
15
|
+
xgic_wagtail_cli-0.1.0.dist-info/licenses/LICENSE,sha256=zR7vJ5cGf_9LgWHYDAugptsXPsV0_78I9kvVnf7VRk0,11335
|
|
16
|
+
xgic_wagtail_cli-0.1.0.dist-info/licenses/NOTICE,sha256=0WFLslt_X2suv9rdABKWpPjeT_GpvOS5mQBp83423eY,208
|
|
17
|
+
xgic_wagtail_cli-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 XGIC
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|