Follow configurations under $XDG_CONFIG_HOME on macOS too!
Although macOS is a genuine UNIX OS and the document says
For Unix, we follow the XDG spec
you don't, on macOS.
I'm using $XDG_CONFIG_HOME to manage configurations.
$ ls $XDG_CONFIG_HOME
alacritty/ configstore/ git/ iterm/ micro/ tmux/
anyenv/ fish/ hub karabiner/ ssh/
As you see, many tools like git, fish, anyenv and karabiner-elements supports XDG by nature (some are not by nature, but can be configured).
I believe this is good strategy since it's more suitable to version-control in my "dotfiles" repository GitHub.
I know this will be breaking change, but at least, I want some way to configure it (such as env variable like PYPOETRY_FOLLOW_XDG).
Second this as a macOS user organizing my dotfiles in a XDG-compliant manner.
Regarding the compatibility, could something like this be an option?
diff --git a/poetry/utils/appdirs.py b/poetry/utils/appdirs.py
index 522dcf3..63572e5 100644
--- a/poetry/utils/appdirs.py
+++ b/poetry/utils/appdirs.py
@@ -47,7 +47,7 @@ def user_cache_dir(appname):
# Add our app name and Cache directory to it
path = os.path.join(path, appname, "Cache")
- elif sys.platform == "darwin":
+ elif sys.platform == "darwin" and "XDG_CACHE_HOME" not in os.environ:
# Get the base path
path = expanduser("~/Library/Caches")
@@ -93,7 +93,7 @@ def user_data_dir(appname, roaming=False):
if WINDOWS:
const = roaming and "CSIDL_APPDATA" or "CSIDL_LOCAL_APPDATA"
path = os.path.join(os.path.normpath(_get_win_folder(const)), appname)
- elif sys.platform == "darwin":
+ elif sys.platform == "darwin" and "XDG_DATA_HOME" not in os.environ:
path = os.path.join(expanduser("~/Library/Application Support/"), appname)
else:
path = os.path.join(
@@ -125,7 +125,7 @@ def user_config_dir(appname, roaming=True):
"""
if WINDOWS:
path = user_data_dir(appname, roaming=roaming)
- elif sys.platform == "darwin":
+ elif sys.platform == "darwin" and "XDG_CONFIG_HOME" not in os.environ:
path = user_data_dir(appname)
else:
path = os.getenv("XDG_CONFIG_HOME", expanduser("~/.config"))
@@ -155,7 +155,7 @@ def site_config_dirs(appname):
if WINDOWS:
path = os.path.normpath(_get_win_folder("CSIDL_COMMON_APPDATA"))
pathlist = [os.path.join(path, appname)]
- elif sys.platform == "darwin":
+ elif sys.platform == "darwin" and "XDG_CONFIG_DIRS" not in os.environ:
pathlist = [os.path.join("/Library/Application Support", appname)]
else:
# try looking in $XDG_CONFIG_DIRS
Although this indeed brings a breaking change, it has no effect on macOS users who do not set XDG-related environment variables. macOS users who deliberately set those variables (like me) will be affected, but I suppose they should be happy with this change.
I've prepared yudai-nkt/poetry@513c990, so I can send a PR if this is more or less the right direction.
I don't think this needs to be a breaking change. Simply follow the freedesktop spec by default but fall back to the old behavior if files are not found there.
There's also this bit:
The installer installs the poetry tool to Poetry's bin directory. On Unix it is located at $HOME/.poetry/bin and on Windows at %USERPROFILE%.poetrybin.
This should be installed to $XDG_DATA_HOME. On my system this would be /home/ryan/.local/share.
I created a PR to solve this issue, but since I don't know it is considered a new feature or a bug fix, I create it against the develop branch. If this can be a bug fix for 1.0, I can submit another PR:
~#1507~ #1823
Is there any chance of this making it into 1.0.4, or whatever the next version is? It's one of the assorted UX papercuts that still remain.
Also, thanks for making the PR.
Have there been any developments here? Would be interested in this as well.
Most helpful comment
I created a PR to solve this issue, but since I don't know it is considered a new feature or a bug fix, I create it against the
developbranch. If this can be a bug fix for 1.0, I can submit another PR:~#1507~ #1823