Skip to content

Commit

Permalink
Expose jaraco.abode.config.paths.override to allow overriding of pa…
Browse files Browse the repository at this point in the history
…ths by downstream consumers.

Closes #36
  • Loading branch information
jaraco committed Sep 8, 2024
1 parent 91645cf commit ea1f6fe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
23 changes: 21 additions & 2 deletions jaraco/abode/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
"""
Expose platform paths for the application.
>>> hasattr(paths, 'user_data')
True
"""

from collections.abc import Mapping

import pathlib
import platformdirs


Expand All @@ -6,8 +16,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()
"""

Expand All @@ -16,5 +25,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)
1 change: 1 addition & 0 deletions newsfragments/36.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expose `jaraco.abode.config.paths.override` to allow overriding of paths by downstream consumers.

0 comments on commit ea1f6fe

Please sign in to comment.