Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
Python_Packaging_Authority
pip
提交
0c284520
P
pip
项目概览
镜像
/
Python_Packaging_Authority
/
pip
10 个月 前同步成功
通知
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
0c284520
编写于
3月 16, 2022
作者:
Q
q0w
提交者:
GitHub
3月 16, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Filter available distributions using hash declarations from constraints files (#10962)
上级
b73b1286
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
57 addition
and
15 deletion
+57
-15
news/9243.bugfix.rst
news/9243.bugfix.rst
+1
-0
src/pip/_internal/req/req_install.py
src/pip/_internal/req/req_install.py
+2
-3
src/pip/_internal/resolution/resolvelib/factory.py
src/pip/_internal/resolution/resolvelib/factory.py
+6
-12
src/pip/_internal/utils/hashes.py
src/pip/_internal/utils/hashes.py
+4
-0
src/pip/_internal/utils/packaging.py
src/pip/_internal/utils/packaging.py
+13
-0
tests/functional/test_new_resolver_hashes.py
tests/functional/test_new_resolver_hashes.py
+31
-0
未找到文件。
news/9243.bugfix.rst
0 → 100644
浏览文件 @
0c284520
Filter available distributions using hash declarations from constraints files.
src/pip/_internal/req/req_install.py
浏览文件 @
0c284520
...
...
@@ -52,7 +52,7 @@ from pip._internal.utils.misc import (
hide_url
,
redact_auth_from_url
,
)
from
pip._internal.utils.packaging
import
safe_extra
from
pip._internal.utils.packaging
import
is_pinned
,
safe_extra
from
pip._internal.utils.subprocess
import
runner_with_spinner_message
from
pip._internal.utils.temp_dir
import
TempDirectory
,
tempdir_kinds
from
pip._internal.utils.virtualenv
import
running_under_virtualenv
...
...
@@ -238,8 +238,7 @@ class InstallRequirement:
For example, some-package==1.2 is pinned; some-package>1.2 is not.
"""
specifiers
=
self
.
specifier
return
len
(
specifiers
)
==
1
and
next
(
iter
(
specifiers
)).
operator
in
{
"=="
,
"==="
}
return
is_pinned
(
self
.
specifier
)
def
match_markers
(
self
,
extras_requested
:
Optional
[
Iterable
[
str
]]
=
None
)
->
bool
:
if
not
extras_requested
:
...
...
src/pip/_internal/resolution/resolvelib/factory.py
浏览文件 @
0c284520
...
...
@@ -45,7 +45,7 @@ from pip._internal.req.req_install import (
from
pip._internal.resolution.base
import
InstallRequirementProvider
from
pip._internal.utils.compatibility_tags
import
get_supported
from
pip._internal.utils.hashes
import
Hashes
from
pip._internal.utils.packaging
import
get_requirement
from
pip._internal.utils.packaging
import
get_requirement
,
is_pinned
from
pip._internal.utils.virtualenv
import
running_under_virtualenv
from
.base
import
Candidate
,
CandidateVersion
,
Constraint
,
Requirement
...
...
@@ -303,19 +303,13 @@ class Factory:
# solely satisfied by a yanked release.
all_yanked
=
all
(
ican
.
link
.
is_yanked
for
ican
in
icans
)
def
is_pinned
(
specifier
:
SpecifierSet
)
->
bool
:
for
sp
in
specifier
:
if
sp
.
operator
==
"==="
:
return
True
if
sp
.
operator
!=
"=="
:
continue
if
sp
.
version
.
endswith
(
".*"
):
continue
return
True
return
False
pinned
=
is_pinned
(
specifier
)
if
not
template
.
is_pinned
:
assert
template
.
req
,
"Candidates found on index must be PEP 508"
template
.
req
.
specifier
=
specifier
template
.
hash_options
=
hashes
.
allowed
# PackageFinder returns earlier versions first, so we reverse.
for
ican
in
reversed
(
icans
):
if
not
(
all_yanked
and
pinned
)
and
ican
.
link
.
is_yanked
:
...
...
src/pip/_internal/utils/hashes.py
浏览文件 @
0c284520
...
...
@@ -63,6 +63,10 @@ class Hashes:
def
digest_count
(
self
)
->
int
:
return
sum
(
len
(
digests
)
for
digests
in
self
.
_allowed
.
values
())
@
property
def
allowed
(
self
)
->
Dict
[
str
,
List
[
str
]]:
return
self
.
_allowed
def
is_hash_allowed
(
self
,
hash_name
:
str
,
hex_digest
:
str
)
->
bool
:
"""Return whether the given hex digest is allowed."""
return
hex_digest
in
self
.
_allowed
.
get
(
hash_name
,
[])
...
...
src/pip/_internal/utils/packaging.py
浏览文件 @
0c284520
...
...
@@ -5,6 +5,7 @@ from typing import NewType, Optional, Tuple, cast
from
pip._vendor.packaging
import
specifiers
,
version
from
pip._vendor.packaging.requirements
import
Requirement
from
pip._vendor.packaging.specifiers
import
SpecifierSet
NormalizedExtra
=
NewType
(
"NormalizedExtra"
,
str
)
...
...
@@ -55,3 +56,15 @@ def safe_extra(extra: str) -> NormalizedExtra:
the same to either ``canonicalize_name`` or ``_egg_link_name``.
"""
return
cast
(
NormalizedExtra
,
re
.
sub
(
"[^A-Za-z0-9.-]+"
,
"_"
,
extra
).
lower
())
def
is_pinned
(
specifier
:
SpecifierSet
)
->
bool
:
for
sp
in
specifier
:
if
sp
.
operator
==
"==="
:
return
True
if
sp
.
operator
!=
"=="
:
continue
if
sp
.
version
.
endswith
(
".*"
):
continue
return
True
return
False
tests/functional/test_new_resolver_hashes.py
浏览文件 @
0c284520
...
...
@@ -373,3 +373,34 @@ def test_new_resolver_hash_with_extras(script: PipTestEnvironment) -> None:
child
=
"0.1.0"
,
extra
=
"0.1.0"
,
)
def
test_new_resolver_hash_with_pin
(
script
:
PipTestEnvironment
)
->
None
:
find_links
=
_create_find_links
(
script
)
requirements_txt
=
script
.
scratch_path
/
"requirements.txt"
requirements_txt
.
write_text
(
"base"
)
constraints_txt
=
script
.
scratch_path
/
"constraints.txt"
constraints_txt
.
write_text
(
"""
base==0.1.0 --hash=sha256:{sdist_hash} --hash=sha256:{wheel_hash}
"""
.
format
(
sdist_hash
=
find_links
.
sdist_hash
,
wheel_hash
=
find_links
.
wheel_hash
,
)
)
script
.
pip
(
"install"
,
"--no-cache-dir"
,
"--no-index"
,
"--find-links"
,
find_links
.
index_html
,
"--requirement"
,
requirements_txt
,
"--constraint"
,
constraints_txt
,
)
script
.
assert_installed
(
base
=
"0.1.0"
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录