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

Switch from appdirs to platformdirs #10202

Merged
merged 11 commits into from
Oct 2, 2021
1 change: 1 addition & 0 deletions news/10202.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace vendored appdirs with platformdirs.
1 change: 1 addition & 0 deletions news/pkg_resources.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Patch pkg_resources to use platformdirs rather than appdirs.
1 change: 1 addition & 0 deletions news/platformdirs.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Patch platformdirs import its submodules from ``pip._vendor.platformdirs``.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ drop = [

[tool.vendoring.typing-stubs]
six = ["six.__init__", "six.moves.__init__", "six.moves.configparser"]
appdirs = []
distro = []

[tool.vendoring.license.directories]
Expand Down
13 changes: 9 additions & 4 deletions src/pip/_internal/utils/appdirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
"""

import os
import sys
from typing import List

from pip._vendor import appdirs as _appdirs
from pip._vendor import platformdirs as _appdirs


def user_cache_dir(appname: str) -> str:
Expand All @@ -18,7 +19,7 @@ def user_cache_dir(appname: str) -> str:

def user_config_dir(appname: str, roaming: bool = True) -> str:
path = _appdirs.user_config_dir(appname, appauthor=False, roaming=roaming)
if _appdirs.system == "darwin" and not os.path.isdir(path):
if sys.platform == "darwin" and not os.path.isdir(path):
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved
path = os.path.expanduser("~/.config/")
if appname:
path = os.path.join(path, appname)
Expand All @@ -29,7 +30,11 @@ def user_config_dir(appname: str, roaming: bool = True) -> str:
# 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 _appdirs.system not in ["win32", "darwin"]:
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 [dirval]
else:
# always look in /etc directly as well
return dirval.split(os.pathsep) + ["/etc"]
return [dirval]
5 changes: 3 additions & 2 deletions src/pip/_vendor/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ Modifications

* ``setuptools`` is completely stripped to only keep ``pkg_resources``.
* ``pkg_resources`` has been modified to import its dependencies from
``pip._vendor``.
``pip._vendor``, and to use the vendored copy of ``platformdirs``
rather than ``appdirs``.
* ``packaging`` has been modified to import its dependencies from
``pip._vendor``.
* ``html5lib`` has been modified to import six from ``pip._vendor``, to prefer
Expand All @@ -111,7 +112,7 @@ Modifications
* ``requests`` has been modified to import its other dependencies from
``pip._vendor`` and to *not* load ``simplejson`` (all platforms) and
``pyopenssl`` (Windows).

* ``platformdirs`` has been modified to import its submodules from ``pip._vendor.platformdirs``.

Automatic Vendoring
===================
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_vendor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def vendored(modulename):
sys.path[:] = glob.glob(os.path.join(WHEEL_DIR, "*.whl")) + sys.path

# Actually alias all of our vendored dependencies.
vendored("appdirs")
vendored("cachecontrol")
vendored("certifi")
vendored("colorama")
Expand All @@ -74,6 +73,7 @@ def vendored(modulename):
vendored("packaging.specifiers")
vendored("pep517")
vendored("pkg_resources")
vendored("platformdirs")
vendored("progress")
vendored("requests")
vendored("requests.exceptions")
Expand Down
Loading