Skip to content

Commit 50ab156

Browse files
authored
Parse database_url strings from config (#768)
1 parent 4303417 commit 50ab156

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/_pytask/database.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
@hookimpl
1515
def pytask_parse_config(config: dict[str, Any]) -> None:
1616
"""Parse the configuration."""
17+
database_url = config["database_url"]
1718
# Set default.
18-
if not config["database_url"]:
19+
if not database_url:
1920
config["database_url"] = make_url(
2021
f"sqlite:///{config['root'].joinpath('.pytask').as_posix()}/pytask.sqlite3"
2122
)
23+
elif isinstance(database_url, str):
24+
config["database_url"] = make_url(database_url)
2225

2326
if (
2427
config["database_url"].drivername == "sqlite"

tests/test_database.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ def test_rename_database_w_config(tmp_path, runner):
6868
assert path_to_db.exists()
6969

7070

71+
def test_database_url_from_config_is_parsed(tmp_path):
72+
tmp_path.joinpath("pyproject.toml").write_text(
73+
"[tool.pytask.ini_options]\ndatabase_url='sqlite:///.db.sqlite'"
74+
)
75+
76+
session = build(paths=tmp_path)
77+
78+
assert session.exit_code == ExitCode.OK
79+
assert session.config["database_url"].drivername == "sqlite"
80+
81+
7182
def test_rename_database_w_cli(tmp_path, runner):
7283
"""Modification dates of input and output files are stored in database."""
7384
path_to_db = tmp_path.joinpath(".db.sqlite")

0 commit comments

Comments
 (0)