本文整理汇总了Python中pip.locations.USER_CACHE_DIR属性的典型用法代码示例。如果您正苦于以下问题:Python locations.USER_CACHE_DIR属性的具体用法?Python locations.USER_CACHE_DIR怎么用?Python locations.USER_CACHE_DIR使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pip.locations
的用法示例。
在下文中一共展示了locations.USER_CACHE_DIR属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_clear
# 需要导入模块: from pip import locations [as 别名]
# 或者: from pip.locations import USER_CACHE_DIR [as 别名]
def do_clear():
click.echo(crayons.white(fix_utf8("Clearing caches…"), bold=True))
try:
from pip._internal import locations
except ImportError: # pip 9.
from pip import locations
try:
vistir.path.rmtree(PIPENV_CACHE_DIR, onerror=vistir.path.handle_remove_readonly)
# Other processes may be writing into this directory simultaneously.
vistir.path.rmtree(
locations.USER_CACHE_DIR,
ignore_errors=environments.PIPENV_IS_CI,
onerror=vistir.path.handle_remove_readonly
)
except OSError as e:
# Ignore FileNotFoundError. This is needed for Python 2.7.
import errno
if e.errno == errno.ENOENT:
pass
raise
示例2: __init__
# 需要导入模块: from pip import locations [as 别名]
# 或者: from pip.locations import USER_CACHE_DIR [as 别名]
def __init__(self):
self.statefile_path = os.path.join(USER_CACHE_DIR, "selfcheck.json")
# Load the existing state
try:
with open(self.statefile_path) as statefile:
self.state = json.load(statefile)[sys.prefix]
except (IOError, ValueError, KeyError):
self.state = {}
示例3: pip_version_check
# 需要导入模块: from pip import locations [as 别名]
# 或者: from pip.locations import USER_CACHE_DIR [as 别名]
def pip_version_check(session):
"""Check for an update for pip.
Limit the frequency of checks to once per week. State is stored either in
the active virtualenv or in the user's USER_CACHE_DIR keyed off the prefix
of the pip script path.
"""
import pip # imported here to prevent circular imports
pypi_version = None
try:
state = load_selfcheck_statefile()
current_time = datetime.datetime.utcnow()
# Determine if we need to refresh the state
if "last_check" in state.state and "pypi_version" in state.state:
last_check = datetime.datetime.strptime(
state.state["last_check"],
SELFCHECK_DATE_FMT
)
if total_seconds(current_time - last_check) < 7 * 24 * 60 * 60:
pypi_version = state.state["pypi_version"]
# Refresh the version if we need to or just see if we need to warn
if pypi_version is None:
resp = session.get(
PyPI.pip_json_url,
headers={"Accept": "application/json"},
)
resp.raise_for_status()
pypi_version = [
v for v in sorted(
list(resp.json()["releases"]),
key=packaging_version.parse,
)
if not packaging_version.parse(v).is_prerelease
][-1]
# save that we've performed a check
state.save(pypi_version, current_time)
pip_version = packaging_version.parse(pip.__version__)
remote_version = packaging_version.parse(pypi_version)
# Determine if our pypi_version is older
if (pip_version < remote_version and
pip_version.base_version != remote_version.base_version):
logger.warning(
"You are using pip version %s, however version %s is "
"available.\nYou should consider upgrading via the "
"'pip install --upgrade pip' command." % (pip.__version__,
pypi_version)
)
except Exception:
logger.debug(
"There was an error checking the latest version of pip",
exc_info=True,
)