Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
Python_Packaging_Authority
pip
提交
750b8a32
P
pip
项目概览
镜像
/
Python_Packaging_Authority
/
pip
12 个月 前同步成功
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
pip
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
750b8a32
编写于
1月 10, 2021
作者:
S
Stéphane Bidoul
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove support for legacy cache entries
上级
e157cf56
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
2 addition
and
88 deletion
+2
-88
news/7502.removal.rst
news/7502.removal.rst
+2
-0
src/pip/_internal/cache.py
src/pip/_internal/cache.py
+0
-47
tests/unit/test_cache.py
tests/unit/test_cache.py
+0
-41
未找到文件。
news/7502.removal.rst
0 → 100644
浏览文件 @
750b8a32
Remove support for legacy wheel cache entries that were created with pip
versions older than 20.0.
src/pip/_internal/cache.py
浏览文件 @
750b8a32
...
...
@@ -55,34 +55,6 @@ class Cache:
_valid_formats
=
{
"source"
,
"binary"
}
assert
self
.
allowed_formats
.
union
(
_valid_formats
)
==
_valid_formats
def
_get_cache_path_parts_legacy
(
self
,
link
):
# type: (Link) -> List[str]
"""Get parts of part that must be os.path.joined with cache_dir
Legacy cache key (pip < 20) for compatibility with older caches.
"""
# We want to generate an url to use as our cache key, we don't want to
# just re-use the URL because it might have other items in the fragment
# and we don't care about those.
key_parts
=
[
link
.
url_without_fragment
]
if
link
.
hash_name
is
not
None
and
link
.
hash
is
not
None
:
key_parts
.
append
(
"="
.
join
([
link
.
hash_name
,
link
.
hash
]))
key_url
=
"#"
.
join
(
key_parts
)
# Encode our key url with sha224, we'll use this because it has similar
# security properties to sha256, but with a shorter total output (and
# thus less secure). However the differences don't make a lot of
# difference for our use case here.
hashed
=
hashlib
.
sha224
(
key_url
.
encode
()).
hexdigest
()
# We want to nest the directories some to prevent having a ton of top
# level directories where we might run out of sub directories on some
# FS.
parts
=
[
hashed
[:
2
],
hashed
[
2
:
4
],
hashed
[
4
:
6
],
hashed
[
6
:]]
return
parts
def
_get_cache_path_parts
(
self
,
link
):
# type: (Link) -> List[str]
"""Get parts of part that must be os.path.joined with cache_dir
...
...
@@ -139,17 +111,8 @@ class Cache:
if
os
.
path
.
isdir
(
path
):
for
candidate
in
os
.
listdir
(
path
):
candidates
.
append
((
candidate
,
path
))
# TODO remove legacy path lookup in pip>=21
legacy_path
=
self
.
get_path_for_link_legacy
(
link
)
if
os
.
path
.
isdir
(
legacy_path
):
for
candidate
in
os
.
listdir
(
legacy_path
):
candidates
.
append
((
candidate
,
legacy_path
))
return
candidates
def
get_path_for_link_legacy
(
self
,
link
):
# type: (Link) -> str
raise
NotImplementedError
()
def
get_path_for_link
(
self
,
link
):
# type: (Link) -> str
"""Return a directory to store cached items in for link.
...
...
@@ -177,12 +140,6 @@ class SimpleWheelCache(Cache):
# type: (str, FormatControl) -> None
super
().
__init__
(
cache_dir
,
format_control
,
{
"binary"
})
def
get_path_for_link_legacy
(
self
,
link
):
# type: (Link) -> str
parts
=
self
.
_get_cache_path_parts_legacy
(
link
)
assert
self
.
cache_dir
return
os
.
path
.
join
(
self
.
cache_dir
,
"wheels"
,
*
parts
)
def
get_path_for_link
(
self
,
link
):
# type: (Link) -> str
"""Return a directory to store cached wheels for link
...
...
@@ -286,10 +243,6 @@ class WheelCache(Cache):
self
.
_wheel_cache
=
SimpleWheelCache
(
cache_dir
,
format_control
)
self
.
_ephem_cache
=
EphemWheelCache
(
format_control
)
def
get_path_for_link_legacy
(
self
,
link
):
# type: (Link) -> str
return
self
.
_wheel_cache
.
get_path_for_link_legacy
(
link
)
def
get_path_for_link
(
self
,
link
):
# type: (Link) -> str
return
self
.
_wheel_cache
.
get_path_for_link
(
link
)
...
...
tests/unit/test_cache.py
浏览文件 @
750b8a32
...
...
@@ -51,47 +51,6 @@ def test_cache_hash():
assert
h
==
"f83b32dfa27a426dec08c21bf006065dd003d0aac78e7fc493d9014d"
def
test_get_path_for_link_legacy
(
tmpdir
):
"""
Test that an existing cache entry that was created with the legacy hashing
mechanism is returned by WheelCache._get_candidates().
"""
wc
=
WheelCache
(
tmpdir
,
FormatControl
())
link
=
Link
(
"https://g.c/o/r"
)
path
=
wc
.
get_path_for_link
(
link
)
legacy_path
=
wc
.
get_path_for_link_legacy
(
link
)
assert
path
!=
legacy_path
ensure_dir
(
path
)
with
open
(
os
.
path
.
join
(
path
,
"test-1.0.0-pyz-none-any.whl"
),
"w"
):
pass
ensure_dir
(
legacy_path
)
with
open
(
os
.
path
.
join
(
legacy_path
,
"test-1.0.0-pyx-none-any.whl"
),
"w"
):
pass
expected_candidates
=
{
"test-1.0.0-pyx-none-any.whl"
,
"test-1.0.0-pyz-none-any.whl"
}
candidates
=
{
c
[
0
]
for
c
in
wc
.
_get_candidates
(
link
,
"test"
)}
assert
candidates
==
expected_candidates
def
test_get_with_legacy_entry_only
(
tmpdir
):
"""
Test that an existing cache entry that was created with the legacy hashing
mechanism is actually returned in WheelCache.get().
"""
wc
=
WheelCache
(
tmpdir
,
FormatControl
())
link
=
Link
(
"https://g.c/o/r"
)
legacy_path
=
wc
.
get_path_for_link_legacy
(
link
)
ensure_dir
(
legacy_path
)
with
open
(
os
.
path
.
join
(
legacy_path
,
"test-1.0.0-py3-none-any.whl"
),
"w"
):
pass
cached_link
=
wc
.
get
(
link
,
"test"
,
[
Tag
(
"py3"
,
"none"
,
"any"
)])
assert
(
os
.
path
.
normcase
(
os
.
path
.
dirname
(
cached_link
.
file_path
))
==
os
.
path
.
normcase
(
legacy_path
)
)
def
test_get_cache_entry
(
tmpdir
):
wc
=
WheelCache
(
tmpdir
,
FormatControl
())
persi_link
=
Link
(
"https://g.c/o/r/persi"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录