Skip to content

Commit

Permalink
Add poetry.locations.REPOSITORY_CACHE_DIR
Browse files Browse the repository at this point in the history
The repository cache directory is used in multiple places in the
codebase. This change ensures that the value is reused.
  • Loading branch information
abn committed Mar 2, 2020
1 parent 7b1fd0c commit c8d136b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
8 changes: 3 additions & 5 deletions poetry/console/commands/cache/clear.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@ class CacheClearCommand(Command):

def handle(self):
from cachy import CacheManager
from poetry.locations import CACHE_DIR
from poetry.utils._compat import Path
from poetry.locations import REPOSITORY_CACHE_DIR

cache = self.argument("cache")

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

base_cache = Path(CACHE_DIR) / "cache" / "repositories"
cache_dir = base_cache / root
cache_dir = REPOSITORY_CACHE_DIR / root

try:
cache_dir.relative_to(base_cache)
cache_dir.relative_to(REPOSITORY_CACHE_DIR)
except ValueError:
raise ValueError("{} is not a valid repository cache".format(root))

Expand Down
3 changes: 3 additions & 0 deletions poetry/locations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from .utils._compat import Path
from .utils.appdirs import user_cache_dir
from .utils.appdirs import user_config_dir


CACHE_DIR = user_cache_dir("pypoetry")
CONFIG_DIR = user_config_dir("pypoetry")

REPOSITORY_CACHE_DIR = Path(CACHE_DIR) / "cache" / "repositories"
4 changes: 2 additions & 2 deletions poetry/repositories/legacy_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import poetry.packages

from poetry.locations import CACHE_DIR
from poetry.locations import REPOSITORY_CACHE_DIR
from poetry.packages import Package
from poetry.packages import dependency_from_pep_508
from poetry.packages.utils.link import Link
Expand Down Expand Up @@ -174,7 +174,7 @@ def __init__(
self._client_cert = client_cert
self._cert = cert
self._inspector = Inspector()
self._cache_dir = Path(CACHE_DIR) / "cache" / "repositories" / name
self._cache_dir = REPOSITORY_CACHE_DIR / name
self._cache = CacheManager(
{
"default": "releases",
Expand Down
4 changes: 2 additions & 2 deletions poetry/repositories/pypi_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from requests import session
from requests.exceptions import TooManyRedirects

from poetry.locations import CACHE_DIR
from poetry.locations import REPOSITORY_CACHE_DIR
from poetry.packages import Package
from poetry.packages import dependency_from_pep_508
from poetry.packages.utils.link import Link
Expand Down Expand Up @@ -55,7 +55,7 @@ def __init__(self, url="https://pypi.org/", disable_cache=False, fallback=True):
self._disable_cache = disable_cache
self._fallback = fallback

release_cache_dir = Path(CACHE_DIR) / "cache" / "repositories" / "pypi"
release_cache_dir = REPOSITORY_CACHE_DIR / "pypi"
self._cache = CacheManager(
{
"default": "releases",
Expand Down

0 comments on commit c8d136b

Please sign in to comment.