You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For many tools, especially those designed for use across Linux/Unix/Mac, it makes sense to use XDG as a common standard. This especially applies to command line tools, for which ~/Library/* breaks inherited convention (and thus breaks interop).
I have previously submitted PRs to resolve this in several applications on macOS, but it would be easier to establish good defaults here instead of sending PRs to patch around it downstream. (This also makes this a blocker for personal usage – at least without vendoring and modifying the module, which isn't ideal.)
I want (some version of) this change personally too, but I think we have to be quite careful -- the Apple guidelines are clear, so I'm:
+1 on "follow XDG_* if set, even on macOS"
But -1 for any suggestion of following the XDG-recommended behavior (which says what to do when XDG_ is unset) on macOS
But +0 on "add a way for libraries using platformdirs to opt-in to that behavior even on macOS", which is sometimes useful -- e.g. ~/Library/Application Support has a space in it, so for libraries that install scripts with shebangs and put them there, they literally won't execute (unless they use the newer ~/Library/ApplicationSupport spaceless symlink), and for those, always defaulting to ~/.local/share, a la XDG_DATA_HOME's default seems potentially reasonable
(Not sure you were suggesting anything about default behavior, but yeah just mentioning my own opinion on all 3 decisions).
If XDG* is set (and is a CLI program), then the program should use XDG.
Other cases (GUI programs) are less clear, but if it has an application
bundle, then it's less likely that XDG is the answer.
Reacted by Tony Soloveyv, TW, Sandeep Dilip and 1 more
I think that the default should assume CLI. At the very least, this needs
to be specifiable downstream. Cross platform applications using Python most
likely see use in XDG compliant systems as well, and they often use configs
editable in Vim/etc. So having them in a well known location across
platforms is a compelling concern IMHO.
It gets tricky because platformdirs might be a dependency of one of your libraries, so the caller codebase might not have direct access to it, and could not necessarily tell in what env type is used. We could make it a global state I guess, something like
platformdirs.set_cli_type(False)
So then GUIS could call part of their setup that code, even if it's used by a transient dependency.
I'm unsure if it makes sense for a dependent library to use platformdirs. I
guess it needs to be supported regardless, though.
Actually, what if this is done per key?
If you are aware of ones that *don't* support XDG, please let me know so
that I can PR it in the future. With any luck, I can just PR platformdirs
instead of appdirs. :)
But in all seriousness, anything ported directly from Linux/Unix that
already uses XDG generally adheres to XDG on Mac. Anything that uses
~/.config follows the half of XDG that I care about (and a lot of stuff
uses ~/.config these days, including git).
And a concrete example: I did recently PR XDG into the Backblaze SDK, which
is used by their CLI and in other applications as a library.
What about a opt-in environment variable PLATFORMDIRS_USE_XDG? Poeple who don't have it will not be affected. It will be a quite simple patch:
--- __init__.py.bak 2023-03-25 16:36:36.753498600 +0800+++ __init__.py 2023-03-25 16:38:20.665189000 +0800@@ -19,6 +19,9 @@
def _set_platform_dir_class() -> type[PlatformDirsABC]:
+ if os.getenv("PLATFORMDIRS_USE_XDG"):+ from platformdirs.unix import Unix as Result+
if sys.platform == "win32":
from platformdirs.windows import Windows as Result
elif sys.platform == "darwin":
is anything but Unix thing. It's also not exactly macOS native thing, as all plist configs should go to
~/Library/Preferences
but I guess it's fine for some cross platform, especially, GUI apps, to use the former.
Because macOS is certified Unix (inspired by BSD at POSIX level), it's not unnatural to expect basic Unix conformance, which is luckily the case (notwithstanding its infamously being known to deviate from all kinds of standards).
It also implies one should be able to live a decent life, without need to know about Library and other macOS-specific stuff (given they enjoy Unix-only workflows).
The concern I can immediately come up with (there might be more) is related to dotfiles management, e.g. using one of tools:
which rules out their placement to Application Support. For this to work,
it's expected for CLI apps to have their config dirs configurable, if they opt for Application Support relative path.
With all respect to the maintainers: it's disappointing that the issue was closed, and, from what I see, PRs are not too much welcome. Please kindly correct me if I'm wrong, @gaborbernat.
I do not believe this to be the case to the extent you wish to be.
I suppose it was meant that macOS is POSIX certified? But at that level we are just splitting hairs and getting nowhere further to solving a major pain point that users are complaining about here.
The commenters in this issue have given plenty of use cases for supporting XDG_CONFIG_HOME on macOS.
Being technically correct about this or that is not the same as "doing the right thing". To me, open source is about respecting user freedom.
Activity
Julian commentedon Jul 10, 2021
I want (some version of) this change personally too, but I think we have to be quite careful -- the Apple guidelines are clear, so I'm:
~/Library/Application Supporthas a space in it, so for libraries that install scripts with shebangs and put them there, they literally won't execute (unless they use the newer~/Library/ApplicationSupportspaceless symlink), and for those, always defaulting to~/.local/share, a laXDG_DATA_HOME's default seems potentially reasonable(Not sure you were suggesting anything about default behavior, but yeah just mentioning my own opinion on all 3 decisions).
0az commentedon Jul 10, 2021
For the record, I'm +1, +0, and +1 on those three points.
gaborbernat commentedon Jul 23, 2021
Apple does not follow the XDG spec, so at best what I've seen is people roughly mapping it, see https://stackoverflow.com/questions/3373948/equivalents-of-xdg-config-home-and-xdg-data-home-on-mac-os-x
If anyone has better links/documentation on what exactly would mean following the XDG spec when the XDG env-vars are set feel free to clarify.
0az commentedon Jul 23, 2021
gaborbernat commentedon Jul 23, 2021
How do you identify if the Python app is CLI or not?
0az commentedon Jul 23, 2021
gaborbernat commentedon Jul 23, 2021
It gets tricky because platformdirs might be a dependency of one of your libraries, so the caller codebase might not have direct access to it, and could not necessarily tell in what env type is used. We could make it a global state I guess, something like
So then GUIS could call part of their setup that code, even if it's used by a transient dependency.
0az commentedon Jul 23, 2021
gaborbernat commentedon Jul 23, 2021
I'd personally rather have one global flag. Are we aware of other languages/libraries respecting XDG on macOS as precedence?
0az commentedon Jul 23, 2021
gaborbernat commentedon Jul 25, 2021
Feel free to open a pull request 👍
0az commentedon Jul 25, 2021
How should backwards compatibility be handled?
gaborbernat commentedon Jul 25, 2021
What do you suggest?
21 remaining items
julie777 commentedon Feb 20, 2022
I understand.
gaborbernat commentedon Nov 13, 2022
Closing per above.
gshpychka commentedon Jan 6, 2023
@gaborbernat is the maintainer team also against implementing it on MacOS? If not - might be worth keeping this open?
gaborbernat commentedon Jan 6, 2023
I think we were 🤔
Allow specifying config/cache directories
GalaxySnail commentedon Mar 25, 2023
What about a opt-in environment variable
PLATFORMDIRS_USE_XDG? Poeple who don't have it will not be affected. It will be a quite simple patch:ink-splatters commentedon Apr 25, 2023
Got surprised I could not find a way to specify PDM config dir on macOS, in order to change it from
~/Library/Application Support/pdmto much more appropriate
~/.config/pdmwhich is effectively
XDG_CONFIG_HOME, as per XDG Base Directory SpecificationDigging into
PDMcode led me eventually to this thread, as well as I found your referring some macOS Guidelines:https://github.com/platformdirs/platformdirs/blob/b866d404c74d3467ab7a16e2be974612b14145b7/src/platformdirs/macos.py#L10-L11
Having config stored at
~/Library/Application Supportis anything but Unix thing. It's also not exactly macOS native thing, as all
plistconfigs should go to~/Library/Preferencesbut I guess it's fine for some cross platform, especially, GUI apps, to use the former.
Because macOS is certified Unix (inspired by BSD at POSIX level), it's not unnatural to expect basic Unix conformance, which is luckily the case (notwithstanding its infamously being known to deviate from all kinds of standards).
It also implies one should be able to live a decent life, without need to know about Library and other macOS-specific stuff (given they enjoy Unix-only workflows).
The concern I can immediately come up with (there might be more) is related to
dotfilesmanagement, e.g. using one of tools:Besides:
there is unspoken contract for them to reside at
$HOME/.configor
which rules out their placement to Application Support. For this to work,
it's expected for CLI apps to have their config dirs configurable, if they opt for Application Support relative path.
With all respect to the maintainers: it's disappointing that the issue was closed, and, from what I see, PRs are not too much welcome. Please kindly correct me if I'm wrong, @gaborbernat.
gaborbernat commentedon Apr 25, 2023
I do not believe this to be the case to the extent you wish to be.
install.sh: Honor XDG_DATA_HOME
justuswilhelm commentedon Sep 13, 2023
I suppose it was meant that macOS is POSIX certified? But at that level we are just splitting hairs and getting nowhere further to solving a major pain point that users are complaining about here.
The commenters in this issue have given plenty of use cases for supporting XDG_CONFIG_HOME on macOS.
Being technically correct about this or that is not the same as "doing the right thing". To me, open source is about respecting user freedom.
RonnyPfannschmidt commentedon Sep 13, 2023
Sometimes freedom from incorrect implementation is more important than freedom to do broken things out of preference
install.sh: Honor XDG_DATA_HOME
install.sh: Honor XDG_DATA_HOME
install.sh: Honor XDG_DATA_HOME