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 0635800
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
25 changes: 23 additions & 2 deletions jaraco/abode/config.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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()
"""

Expand All @@ -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)
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 0635800

Please sign in to comment.