1import os
2from shutil import rmtree
3
4from pip._internal.utils.appdirs import user_cache_dir
5
6from .click import secho
7
8# The user_cache_dir helper comes straight from pip itself
9CACHE_DIR = user_cache_dir("pip-tools")
10
11# NOTE
12# We used to store the cache dir under ~/.pip-tools, which is not the
13# preferred place to store caches for any platform.  This has been addressed
14# in pip-tools==1.0.5, but to be good citizens, we point this out explicitly
15# to the user when this directory is still found.
16LEGACY_CACHE_DIR = os.path.expanduser("~/.pip-tools")
17
18if os.path.exists(LEGACY_CACHE_DIR):
19    secho(
20        "Removing old cache dir {} (new cache dir is {})".format(
21            LEGACY_CACHE_DIR, CACHE_DIR
22        ),
23        fg="yellow",
24    )
25    rmtree(LEGACY_CACHE_DIR)
26