Skip to content

Commit

Permalink
Improve dbos init --config (#194)
Browse files Browse the repository at this point in the history
Update `dbos init --config` to use the config from the in-repo template
by default. Add a test for it.
  • Loading branch information
kraftp authored Jan 31, 2025
1 parent 42af0cc commit b200aaf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dbos/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 25 additions & 0 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

0 comments on commit b200aaf

Please sign in to comment.