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

Allow XDG_CONFIG_HOME on macOS #4

Closed
0az opened this issue Jul 10, 2021 · 40 comments
Closed

Allow XDG_CONFIG_HOME on macOS #4

0az opened this issue Jul 10, 2021 · 40 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@0az
Copy link

0az commented Jul 10, 2021

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.)

Appdirs issue: ActiveState/appdirs#78

@Julian
Copy link
Contributor

Julian commented 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:

  • +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).

@Julian Julian added the enhancement New feature or request label Jul 10, 2021
@0az
Copy link
Author

0az commented Jul 10, 2021

(Not sure you were suggesting anything about default behavior, but yeah just mentioning my own opinion on all 3 decisions).

For the record, I'm +1, +0, and +1 on those three points.

@gaborbernat
Copy link
Member

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
Copy link
Author

0az commented Jul 23, 2021 via email

@gaborbernat
Copy link
Member

How do you identify if the Python app is CLI or not?

@0az
Copy link
Author

0az commented Jul 23, 2021 via email

@gaborbernat
Copy link
Member

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.

@0az
Copy link
Author

0az commented Jul 23, 2021 via email

@gaborbernat gaborbernat added the help wanted Extra attention is needed label Jul 23, 2021
@gaborbernat
Copy link
Member

I'd personally rather have one global flag. Are we aware of other languages/libraries respecting XDG on macOS as precedence?

@0az
Copy link
Author

0az commented Jul 23, 2021 via email

@gaborbernat
Copy link
Member

Feel free to open a pull request 👍

@0az
Copy link
Author

0az commented Jul 25, 2021

How should backwards compatibility be handled?

@gaborbernat
Copy link
Member

What do you suggest?

0az added a commit to 0az/platformdirs that referenced this issue Aug 3, 2021
0az added a commit to 0az/platformdirs that referenced this issue Aug 3, 2021
@0az
Copy link
Author

0az commented Aug 3, 2021

Pushed my proposal for backwards compat to #35, which is mostly complete (just needs more tests, a bit of bikeshedding, and a rebase).

0az added a commit to 0az/platformdirs that referenced this issue Aug 4, 2021
@layday
Copy link

layday commented Aug 17, 2021

* unless they use the newer `~/Library/ApplicationSupport` spaceless symlink

This symlink is created by iTerm2, it's not a new addition to the OS.

@percurnicus
Copy link

Would you accept a PR to extend the XDG_* environment variables to Windows as well as Mac? I've ran into cases on Windows where I would like to override the cache directory using an environment variable. My thought on the implementation would be to
have all systems obey the environment variable like Unix currently does and to revert to the current logic if it is not set.

@gaborbernat
Copy link
Member

I personally would be alright with this, however, considering its wide-ranging implications I'd like to get input of some of the downstream users; e.g. pip cc @pradyunsg, pytest @asottile @nicoddemus. Plus the opinion of other maintainers: @RonnyPfannschmidt @ofek @Julian.

@Julian
Copy link
Contributor

Julian commented Jan 2, 2022

I felt icky about it when seeing the email notification last night, but I can't place my finger on why yet :)
I am obviously pro doing it on macOS, so I slept on it personally and couldn't think of a reason Windows users should get left out -- I think to me the justification is that a user who sets this envvar, regardless of platform, likely intends to use it. So yeah +0 for now from me for doing this on all OSes.
I would feel less good however about proactively telling users that this is the "recommended" way to get this behavior on all OSes, because indeed these envvars do not have wide adoption on Windows, and even macOS to some extent, so other software will not work this way -- (if we were to advertise a way to mutate these dirs I would instead prefer we have an explicit PLATFORMDIRS_* set of vars for the fully blessed case) But I could be convinced off of that too and just stick with these if others are for it.

@asottile
Copy link

asottile commented Jan 2, 2022

I don't think pytest uses platformdirs/appdirs yet though many of its consumers do

