Fix CLI import paths for installed packages

The CLI api commands were using a hardcoded path to find frontends/
which didn't work when installed as a package. Now tries both:
- Development: .../stegasoo/frontends
- Installed: .../site-packages/frontends

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Aaron D. Lee
2026-01-11 18:29:06 -05:00
parent 110b160e68
commit d395e5731e

View File

@@ -1673,6 +1673,26 @@ def admin_generate_key(show_qr):
# ============================================================================= # =============================================================================
def _setup_frontends_path():
"""Add frontends directory to sys.path for importing API/web modules."""
import sys
# Try multiple possible locations
possible_paths = [
# Development: stegasoo/frontends
Path(__file__).parent.parent.parent / "frontends",
# Installed package: site-packages/frontends
Path(__file__).parent.parent / "frontends",
]
for path in possible_paths:
if path.exists() and str(path) not in sys.path:
sys.path.insert(0, str(path))
return True
return False
@cli.group() @cli.group()
@click.pass_context @click.pass_context
def api(ctx): def api(ctx):
@@ -1699,8 +1719,7 @@ def api_keys_list(location):
stegasoo api keys list stegasoo api keys list
stegasoo api keys list --location user stegasoo api keys list --location user
""" """
import sys _setup_frontends_path()
sys.path.insert(0, str(Path(__file__).parent.parent.parent / "frontends"))
try: try:
from api.auth import list_api_keys, get_api_key_status from api.auth import list_api_keys, get_api_key_status
@@ -1740,8 +1759,7 @@ def api_keys_create(name, location):
stegasoo api keys create laptop stegasoo api keys create laptop
stegasoo api keys create automation --location project stegasoo api keys create automation --location project
""" """
import sys _setup_frontends_path()
sys.path.insert(0, str(Path(__file__).parent.parent.parent / "frontends"))
try: try:
from api.auth import add_api_key from api.auth import add_api_key
@@ -1772,8 +1790,7 @@ def api_keys_delete(name, location):
stegasoo api keys delete laptop stegasoo api keys delete laptop
stegasoo api keys delete automation --location project stegasoo api keys delete automation --location project
""" """
import sys _setup_frontends_path()
sys.path.insert(0, str(Path(__file__).parent.parent.parent / "frontends"))
try: try:
from api.auth import remove_api_key from api.auth import remove_api_key
@@ -1811,8 +1828,7 @@ def api_tls_generate(hostname, days, output):
stegasoo api tls generate --hostname myserver --days 730 stegasoo api tls generate --hostname myserver --days 730
stegasoo api tls generate -o /etc/stegasoo/certs stegasoo api tls generate -o /etc/stegasoo/certs
""" """
import sys _setup_frontends_path()
sys.path.insert(0, str(Path(__file__).parent.parent.parent / "frontends"))
try: try:
from web.ssl_utils import generate_self_signed_cert, get_cert_paths from web.ssl_utils import generate_self_signed_cert, get_cert_paths
@@ -1906,8 +1922,7 @@ def api_serve(host, port, ssl, cert, key, do_reload):
stegasoo api serve --no-ssl stegasoo api serve --no-ssl
stegasoo api serve --cert /path/to/cert.pem --key /path/to/key.pem stegasoo api serve --cert /path/to/cert.pem --key /path/to/key.pem
""" """
import sys _setup_frontends_path()
sys.path.insert(0, str(Path(__file__).parent.parent.parent / "frontends"))
# Determine cert paths # Determine cert paths
if ssl: if ssl: