From 7251504dc45b2bced017c093247af2e93978fa6e Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 29 Nov 2025 18:28:52 +0100 Subject: [PATCH] ref: Extract note parent dir creation function --- topen.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/topen.py b/topen.py index e04e39e..fae010e 100755 --- a/topen.py +++ b/topen.py @@ -63,9 +63,7 @@ def main(cfg: "TConf | None" = None, io: "_IO | None" = None) -> int: fpath = get_notes_file(uuid, notes_dir=cfg.notes_dir, notes_ext=cfg.notes_ext) - if not fpath.parent.exists(): - fpath.parent.mkdir(parents=True, exist_ok=True) - + _ensure_parent_dir(fpath) io.out(f"Editing note: {fpath}") open_editor(fpath, editor=cfg.notes_editor) @@ -139,6 +137,11 @@ def _real_path(p: Path | str) -> Path: return Path(os.path.expandvars(p)).expanduser() +def _ensure_parent_dir(file: Path) -> None: + if not file.parent.exists(): + file.parent.mkdir(parents=True, exist_ok=True) + + def _determine_default_task_rc() -> Path: if _real_path("~/.taskrc").exists(): return _real_path("~/.taskrc")