so my opinion is less rooted but I'll give it anyway:

  • personally (and I know I'm wrong so no need to tell me!) platform-specific directories confuse me and my users so I tend to just use xdg everywhere (the pre-commit cache for instance on every platform will end up in ~/.cache/pre-commit)
  • this makes support and triage much easier since it cuts out the "oh you're on windows, uh look in hmm %APPDATA%\Local, or was it Roaming err..."

that said, I think having some way to configure the directories via an environment variable is a desirably feature, and XDG is fairly well specced to enable such a feature. there's an additional question as to how you handle XDG considering a "default" -- and in that case you'd probably want to ignore XDG's recommended defaults and use the platform-specific defaults. the other edge case is when the xdg variable is present but empty -- which seems to imply a bit more "I want xdg" but typically empty should be treated the same as missing (though a popular "standard" (NO_COLOR) gets this wrong as well)

anyway, I'm not a maintainer here -- nor am I currently a direct consumer -- nor am I a maintainer of a direct consumer -- so feel free to ignore my thoughts on this :) -- I'm going to unsubscribe from notifications and if you need me please @-mention directly

@pradyunsg
Copy link
Contributor

pradyunsg commented Jan 2, 2022

I'm a soft -1 for doing any changes related to this on Windows, and -0 for adopting XDG-when-set on MacOS (as long as there's a way to opt out, or if it's made opt-in). I'd lean toward having pip not enable such support on MacOS.

There's absolutely no reason to follow XDG for Windows; and doing so will only complicate the story for files on Windows. For pip, this will mean additional caveats to the configuration file story on Windows.

I'm not sure I'd want pip to support XDG configuration on MacOS either, since we're already technically out of sync with the Apple's specification for where configuration files should be; in more ways than one. Adding XDG as an additional layer of complexity on that would not be something I'd be enthusiastic about, to put it mildly.

@percurnicus
Copy link

(if we were to advertise a way to mutate these dirs I would instead prefer we have an explicit PLATFORMDIRS_* set of vars for the fully blessed case) But I could be convinced off of that too and just stick with these if others are for it.

I would prefer this as well. Using XDG on windows feels wrong and that way we don't run into issues causing unintended behavior for other applications that are using those environment variables.

I'm a soft -1 for doing any changes related to this on Windows

Does that also include adding PLATFORMDIRS_* env vars?

@RonnyPfannschmidt
Copy link

Are there any well know / used standards for this on windows?

IMHO the platform specific override mechanism should be used

@Julian
Copy link
Contributor

Julian commented Jan 2, 2022

CC @zooba in case he cares to opine.

@julie777
Copy link

I'm a soft -1 for doing any changes related to this on Windows, and -0 for adopting XDG-when-set on MacOS (as long as there's a way to opt out, or if it's made opt-in). I'd lean toward having pip not enable such support on MacOS.

There's absolutely no reason to follow XDG for Windows; and doing so will only complicate the story for files on Windows. For pip, this will mean additional caveats to the configuration file story on Windows.

I'm not sure I'd want pip to support XDG configuration on MacOS either, since we're already technically out of sync with the Apple's specification for where configuration files should be; in more ways than one. Adding XDG as an additional layer of complexity on that would not be something I'd be enthusiastic about, to put it mildly.

I have to disagree with the logic. There is absolutely a reason to support XDG on both MacOS and Windows. It gives developers options. Regular "I don't know anything about computers" users won't care. But, I certainly do.

I share my HOME directory tree across platforms. During development I hate to have to go digging around in AppData to find things. Being able to control that would be very helpful. You may think that Windows has standard directories for everything, but many application don't use them. For years Python only installed in C:\Python.

And along came WSL. Now I can run Linux and Windows at the same time and share files. Being able to have a project directory seen by both platforms is great for development. With XDG dirs I can have python tools install into $HOME/.local/bin or $HOME/.local/bin_win.

Please remember that adding support for XDG dirs doesn't affect anyone that doesn't use them (for MacOS and Windows). On Linux if not set they should default appropriately.

@gaborbernat
Copy link
Member

Please remember that adding support for XDG dirs doesn't affect anyone that doesn't use them (for MacOS and Windows).

We hear your points, but please respect the decision of the maintainer team on this topic 👍 Unless the current maintainers come back that they've changed their minds there's nothing else to do.

@julie777
Copy link

I understand.

@gaborbernat
Copy link
Member

Closing per above.

@gshpychka
Copy link

@gaborbernat is the maintainer team also against implementing it on MacOS? If not - might be worth keeping this open?

@gaborbernat
Copy link
Member

I think we were 🤔

apyrgio added a commit to freedomofpress/dangerzone that referenced this issue Feb 8, 2023
Allow specifying the config/cache directories that Dangerzone will use,
both for the CLI and the GUI, via CLI arguments. This way, the user has
better control of where Dangerzone will save its state and, most
importantly, we can use this feature to make each test run in a
different directory.

Moreover, we fix an issue where the temporary conversion artifacts were
stored in the configuration directory, instead of the cache directory.

Note that while most OSes (Windows and Linux) offer a way to specify
these directories through environment variables, the same does not apply
to MacOS [1], so having a CLI flag is required.

[1]: tox-dev/platformdirs#4
@GalaxySnail
Copy link

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":

@ink-splatters
Copy link

ink-splatters commented 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/pdm

to much more appropriate

~/.config/pdm

which is effectively XDG_CONFIG_HOME, as per XDG Base Directory Specification

Digging into PDM code 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 Support

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:

Besides:

dotfiles

there is unspoken contract for them to reside at

$HOME/.config

or

$HOME/.local/share

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
Copy link
Member

Because macOS is certified Unix

I do not believe this to be the case to the extent you wish to be.

Finii added a commit to ryanoasis/nerd-fonts that referenced this issue Jul 28, 2023
[why]
When a user sets the XDG_DATA_HOME environment variable the default of
$HOME/.local/share should not be used.

https://wiki.archlinux.org/title/XDG_Base_Directory

[how]
Enable XDG_DATA_HOME to override the default user data directory on Unix
and MacOS platforms.

There is some controversy if XDG_DATA_HOME should be honored on MacOS,
see for example platformdirs (link below). But me also working on Linux
and MacOS (and Windows) in parallel, I can not quite follow the
downsides and believe we should allow XDG_DATA_HOME also for MacOS.

Related: tox-dev/platformdirs#4
Fixes: #1324

Suggested-by: Anthony Foglia <@afoglia>
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
@justuswilhelm
Copy link

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.

@RonnyPfannschmidt
Copy link

Sometimes freedom from incorrect implementation is more important than freedom to do broken things out of preference

Finii added a commit to ryanoasis/nerd-fonts that referenced this issue Sep 27, 2023
[why]
When a user sets the XDG_DATA_HOME environment variable the default of
$HOME/.local/share should not be used.

https://wiki.archlinux.org/title/XDG_Base_Directory

[how]
Enable XDG_DATA_HOME to override the default user data directory on Unix
and MacOS platforms.

There is some controversy if XDG_DATA_HOME should be honored on MacOS,
see for example platformdirs (link below). But me also working on Linux
and MacOS (and Windows) in parallel, I can not quite follow the
downsides and believe we should allow XDG_DATA_HOME also for MacOS.

Related: tox-dev/platformdirs#4
Fixes: #1324

Suggested-by: Anthony Foglia <@afoglia>
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
liziqiang pushed a commit to liziqiang/nerd-fonts-forked that referenced this issue Oct 13, 2023
[why]
When a user sets the XDG_DATA_HOME environment variable the default of
$HOME/.local/share should not be used.

https://wiki.archlinux.org/title/XDG_Base_Directory

[how]
Enable XDG_DATA_HOME to override the default user data directory on Unix
and MacOS platforms.

There is some controversy if XDG_DATA_HOME should be honored on MacOS,
see for example platformdirs (link below). But me also working on Linux
and MacOS (and Windows) in parallel, I can not quite follow the
downsides and believe we should allow XDG_DATA_HOME also for MacOS.

Related: tox-dev/platformdirs#4
Fixes: ryanoasis#1324

Suggested-by: Anthony Foglia <@afoglia>
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
LNKLEO pushed a commit to LNKLEO/Nerd that referenced this issue Nov 24, 2023
[why]
When a user sets the XDG_DATA_HOME environment variable the default of
$HOME/.local/share should not be used.

https://wiki.archlinux.org/title/XDG_Base_Directory

[how]
Enable XDG_DATA_HOME to override the default user data directory on Unix
and MacOS platforms.

There is some controversy if XDG_DATA_HOME should be honored on MacOS,
see for example platformdirs (link below). But me also working on Linux
and MacOS (and Windows) in parallel, I can not quite follow the
downsides and believe we should allow XDG_DATA_HOME also for MacOS.

Related: tox-dev/platformdirs#4
Fixes: ryanoasis#1324

Suggested-by: Anthony Foglia <@afoglia>
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.