From e77cfe7ce3718ae991d149cac0f5829086a5bc1e Mon Sep 17 00:00:00 2001 From: Martin Ueding Date: Sat, 3 Feb 2024 17:49:20 +0100 Subject: [PATCH] GH-89: Fiddle around with paths --- geo_activity_playground/core/paths.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/geo_activity_playground/core/paths.py b/geo_activity_playground/core/paths.py index 277354a..be17369 100644 --- a/geo_activity_playground/core/paths.py +++ b/geo_activity_playground/core/paths.py @@ -6,19 +6,31 @@ import typing -def make_path(path) -> typing.Callable[[], pathlib.Path]: +def dir_wrapper( + dir_func: typing.Callable[[], pathlib.Path] +) -> typing.Callable[[], pathlib.Path]: + @functools.wraps(dir_func) @functools.cache - def path_creator() -> pathlib.Path: + def wrapper() -> pathlib.Path: + path = dir_func() path.mkdir(exist_ok=True, parents=True) return path - return path_creator + return wrapper -cache_dir = make_path(pathlib.Path("Cache")) -activity_timeseries_dir = lambda: make_path(cache_dir() / "Activity Timeseries") +@dir_wrapper +def cache_dir() -> pathlib.Path: + return pathlib.Path("Cache") -activities_path = lambda: cache_dir() / "activities.parquet" + +@dir_wrapper +def activity_timeseries_dir() -> pathlib.Path: + return cache_dir() / "Activity Timeseries" + + +def activities_path() -> pathlib.Path: + return cache_dir() / "activities.parquet" def activity_timeseries_path(activity_id: int) -> pathlib.Path: