Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API calls that return pathlib.Path instead of str objects #27

Merged
merged 14 commits into from
Jul 23, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/platformdirs/unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,21 @@ def user_log_dir(self) -> str:
@property
def site_data_path(self) -> Path:
""":return: data path shared by users. Only return first item, even if ``multipath`` is set to ``True``"""
site_data_dir = self.site_data_dir
if self.multipath:
# If multipath is True, the first path is returned.
site_data_dir = site_data_dir.split(os.pathsep)[0]
return Path(site_data_dir)
return self._first_item_as_path_if_multipath(self.site_data_dir)

@property
def site_config_path(self) -> Path:
""":return: config path shared by the users. Only return first item, even if ``multipath`` is set to ``True``"""
site_config_dir = self.site_config_dir
return self._first_item_as_path_if_multipath(self.site_config_dir)

def _first_item_as_path_if_multipath(self, directory: str) -> Path:
"""
:return: first directory as path, even if ``multipath`` is set to ``True``
papr marked this conversation as resolved.
Show resolved Hide resolved
"""
if self.multipath:
# If multipath is True, the first path is returned.
site_config_dir = site_config_dir.split(os.pathsep)[0]
return Path(site_config_dir)
directory = directory.split(os.pathsep)[0]
return Path(directory)


__all__ = [
Expand Down