Skip to content

Allow XDG_CONFIG_HOME on macOS  #4

Closed

Description

@0az

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

Activity

  1. Julian commented on Jul 10, 2021

    @Julian
    Contributor

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

  2. added
    enhancement
    on Jul 10, 2021
  3. 0az commented on Jul 10, 2021

    @0az
    Author

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

  4. gaborbernat commented on Jul 23, 2021

    @gaborbernat
    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.

  5. 0az commented on Jul 23, 2021

    @0az
    Author
  6. gaborbernat commented on Jul 23, 2021

    @gaborbernat
    Member

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

  7. 0az commented on Jul 23, 2021

    @0az
    Author
  8. gaborbernat commented on Jul 23, 2021

    @gaborbernat
    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.

  9. 0az commented on Jul 23, 2021

    @0az
    Author
  10. added
    help wanted
    on Jul 23, 2021
  11. gaborbernat commented on Jul 23, 2021

    @gaborbernat
    Member

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

  12. 0az commented on Jul 23, 2021

    @0az
    Author
  13. gaborbernat commented on Jul 25, 2021

    @gaborbernat
    Member

    Feel free to open a pull request 👍

  14. 0az commented on Jul 25, 2021

    @0az
    Author

    How should backwards compatibility be handled?

  15. gaborbernat commented on Jul 25, 2021

    @gaborbernat
    Member

    What do you suggest?

  16. 21 remaining items

  17. julie777 commented on Feb 20, 2022

    @julie777

    I understand.

  18. gaborbernat commented on Nov 13, 2022

    @gaborbernat
    Member

    Closing per above.

  19. gshpychka commented on Jan 6, 2023

    @gshpychka

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

  20. gaborbernat commented on Jan 6, 2023

    @gaborbernat
    Member

    I think we were 🤔

  21. GalaxySnail commented on Mar 25, 2023

    @GalaxySnail

    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":
  22. ink-splatters commented on Apr 25, 2023

    @ink-splatters

    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.

  23. gaborbernat commented on Apr 25, 2023

    @gaborbernat
    Member

    Because macOS is certified Unix

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

  24. added a commit that references this issue on Jul 28, 2023
  25. justuswilhelm commented on Sep 13, 2023

    @justuswilhelm

    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.

  26. RonnyPfannschmidt commented on Sep 13, 2023

    @RonnyPfannschmidt

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

  27. added a commit that references this issue on Sep 27, 2023
  28. added a commit that references this issue on Oct 13, 2023
  29. added a commit that references this issue on Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions