Skip to content

Commit c8d136b

Browse files
committed
Add poetry.locations.REPOSITORY_CACHE_DIR
The repository cache directory is used in multiple places in the codebase. This change ensures that the value is reused.
1 parent 7b1fd0c commit c8d136b

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

poetry/console/commands/cache/clear.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,17 @@ class CacheClearCommand(Command):
1616

1717
def handle(self):
1818
from cachy import CacheManager
19-
from poetry.locations import CACHE_DIR
20-
from poetry.utils._compat import Path
19+
from poetry.locations import REPOSITORY_CACHE_DIR
2120

2221
cache = self.argument("cache")
2322

2423
parts = cache.split(":")
2524
root = parts[0]
2625

27-
base_cache = Path(CACHE_DIR) / "cache" / "repositories"
28-
cache_dir = base_cache / root
26+
cache_dir = REPOSITORY_CACHE_DIR / root
2927

3028
try:
31-
cache_dir.relative_to(base_cache)
29+
cache_dir.relative_to(REPOSITORY_CACHE_DIR)
3230
except ValueError:
3331
raise ValueError("{} is not a valid repository cache".format(root))
3432

poetry/locations.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from .utils._compat import Path
12
from .utils.appdirs import user_cache_dir
23
from .utils.appdirs import user_config_dir
34

45

56
CACHE_DIR = user_cache_dir("pypoetry")
67
CONFIG_DIR = user_config_dir("pypoetry")
8+
9+
REPOSITORY_CACHE_DIR = Path(CACHE_DIR) / "cache" / "repositories"

poetry/repositories/legacy_repository.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import poetry.packages
1717

18-
from poetry.locations import CACHE_DIR
18+
from poetry.locations import REPOSITORY_CACHE_DIR
1919
from poetry.packages import Package
2020
from poetry.packages import dependency_from_pep_508
2121
from poetry.packages.utils.link import Link
@@ -174,7 +174,7 @@ def __init__(
174174
self._client_cert = client_cert
175175
self._cert = cert
176176
self._inspector = Inspector()
177-
self._cache_dir = Path(CACHE_DIR) / "cache" / "repositories" / name
177+
self._cache_dir = REPOSITORY_CACHE_DIR / name
178178
self._cache = CacheManager(
179179
{
180180
"default": "releases",

poetry/repositories/pypi_repository.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from requests import session
1616
from requests.exceptions import TooManyRedirects
1717

18-
from poetry.locations import CACHE_DIR
18+
from poetry.locations import REPOSITORY_CACHE_DIR
1919
from poetry.packages import Package
2020
from poetry.packages import dependency_from_pep_508
2121
from poetry.packages.utils.link import Link
@@ -55,7 +55,7 @@ def __init__(self, url="https://pypi.org/", disable_cache=False, fallback=True):
5555
self._disable_cache = disable_cache
5656
self._fallback = fallback
5757

58-
release_cache_dir = Path(CACHE_DIR) / "cache" / "repositories" / "pypi"
58+
release_cache_dir = REPOSITORY_CACHE_DIR / "pypi"
5959
self._cache = CacheManager(
6060
{
6161
"default": "releases",

0 commit comments

Comments
 (0)