tox-dev / platformdirs

A small Python module for determining appropriate platform-specific dirs, e.g. a "user data dir".
https://platformdirs.readthedocs.io
MIT License
568 stars 49 forks source link

`MacOS.site_data_path` returns `:` separated path under Homebrew with multipath #292

Closed matthewhughes934 closed 2 weeks ago

matthewhughes934 commented 1 month ago

Hi, I was wondering about this behaviour as I noticed there is a difference between how MacOS and Linux handle this property:

This came from: https://github.com/pypa/pip/issues/12903.

Note: the same behaviour exists for site_cache_dir

demonstration:

import os

from platformdirs import macos, unix

# hack to pretend we're under homebrew
macos.sys.prefix = "/opt/homebrew/"
print(macos.MacOS(multipath=True).site_data_dir)
print(macos.MacOS(multipath=True).site_data_path)

# force site_data_dir to be a multipath
os.environ["XDG_DATA_DIRS"] = "/foo:/bar"
print(unix.Unix(multipath=True).site_data_dir)
print(unix.Unix(multipath=True).site_data_path)

Output:

/opt/homebrew/share:/Library/Application Support
/opt/homebrew/share:/Library/Application Support
/foo:/bar
/foo

Should MacOS also just use the first element, so in the above: macos.MacOS(multipath=True).site_data_path == Path(/opt/homebrew/share)

gaborbernat commented 2 weeks ago

PR welcome with such change 👍

matthewhughes934 commented 2 weeks ago

PR welcome with such change 👍

Thanks, I've created https://github.com/tox-dev/platformdirs/pull/299