From b200aaffe1a393771d27774b637175598d3a2dfa Mon Sep 17 00:00:00 2001 From: Peter Kraft Date: Fri, 31 Jan 2025 17:35:18 -0600 Subject: [PATCH] Improve dbos init --config (#194) Update `dbos init --config` to use the config from the in-repo template by default. Add a test for it. --- dbos/cli/cli.py | 6 ++++-- tests/test_package.py | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/dbos/cli/cli.py b/dbos/cli/cli.py index df04ab18..a44f9a14 100644 --- a/dbos/cli/cli.py +++ b/dbos/cli/cli.py @@ -100,13 +100,15 @@ def init( ] = False, ) -> None: try: + git_templates = ["dbos-app-starter", "dbos-cron-starter"] templates_dir = get_templates_directory() templates = git_templates + [ x.name for x in os.scandir(templates_dir) if x.is_dir() ] - if len(templates) == 0: - raise Exception(f"no DBOS templates found in {templates_dir} ") + + if config and template is None: + template = templates[-1] if template: if template not in templates: diff --git a/tests/test_package.py b/tests/test_package.py index 9593c797..26387826 100644 --- a/tests/test_package.py +++ b/tests/test_package.py @@ -9,6 +9,7 @@ import urllib.request import sqlalchemy as sa +import yaml def test_package(build_wheel: str, postgres_db_engine: sa.Engine) -> None: @@ -90,3 +91,27 @@ def test_package(build_wheel: str, postgres_db_engine: sa.Engine) -> None: finally: os.kill(process.pid, signal.SIGINT) process.wait() + + +def test_init_config() -> None: + app_name = "example-name" + expected_yaml = { + "name": app_name, + "language": "python", + "runtimeConfig": {"start": ["fastapi run ./main.py"]}, + "database": {"migrate": ["echo 'No migrations specified'"]}, + "telemetry": {"logs": {"logLevel": "INFO"}}, + } + with tempfile.TemporaryDirectory() as temp_path: + subprocess.check_call( + ["dbos", "init", app_name, "--config"], + cwd=temp_path, + ) + + config_path = os.path.join(temp_path, "dbos-config.yaml") + assert os.path.exists(config_path) + + with open(config_path) as f: + actual_yaml = yaml.safe_load(f) + + assert actual_yaml == expected_yaml