Skip to content

Commit

Permalink
Update manage command to handle multiple apps
Browse files Browse the repository at this point in the history
  • Loading branch information
polyaxon-ci committed Nov 19, 2023
1 parent 5336368 commit 2de8423
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
20 changes: 16 additions & 4 deletions haupt/haupt/cli/manage.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import os

from typing import List, Optional

import click


@click.command()
@click.command(
context_settings=dict(
ignore_unknown_options=True,
allow_extra_args=True,
)
)
@click.option(
"--app",
default="haupt",
)
@click.option(
"-c",
"--command",
Expand All @@ -16,8 +23,13 @@
help="The sandbox root path.",
)
@click.argument("args", nargs=-1)
def manage(command: str, path: str, args: Optional[List[str]]):
def manage(app: Optional[str], command: str, path: str, args: Optional[List[str]]):
"""Start a new sever session."""
if app and app != "haupt":
from haupt.cli.runners.manage import manage

return manage(command, args, app=app)

from haupt.cli.runners.manage import run_manage
from polyaxon._cli.config import set_home_path

Expand Down
12 changes: 6 additions & 6 deletions haupt/haupt/cli/runners/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
from clipped.utils.lists import to_list

from haupt import settings
from polyaxon._contexts import paths as ctx_paths
from polyaxon._env_vars.keys import ENV_KEYS_SERVICE, ENV_KEYS_UI_IN_SANDBOX
from polyaxon._services.values import PolyaxonServices

_logger = logging.getLogger("haupt.cli.manage")


def manage(command: str, args: Optional[List[str]] = None):
def manage(
command: Optional[str], args: Optional[List[str]] = None, app: Optional[str] = None
):
from django.core.management import execute_from_command_line

app = app or "haupt"

# Required env var to trigger a management command
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "haupt.polyconf.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", f"{app}.polyconf.settings")

argv = ["manage.py"]
if command:
Expand All @@ -30,9 +33,6 @@ def migrate(
migrate_tables: bool = False,
migrate_db: bool = False,
):
# Required env var to trigger a management command
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "haupt.polyconf.settings")

if migrate_tables:
_logger.info("Starting tables migration ...")
manage("tables")
Expand Down

0 comments on commit 2de8423

Please sign in to comment.