Skip to content

Commit b200aaf

Browse files
authored
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.
1 parent 42af0cc commit b200aaf

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

dbos/cli/cli.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,15 @@ def init(
100100
] = False,
101101
) -> None:
102102
try:
103+
103104
git_templates = ["dbos-app-starter", "dbos-cron-starter"]
104105
templates_dir = get_templates_directory()
105106
templates = git_templates + [
106107
x.name for x in os.scandir(templates_dir) if x.is_dir()
107108
]
108-
if len(templates) == 0:
109-
raise Exception(f"no DBOS templates found in {templates_dir} ")
109+
110+
if config and template is None:
111+
template = templates[-1]
110112

111113
if template:
112114
if template not in templates:

tests/test_package.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import urllib.request
1010

1111
import sqlalchemy as sa
12+
import yaml
1213

1314

1415
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:
9091
finally:
9192
os.kill(process.pid, signal.SIGINT)
9293
process.wait()
94+
95+
96+
def test_init_config() -> None:
97+
app_name = "example-name"
98+
expected_yaml = {
99+
"name": app_name,
100+
"language": "python",
101+
"runtimeConfig": {"start": ["fastapi run ./main.py"]},
102+
"database": {"migrate": ["echo 'No migrations specified'"]},
103+
"telemetry": {"logs": {"logLevel": "INFO"}},
104+
}
105+
with tempfile.TemporaryDirectory() as temp_path:
106+
subprocess.check_call(
107+
["dbos", "init", app_name, "--config"],
108+
cwd=temp_path,
109+
)
110+
111+
config_path = os.path.join(temp_path, "dbos-config.yaml")
112+
assert os.path.exists(config_path)
113+
114+
with open(config_path) as f:
115+
actual_yaml = yaml.safe_load(f)
116+
117+
assert actual_yaml == expected_yaml

0 commit comments

Comments
 (0)