Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
Python_Packaging_Authority
pip
提交
e6b1070e
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,发现更多精彩内容 >>
提交
e6b1070e
编写于
6月 04, 2019
作者:
C
Chris Jerdonek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add normalize_version_info() with tests.
上级
107258da
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
4 deletion
+51
-4
src/pip/_internal/utils/misc.py
src/pip/_internal/utils/misc.py
+35
-2
tests/unit/test_utils.py
tests/unit/test_utils.py
+16
-2
未找到文件。
src/pip/_internal/utils/misc.py
浏览文件 @
e6b1070e
...
...
@@ -45,13 +45,23 @@ else:
if
MYPY_CHECK_RUNNING
:
from
typing
import
(
Optional
,
Tuple
,
Iterable
,
List
,
Match
,
Union
,
Any
,
Mapping
,
Text
,
AnyStr
,
Container
Any
,
AnyStr
,
Container
,
Iterable
,
List
,
Mapping
,
Match
,
Optional
,
Text
,
Union
,
)
from
pip._vendor.pkg_resources
import
Distribution
from
pip._internal.models.link
import
Link
from
pip._internal.utils.ui
import
SpinnerInterface
try
:
from
typing
import
cast
,
Tuple
VersionInfo
=
Tuple
[
int
,
int
,
int
]
except
ImportError
:
# typing's cast() isn't supported in code comments, so we need to
# define a dummy, no-op version.
def
cast
(
typ
,
val
):
return
val
VersionInfo
=
None
__all__
=
[
'rmtree'
,
'display_path'
,
'backup_dir'
,
'ask'
,
'splitext'
,
...
...
@@ -94,6 +104,29 @@ except ImportError:
logger
.
debug
(
'lzma module is not available'
)
def
normalize_version_info
(
py_version_info
):
# type: (Optional[Tuple[int, ...]]) -> Optional[Tuple[int, int, int]]
"""
Convert a tuple of ints representing a Python version to one of length
three.
:param py_version_info: a tuple of ints representing a Python version,
or None to specify no version. The tuple can have any length.
:return: a tuple of length three if `py_version_info` is non-None.
Otherwise, return `py_version_info` unchanged (i.e. None).
"""
if
py_version_info
is
None
:
return
None
if
len
(
py_version_info
)
<
3
:
py_version_info
+=
(
3
-
len
(
py_version_info
))
*
(
0
,)
elif
len
(
py_version_info
)
>
3
:
py_version_info
=
py_version_info
[:
3
]
return
cast
(
VersionInfo
,
py_version_info
)
def
ensure_dir
(
path
):
# type: (AnyStr) -> None
"""os.path.makedirs without EEXIST."""
...
...
tests/unit/test_utils.py
浏览文件 @
e6b1070e
...
...
@@ -29,8 +29,9 @@ from pip._internal.utils.glibc import check_glibc_version
from
pip._internal.utils.hashes
import
Hashes
,
MissingHashes
from
pip._internal.utils.misc
import
(
call_subprocess
,
egg_link_path
,
ensure_dir
,
format_command_args
,
get_installed_distributions
,
get_prog
,
normalize_path
,
path_to_url
,
redact_netloc
,
redact_password_from_url
,
remove_auth_from_url
,
rmtree
,
get_installed_distributions
,
get_prog
,
normalize_path
,
normalize_version_info
,
path_to_url
,
redact_netloc
,
redact_password_from_url
,
remove_auth_from_url
,
rmtree
,
split_auth_from_netloc
,
split_auth_netloc_from_url
,
untar_file
,
unzip_file
,
)
from
pip._internal.utils.temp_dir
import
AdjacentTempDirectory
,
TempDirectory
...
...
@@ -700,6 +701,19 @@ class TestGlibc(object):
assert
False
@
pytest
.
mark
.
parametrize
(
'version_info, expected'
,
[
(
None
,
None
),
((),
(
0
,
0
,
0
)),
((
3
,
),
(
3
,
0
,
0
)),
((
3
,
6
),
(
3
,
6
,
0
)),
((
3
,
6
,
2
),
(
3
,
6
,
2
)),
((
3
,
6
,
2
,
4
),
(
3
,
6
,
2
)),
])
def
test_normalize_version_info
(
version_info
,
expected
):
actual
=
normalize_version_info
(
version_info
)
assert
actual
==
expected
class
TestGetProg
(
object
):
@
pytest
.
mark
.
parametrize
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录