Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
Python_Packaging_Authority
pip
提交
bd9bcef8
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 搜索 >>
提交
bd9bcef8
编写于
4月 19, 2022
作者:
T
Tzu-ping Chung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enable importlib.metadata backend on Python 3.11
上级
e195f7bd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
34 addition
and
3 deletion
+34
-3
.github/workflows/ci.yml
.github/workflows/ci.yml
+2
-2
news/11044.process.rst
news/11044.process.rst
+4
-0
src/pip/_internal/metadata/__init__.py
src/pip/_internal/metadata/__init__.py
+28
-1
未找到文件。
.github/workflows/ci.yml
浏览文件 @
bd9bcef8
...
...
@@ -219,11 +219,12 @@ jobs:
env
:
TEMP
:
"
R:
\\
Temp"
# TODO: Remove this when we add Python 3.11 to CI.
tests-importlib-metadata
:
name
:
tests for importlib.metadata backend
runs-on
:
ubuntu-latest
env
:
_PIP_
METADATA_BACKEND_IMPORTLIB
:
egg-compat
_PIP_
USE_IMPORTLIB_METADATA
:
'
true'
needs
:
[
pre-commit
,
packaging
,
determine-changes
]
if
:
>-
...
...
@@ -241,7 +242,6 @@ jobs:
-
run
:
pip install nox 'virtualenv<20'
# Main check
-
name
:
Run unit tests
run
:
>-
nox -s test-3.10 --
...
...
news/11044.process.rst
0 → 100644
浏览文件 @
bd9bcef8
Enable the ``importlib.metadata`` metadata implementation by default on
Python 3.11 (or later). The environment variable ``_PIP_USE_IMPORTLIB_METADATA``
can still be used to enable the implementation on 3.10 and earlier, or disable
it on 3.11 (by setting it to ``0`` or ``false``).
src/pip/_internal/metadata/__init__.py
浏览文件 @
bd9bcef8
import
contextlib
import
functools
import
os
import
sys
from
typing
import
TYPE_CHECKING
,
List
,
Optional
,
Type
,
cast
from
pip._internal.utils.misc
import
strtobool
from
.base
import
BaseDistribution
,
BaseEnvironment
,
FilesystemWheel
,
MemoryWheel
,
Wheel
if
TYPE_CHECKING
:
...
...
@@ -22,6 +26,29 @@ __all__ = [
]
def
_should_use_importlib_metadata
()
->
bool
:
"""Whether to use the ``importlib.metadata`` or ``pkg_resources`` backend.
By default, pip uses ``importlib.metadata`` on Python 3.11+, and
``pkg_resourcess`` otherwise. This can be overriden by a couple of ways:
* If environment variable ``_PIP_USE_IMPORTLIB_METADATA`` is set, it
dictates whether ``importlib.metadata`` is used, regardless of Python
version.
* On Python 3.11+, Python distributors can patch ``importlib.metadata``
to add a global constant ``_PIP_USE_IMPORTLIB_METADATA = False``. This
makes pip use ``pkg_resources`` (unless the user set the aforementioned
environment variable to *True*).
"""
with
contextlib
.
suppress
(
KeyError
,
ValueError
):
return
bool
(
strtobool
(
os
.
environ
[
"_PIP_USE_IMPORTLIB_METADATA"
]))
if
sys
.
version_info
<
(
3
,
11
):
return
False
import
importlib.metadata
return
bool
(
getattr
(
importlib
.
metadata
,
"_PIP_USE_IMPORTLIB_METADATA"
,
True
))
class
Backend
(
Protocol
):
Distribution
:
Type
[
BaseDistribution
]
Environment
:
Type
[
BaseEnvironment
]
...
...
@@ -29,7 +56,7 @@ class Backend(Protocol):
@
functools
.
lru_cache
(
maxsize
=
None
)
def
select_backend
()
->
Backend
:
if
os
.
environ
.
get
(
"_PIP_METADATA_BACKEND_IMPORTLIB"
):
if
_should_use_importlib_metadata
(
):
from
.
import
importlib
return
cast
(
Backend
,
importlib
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录