记录已安装发行版的直接 URL 来源#

本文档指定已安装发行版的 direct_url.json 文件,该文件位于 *.dist-info 目录中,用于记录发行版的直接 URL 来源。*.dist-info 目录的一般结构和用法在 记录已安装项目 中进行了描述。

规范#

当从指定直接 URL 引用(包括 VCS URL)的要求中安装发行版时,安装程序必须在 *.dist-info 目录中创建 direct_url.json 文件。

从其他类型的要求(即名称加版本规范)中安装发行版时,不得创建此文件。

此 JSON 文件必须是 UTF-8 编码的,RFC 8259 兼容的 直接 URL 数据结构 序列化。

注意

当请求的 URL 具有 file:// 方案并指向碰巧包含 VCS 签出的本地目录时,安装程序不得尝试推断任何 VCS 信息,因此不得在 direct_url.json 中输出任何与 VCS 相关的信息(例如 vcs_info)。

注意

作为一般规则,安装程序在生成 direct_url.json 时应尽可能保留在请求的 URL 中提供的信息。例如,应保留用户:密码环境变量,并且 requested_revision 应尽可能如实反映请求的 URL 中提供的修订版。但是,此信息已使用更精确的数据(例如 commit_id)进行了丰富

示例 pip 命令及其对 direct_url.json 的影响#

生成 direct_url.json 的命令

  • pip install https://example.com/app-1.0.tgz

  • pip install https://example.com/app-1.0.whl

  • pip install "app @ git+https://example.com/repo/app.git#subdirectory=setup"

  • pip install ./app

  • pip install file:///home/user/app

  • pip install --editable "app @ git+https://example.com/repo/app.git#subdirectory=setup"(在这种情况下,url 将为已克隆 git 存储库的本地目录,并且 dir_info 将显示 "editable": true,且不会设置任何 vcs_info

  • pip install -e ./app

不会生成 direct_url.json 的命令

  • pip install app

  • pip install app --no-index --find-links https://example.com/

历史记录#

  • 2020 年 3 月:此规范已通过 PEP 610 批准。