Repository: pypa/pip

Issue:
21.3: No longer looking for pip.conf in ~/Library/Application Support/pip/
### Description

After upgrading to pip 21.3, it no longer read the configuration file in ~/Library/Application Support/pip/.

### Expected behavior

Please read the configuration file in  ~/Library/Application Support/pip/.

### pip version

21.3

### Python version

3.8.5

### OS

macOS 11.6

### How to Reproduce

1. Upgrade pip to 21.3
2. Put configuration in ~/Library/Application Support/pip/.
3. Observe that the configuration is not read.


### Output

_No response_

### Code of Conduct

- [X] I agree to follow the [PSF Code of Conduct](https://www.python.org/psf/conduct/).


Discussion:
21.3:

    env_var:
    env:
    global:
      /Library/Preferences/pip/pip.conf, exists: False
      /Library/Application Support/pip/pip.conf, exists: False
    site:
      /Users/pradyunsg/Developer/pip/.venv/pip.conf, exists: False
    user:
      /Users/pradyunsg/.pip/pip.conf, exists: False
      /Users/pradyunsg/.config/pip/pip.conf, exists: True

21.2.4:

    env_var:
    env:
    global:
      /Library/Application Support/pip/pip.conf, exists: False
    site:
      /Users/pradyunsg/Developer/pip/.venv/pip.conf, exists: False
    user:
      /Users/pradyunsg/.pip/pip.conf, exists: False
      /Users/pradyunsg/.config/pip/pip.conf, exists: True

Hmm... that's not the behaviour that I see.
We explicitly have code, to ensure that we look there:

https://github.com/pypa/pip/blob/abec8a701bfa66aa15fedf4c898011aa2d95f29e/src/pip/_internal/utils/appdirs.py#L35
What's the output of `pip config debug` and `pip debug` for you?
The path difference is probably caused by different behaviour between appdirs and platformdirs? But the report confuses me even accounting for the difference; shouldn't the `Application Support` directory be respected even if there's now a new directory ahead of it?
Here some pip confg debug outputs 

pip 21.2.4 

```
env_var:
env:
global:
  /Library/Application Support/pip/pip.conf, exists: False
site:
  /private/tmp/test/pip.conf, exists: False
user:
  /Users/estartu/.pip/pip.conf, exists: False
  /Users/estartu/Library/Application Support/pip/pip.conf, exists: True
    global.timeout: 20
    global.upgrade-strategy: eager
    list.format: columns
```
pip 21.3
```
env_var:
env:
global:
  /Library/Preferences/pip/pip.conf, exists: False
  /Library/Application Support/pip/pip.conf, exists: False
site:
  /private/tmp/test/pip.conf, exists: False
user:
  /Users/estartu/.pip/pip.conf, exists: False
  /Users/estartu/.config/pip/pip.conf, exists: False
``` 

pip 21.3 checks the unix .config dir instead of the MacOS Application Support dir



Ah fun. I'm able to reproduce this on my MacBook.

Not sure how we'd test this, but I think I can whip up a patch for thisnovdr the weekend.

Resolving patch:
diff --git a/src/pip/_internal/utils/appdirs.py b/src/pip/_internal/utils/appdirs.py
--- a/src/pip/_internal/utils/appdirs.py
+++ b/src/pip/_internal/utils/appdirs.py
@@ -17,24 +17,36 @@ def user_cache_dir(appname: str) -> str:
     return _appdirs.user_cache_dir(appname, appauthor=False)
 
 
+def _macos_user_config_dir(appname: str, roaming: bool = True) -> str:
+    # Use ~/Application Support/pip, if the directory exists.
+    path = _appdirs.user_data_dir(appname, appauthor=False, roaming=roaming)
+    if os.path.isdir(path):
+        return path
+
+    # Use a Linux-like ~/.config/pip, by default.
+    linux_like_path = "~/.config/"
+    if appname:
+        linux_like_path = os.path.join(linux_like_path, appname)
+
+    return os.path.expanduser(linux_like_path)
+
+
 def user_config_dir(appname: str, roaming: bool = True) -> str:
-    path = _appdirs.user_config_dir(appname, appauthor=False, roaming=roaming)
-    if sys.platform == "darwin" and not os.path.isdir(path):
-        path = os.path.expanduser("~/.config/")
-        if appname:
-            path = os.path.join(path, appname)
-    return path
+    if sys.platform == "darwin":
+        return _macos_user_config_dir(appname, roaming)
+
+    return _appdirs.user_config_dir(appname, appauthor=False, roaming=roaming)
 
 
 # for the discussion regarding site_config_dir locations
 # see <https://github.com/pypa/pip/issues/1733>
 def site_config_dirs(appname: str) -> List[str]:
-    dirval = _appdirs.site_config_dir(appname, appauthor=False, multipath=True)
     if sys.platform == "darwin":
-        # always look in /Library/Application Support/pip as well
-        return dirval.split(os.pathsep) + ["/Library/Application Support/pip"]
-    elif sys.platform == "win32":
+        return [_appdirs.site_data_dir(appname, appauthor=False, multipath=True)]
+
+    dirval = _appdirs.site_config_dir(appname, appauthor=False, multipath=True)
+    if sys.platform == "win32":
         return [dirval]
-    else:
-        # always look in /etc directly as well
-        return dirval.split(os.pathsep) + ["/etc"]
+
+    # Unix-y system. Look in /etc as well.
+    return dirval.split(os.pathsep) + ["/etc"]


Test patch:
diff --git a/tests/unit/test_appdirs.py b/tests/unit/test_appdirs.py
--- a/tests/unit/test_appdirs.py
+++ b/tests/unit/test_appdirs.py
@@ -99,7 +99,6 @@ def test_site_config_dirs_osx(self, monkeypatch: pytest.MonkeyPatch) -> None:
         monkeypatch.setenv("HOME", "/home/test")
 
         assert appdirs.site_config_dirs("pip") == [
-            "/Library/Preferences/pip",
             "/Library/Application Support/pip",
         ]
 
@@ -107,7 +106,10 @@ def test_site_config_dirs_osx(self, monkeypatch: pytest.MonkeyPatch) -> None:
     def test_site_config_dirs_linux(self, monkeypatch: pytest.MonkeyPatch) -> None:
         monkeypatch.delenv("XDG_CONFIG_DIRS", raising=False)
 
-        assert appdirs.site_config_dirs("pip") == ["/etc/xdg/pip", "/etc"]
+        assert appdirs.site_config_dirs("pip") == [
+            "/etc/xdg/pip",
+            "/etc",
+        ]
 
     @pytest.mark.skipif(sys.platform != "linux", reason="Linux-only test")
     def test_site_config_dirs_linux_override(
@@ -129,7 +131,10 @@ def test_site_config_dirs_linux_empty(
     ) -> None:
         monkeypatch.setattr(os, "pathsep", ":")
         monkeypatch.setenv("XDG_CONFIG_DIRS", "")
-        assert appdirs.site_config_dirs("pip") == ["/etc/xdg/pip", "/etc"]
+        assert appdirs.site_config_dirs("pip") == [
+            "/etc/xdg/pip",
+            "/etc",
+        ]
 
 
 class TestUserConfigDir: