Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
Python_Packaging_Authority
pip
提交
b0a7d2b5
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,发现更多精彩内容 >>
提交
b0a7d2b5
编写于
7月 21, 2019
作者:
C
Chris Hunt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor wheel.move_wheel_files to use updated distlib.
上级
d764181d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
73 addition
and
56 deletion
+73
-56
src/pip/_internal/wheel.py
src/pip/_internal/wheel.py
+59
-56
tests/unit/test_wheel.py
tests/unit/test_wheel.py
+14
-0
未找到文件。
src/pip/_internal/wheel.py
浏览文件 @
b0a7d2b5
...
...
@@ -23,6 +23,7 @@ from email.parser import Parser
from
pip._vendor
import
pkg_resources
from
pip._vendor.distlib.scripts
import
ScriptMaker
from
pip._vendor.distlib.util
import
get_export_entry
from
pip._vendor.packaging.utils
import
canonicalize_name
from
pip._vendor.six
import
StringIO
...
...
@@ -311,6 +312,22 @@ def get_csv_rows_for_installed(
return
installed_rows
class
MissingCallableSuffix
(
Exception
):
pass
def
_assert_valid_entrypoint
(
specification
):
entry
=
get_export_entry
(
specification
)
if
entry
is
not
None
and
entry
.
suffix
is
None
:
raise
MissingCallableSuffix
(
str
(
entry
))
class
PipScriptMaker
(
ScriptMaker
):
def
make
(
self
,
specification
,
options
=
None
):
_assert_valid_entrypoint
(
specification
)
return
super
(
PipScriptMaker
,
self
).
make
(
specification
,
options
)
def
move_wheel_files
(
name
,
# type: str
req
,
# type: Requirement
...
...
@@ -473,7 +490,7 @@ def move_wheel_files(
dest
=
scheme
[
subdir
]
clobber
(
source
,
dest
,
False
,
fixer
=
fixer
,
filter
=
filter
)
maker
=
ScriptMaker
(
None
,
scheme
[
'scripts'
])
maker
=
Pip
ScriptMaker
(
None
,
scheme
[
'scripts'
])
# Ensure old scripts are overwritten.
# See https://github.com/pypa/pip/issues/1800
...
...
@@ -489,36 +506,7 @@ def move_wheel_files(
# See https://bitbucket.org/pypa/distlib/issue/32/
maker
.
set_mode
=
True
# Simplify the script and fix the fact that the default script swallows
# every single stack trace.
# See https://bitbucket.org/pypa/distlib/issue/34/
# See https://bitbucket.org/pypa/distlib/issue/33/
def
_get_script_text
(
entry
):
if
entry
.
suffix
is
None
:
raise
InstallationError
(
"Invalid script entry point: %s for req: %s - A callable "
"suffix is required. Cf https://packaging.python.org/en/"
"latest/distributing.html#console-scripts for more "
"information."
%
(
entry
,
req
)
)
return
maker
.
script_template
%
{
"module"
:
entry
.
prefix
,
"import_name"
:
entry
.
suffix
.
split
(
"."
)[
0
],
"func"
:
entry
.
suffix
,
}
# ignore type, because mypy disallows assigning to a method,
# see https://github.com/python/mypy/issues/2427
maker
.
_get_script_text
=
_get_script_text
# type: ignore
maker
.
script_template
=
r
"""# -*- coding: utf-8 -*-
import re
import sys
from %(module)s import %(import_name)s
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(%(func)s())
"""
scripts_to_generate
=
[]
# Special case pip and setuptools to generate versioned wrappers
#
...
...
@@ -556,15 +544,16 @@ if __name__ == '__main__':
pip_script
=
console
.
pop
(
'pip'
,
None
)
if
pip_script
:
if
"ENSUREPIP_OPTIONS"
not
in
os
.
environ
:
spec
=
'pip = '
+
pip_script
generated
.
extend
(
maker
.
make
(
spec
))
scripts_to_generate
.
append
(
'pip = '
+
pip_script
)
if
os
.
environ
.
get
(
"ENSUREPIP_OPTIONS"
,
""
)
!=
"altinstall"
:
spec
=
'pip%s = %s'
%
(
sys
.
version_info
[
0
],
pip_script
)
generated
.
extend
(
maker
.
make
(
spec
))
scripts_to_generate
.
append
(
'pip%s = %s'
%
(
sys
.
version_info
[
0
],
pip_script
)
)
spec
=
'pip%s = %s'
%
(
get_major_minor_version
(),
pip_script
)
generated
.
extend
(
maker
.
make
(
spec
))
scripts_to_generate
.
append
(
'pip%s = %s'
%
(
get_major_minor_version
(),
pip_script
)
)
# Delete any other versioned pip entry points
pip_ep
=
[
k
for
k
in
console
if
re
.
match
(
r
'pip(\d(\.\d)?)?$'
,
k
)]
for
k
in
pip_ep
:
...
...
@@ -572,13 +561,15 @@ if __name__ == '__main__':
easy_install_script
=
console
.
pop
(
'easy_install'
,
None
)
if
easy_install_script
:
if
"ENSUREPIP_OPTIONS"
not
in
os
.
environ
:
spec
=
'easy_install = '
+
easy_install_script
generated
.
extend
(
maker
.
make
(
spec
))
scripts_to_generate
.
append
(
'easy_install = '
+
easy_install_script
)
spec
=
'easy_install-%s = %s'
%
(
get_major_minor_version
(),
easy_install_script
,
scripts_to_generate
.
append
(
'easy_install-%s = %s'
%
(
get_major_minor_version
(),
easy_install_script
)
)
generated
.
extend
(
maker
.
make
(
spec
))
# Delete any other versioned easy_install entry points
easy_install_ep
=
[
k
for
k
in
console
if
re
.
match
(
r
'easy_install(-\d\.\d)?$'
,
k
)
...
...
@@ -587,25 +578,37 @@ if __name__ == '__main__':
del
console
[
k
]
# Generate the console and GUI entry points specified in the wheel
if
len
(
console
)
>
0
:
generated_console_scripts
=
maker
.
make_multiple
(
[
'%s = %s'
%
kv
for
kv
in
console
.
items
()]
)
generated
.
extend
(
generated_console_scripts
)
scripts_to_generate
.
extend
(
'%s = %s'
%
kv
for
kv
in
console
.
items
()
)
gui_scripts_to_generate
=
[
'%s = %s'
%
kv
for
kv
in
gui
.
items
()
]
generated_console_scripts
=
[]
# type: List[str]
if
warn_script_location
:
msg
=
message_about_scripts_not_on_PATH
(
generated_console_scripts
)
if
msg
is
not
None
:
logger
.
warning
(
msg
)
try
:
generated_console_scripts
=
maker
.
make_multiple
(
scripts_to_generate
)
generated
.
extend
(
generated_console_scripts
)
if
len
(
gui
)
>
0
:
generated
.
extend
(
maker
.
make_multiple
(
[
'%s = %s'
%
kv
for
kv
in
gui
.
items
()],
{
'gui'
:
True
}
)
maker
.
make_multiple
(
gui_scripts_to_generate
,
{
'gui'
:
True
})
)
except
MissingCallableSuffix
as
e
:
entry
=
e
.
args
[
0
]
raise
InstallationError
(
"Invalid script entry point: %s for req: %s - A callable "
"suffix is required. Cf https://packaging.python.org/en/"
"latest/distributing.html#console-scripts for more "
"information."
%
(
entry
,
req
)
)
if
warn_script_location
:
msg
=
message_about_scripts_not_on_PATH
(
generated_console_scripts
)
if
msg
is
not
None
:
logger
.
warning
(
msg
)
# Record pip as the installer
installer
=
os
.
path
.
join
(
info_dir
[
0
],
'INSTALLER'
)
temp_installer
=
os
.
path
.
join
(
info_dir
[
0
],
'INSTALLER.pip'
)
...
...
tests/unit/test_wheel.py
浏览文件 @
b0a7d2b5
...
...
@@ -15,6 +15,7 @@ from pip._internal.models.link import Link
from
pip._internal.req.req_install
import
InstallRequirement
from
pip._internal.utils.compat
import
WINDOWS
from
pip._internal.utils.misc
import
unpack_file
from
pip._internal.wheel
import
MissingCallableSuffix
,
_assert_valid_entrypoint
from
tests.lib
import
DATA_DIR
,
assert_paths_equal
...
...
@@ -265,6 +266,19 @@ def test_get_entrypoints(tmpdir, console_scripts):
)
def
test_assert_valid_entrypoint_ok
():
_assert_valid_entrypoint
(
"hello = hello:main"
)
@
pytest
.
mark
.
parametrize
(
"entrypoint"
,
[
"hello = hello"
,
"hello = hello:"
,
])
def
test_assert_valid_entrypoint_fail
(
entrypoint
):
with
pytest
.
raises
(
MissingCallableSuffix
):
_assert_valid_entrypoint
(
entrypoint
)
@
pytest
.
mark
.
parametrize
(
"outrows, expected"
,
[
([
(
''
,
''
,
'a'
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录