Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
Python_Packaging_Authority
pip
提交
c7419b2a
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,发现更多精彩内容 >>
未验证
提交
c7419b2a
编写于
1月 05, 2021
作者:
P
Pradyun Gedam
提交者:
GitHub
1月 05, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9320 from uranusjr/wheel-check-valid
Verify built wheel contains valid metadata
上级
47493d82
6902269d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
71 addition
and
2 deletion
+71
-2
news/9206.feature.rst
news/9206.feature.rst
+3
-0
src/pip/_internal/commands/install.py
src/pip/_internal/commands/install.py
+1
-0
src/pip/_internal/commands/wheel.py
src/pip/_internal/commands/wheel.py
+9
-0
src/pip/_internal/wheel_builder.py
src/pip/_internal/wheel_builder.py
+58
-2
未找到文件。
news/9206.feature.rst
0 → 100644
浏览文件 @
c7419b2a
``pip wheel`` now verifies the built wheel contains valid metadata, and can be
installed by a subsequent ``pip install``. This can be disabled with
``--no-verify``.
src/pip/_internal/commands/install.py
浏览文件 @
c7419b2a
...
...
@@ -343,6 +343,7 @@ class InstallCommand(RequirementCommand):
_
,
build_failures
=
build
(
reqs_to_build
,
wheel_cache
=
wheel_cache
,
verify
=
True
,
build_options
=
[],
global_options
=
[],
)
...
...
src/pip/_internal/commands/wheel.py
浏览文件 @
c7419b2a
...
...
@@ -77,6 +77,14 @@ class WheelCommand(RequirementCommand):
self
.
cmd_opts
.
add_option
(
cmdoptions
.
build_dir
())
self
.
cmd_opts
.
add_option
(
cmdoptions
.
progress_bar
())
self
.
cmd_opts
.
add_option
(
'--no-verify'
,
dest
=
'no_verify'
,
action
=
'store_true'
,
default
=
False
,
help
=
"Don't verify if built wheel is valid."
,
)
self
.
cmd_opts
.
add_option
(
'--global-option'
,
dest
=
'global_options'
,
...
...
@@ -162,6 +170,7 @@ class WheelCommand(RequirementCommand):
build_successes
,
build_failures
=
build
(
reqs_to_build
,
wheel_cache
=
wheel_cache
,
verify
=
(
not
options
.
no_verify
),
build_options
=
options
.
build_options
or
[],
global_options
=
options
.
global_options
or
[],
)
...
...
src/pip/_internal/wheel_builder.py
浏览文件 @
c7419b2a
...
...
@@ -5,8 +5,15 @@ import logging
import
os.path
import
re
import
shutil
import
zipfile
from
pip._vendor.packaging.utils
import
canonicalize_name
,
canonicalize_version
from
pip._vendor.packaging.version
import
InvalidVersion
,
Version
from
pip._vendor.pkg_resources
import
Distribution
from
pip._internal.exceptions
import
InvalidWheelFilename
,
UnsupportedWheel
from
pip._internal.models.link
import
Link
from
pip._internal.models.wheel
import
Wheel
from
pip._internal.operations.build.wheel
import
build_wheel_pep517
from
pip._internal.operations.build.wheel_legacy
import
build_wheel_legacy
from
pip._internal.utils.logging
import
indent_log
...
...
@@ -16,6 +23,7 @@ from pip._internal.utils.subprocess import call_subprocess
from
pip._internal.utils.temp_dir
import
TempDirectory
from
pip._internal.utils.typing
import
MYPY_CHECK_RUNNING
from
pip._internal.utils.urls
import
path_to_url
from
pip._internal.utils.wheel
import
pkg_resources_distribution_for_wheel
from
pip._internal.vcs
import
vcs
if
MYPY_CHECK_RUNNING
:
...
...
@@ -163,9 +171,49 @@ def _always_true(_):
return
True
def
_get_metadata_version
(
dist
):
# type: (Distribution) -> Optional[Version]
for
line
in
dist
.
get_metadata_lines
(
dist
.
PKG_INFO
):
if
line
.
lower
().
startswith
(
"metadata-version:"
):
value
=
line
.
split
(
":"
,
1
)[
-
1
].
strip
()
try
:
return
Version
(
value
)
except
InvalidVersion
:
msg
=
"Invalid Metadata-Version: {}"
.
format
(
value
)
raise
UnsupportedWheel
(
msg
)
raise
UnsupportedWheel
(
"Missing Metadata-Version"
)
def
_verify_one
(
req
,
wheel_path
):
# type: (InstallRequirement, str) -> None
canonical_name
=
canonicalize_name
(
req
.
name
)
w
=
Wheel
(
os
.
path
.
basename
(
wheel_path
))
if
canonicalize_name
(
w
.
name
)
!=
canonical_name
:
raise
InvalidWheelFilename
(
"Wheel has unexpected file name: expected {!r}, "
"got {!r}"
.
format
(
canonical_name
,
w
.
name
),
)
with
zipfile
.
ZipFile
(
wheel_path
,
allowZip64
=
True
)
as
zf
:
dist
=
pkg_resources_distribution_for_wheel
(
zf
,
canonical_name
,
wheel_path
,
)
if
canonicalize_version
(
dist
.
version
)
!=
canonicalize_version
(
w
.
version
):
raise
InvalidWheelFilename
(
"Wheel has unexpected file name: expected {!r}, "
"got {!r}"
.
format
(
dist
.
version
,
w
.
version
),
)
if
(
_get_metadata_version
(
dist
)
>=
Version
(
"1.2"
)
and
not
isinstance
(
dist
.
parsed_version
,
Version
)):
raise
UnsupportedWheel
(
"Metadata 1.2 mandates PEP 440 version, "
"but {!r} is not"
.
format
(
dist
.
version
)
)
def
_build_one
(
req
,
# type: InstallRequirement
output_dir
,
# type: str
verify
,
# type: bool
build_options
,
# type: List[str]
global_options
,
# type: List[str]
):
...
...
@@ -185,9 +233,16 @@ def _build_one(
# Install build deps into temporary directory (PEP 518)
with
req
.
build_env
:
return
_build_one_inside_env
(
wheel_path
=
_build_one_inside_env
(
req
,
output_dir
,
build_options
,
global_options
)
if
wheel_path
and
verify
:
try
:
_verify_one
(
req
,
wheel_path
)
except
(
InvalidWheelFilename
,
UnsupportedWheel
)
as
e
:
logger
.
warning
(
"Built wheel for %s is invalid: %s"
,
req
.
name
,
e
)
return
None
return
wheel_path
def
_build_one_inside_env
(
...
...
@@ -260,6 +315,7 @@ def _clean_one_legacy(req, global_options):
def
build
(
requirements
,
# type: Iterable[InstallRequirement]
wheel_cache
,
# type: WheelCache
verify
,
# type: bool
build_options
,
# type: List[str]
global_options
,
# type: List[str]
):
...
...
@@ -283,7 +339,7 @@ def build(
for
req
in
requirements
:
cache_dir
=
_get_cache_dir
(
req
,
wheel_cache
)
wheel_file
=
_build_one
(
req
,
cache_dir
,
build_options
,
global_options
req
,
cache_dir
,
verify
,
build_options
,
global_options
)
if
wheel_file
:
# Update the link for this.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录