From 0635800dbda549dc5f1fedbfe59b7a679b42e8cb Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 8 Sep 2024 09:33:05 -0400 Subject: [PATCH] Expose `jaraco.abode.config.paths.override` to allow overriding of paths by downstream consumers. Closes #36 --- jaraco/abode/config.py | 25 +++++++++++++++++++++++-- newsfragments/36.feature.rst | 1 + 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 newsfragments/36.feature.rst diff --git a/jaraco/abode/config.py b/jaraco/abode/config.py index 30d4b7b..7225354 100644 --- a/jaraco/abode/config.py +++ b/jaraco/abode/config.py @@ -1,3 +1,15 @@ +""" +Expose platform paths for the application. + +>>> hasattr(paths, 'user_data') +True +""" + +from __future__ import annotations + +from collections.abc import Mapping + +import pathlib import platformdirs @@ -6,8 +18,7 @@ class PlatformDirs(platformdirs.PlatformDirs): # type: ignore[misc, valid-type] Augment PlatformDirs to ensure the data path exists. >>> dirs = PlatformDirs(appname='Abode', appauthor=False) - >>> alt_udp = getfixture('tmp_path') / 'data' / 'dir' - >>> vars(dirs).update(user_data_path=alt_udp) + >>> dirs.override(data_path=getfixture('tmp_path') / 'data' / 'dir') >>> assert dirs.user_data.is_dir() """ @@ -16,5 +27,15 @@ def user_data(self): self.user_data_path.mkdir(parents=True, exist_ok=True) return self.user_data_path + def override(self, **kwargs: Mapping[str, pathlib.Path]): + """ + Override the default _path variable. + + >>> dirs = PlatformDirs(appname='Abode', appauthor=False) + >>> dirs.override(user_data=pathlib.Path('/tmp/foo')) + """ + for name, path in kwargs.items(): + vars(self).update({name + '_path': path}) + paths = PlatformDirs(appname='Abode', appauthor=False) diff --git a/newsfragments/36.feature.rst b/newsfragments/36.feature.rst new file mode 100644 index 0000000..8fa78f1 --- /dev/null +++ b/newsfragments/36.feature.rst @@ -0,0 +1 @@ +Expose `jaraco.abode.config.paths.override` to allow overriding of paths by downstream consumers. \ No newline at end of file