Following system colour scheme - Python 增强提案 Selected dark colour scheme - Python 增强提案 Selected light colour scheme - Python 增强提案

Python增强提案

PEP 739 – Python 安装构建细节的静态描述文件

作者:
Filipe Laíns <lains at riseup.net>
PEP委托人:
Paul Moore <p.f.moore at gmail.com>
讨论列表:
Discourse 帖子
状态:
草案
类型:
标准跟踪
主题:
打包
创建日期:
2023年12月19日
Python版本:
3.14

目录

摘要

引入一种标准格式,用于存储 Python 安装构建细节的静态描述文件。

基本原理

在检查 Python 安装时,运行代码通常是不希望的或不可能的。拥有一个静态描述文件使得无需运行解释器即可获得各种 Python 构建细节。

这对于交叉编译、Python 启动器等用例很有帮助。

范围

本 PEP 定义了描述文件格式以及放置它的标准位置。

文件位置

如果可能,Python 安装应将静态描述文件安装在标准库目录中,文件名为 build-details.json(例如 /usr/lib/python3.14/build-details.json)。

重要

鉴于可能存在技术挑战,如果不可行,则 Python 实现不需要提供此文件。在这种情况下,它们可以选择以其他方式提供它。

注意

尽管此处指定了标准位置,但这并不阻止另外在其他位置以及使用其他名称提供该文件。实际上,PEP 作者预计未来的 PEP 将定义其他安装此文件的位置,以提高可发现性。

格式

格式规范由下面提供的 JSON 模式定义定义,此处以人类可读的格式呈现。

$schema https://json-schema.fullstack.org.cn/draft/2020-12/schema
$id https://github.com/python/peps/blob/main/peps/pep-0739/python-build-info-v1.schema.json
标题 Python 安装构建细节的静态描述文件
类型 对象
其他属性 不允许

schema_version

类型 string(常量 - 1)
描述 模式版本。

这是一个常量值,在使用此处描述的模式时,**必须**为 1。此模式的未来迭代**必须**更新此值。

必需

base_prefix

类型 字符串
描述 Python 安装的基本前缀。

可以是绝对路径,也可以是相对于包含此文件目录的相对路径。

示例 /usr../..等。
必需

平台

类型 字符串
描述 系统平台字符串。

此字段**应该**等效于 sysconfig.get_platform()

示例
  • linux-x86_64
  • 等等。
必需

语言

类型 对象
描述 包含与 Python 语言规范相关的详细信息的对象。

除了必需的键之外,实现还可以选择包含具有实现特定详细信息的其他键。

必需
其他属性 不允许

language.version

类型 字符串
描述 Python 语言版本的字符串表示 - 一个仅包含组件的版本字符串。

此字段**应该**等效于 sysconfig.get_python_version()

示例 3.14等。
必需

实现

类型 对象
描述 包含与 Python 实现相关的详细信息的对象。

此部分**应该**等效于 sys.implementation。它遵循 PEP 421 中定义的规范,这意味着除了必需的键之外,还可以存在实现特定的键,但必须以下划线为前缀。

必需
其他属性 允许

implementation.name

类型 字符串
描述 Python 实现的小写名称。
示例 cpythonpypy等。
必需

implementation.version

类型 对象
描述 sys.version_info 格式的对象,包含实现版本。
示例
  • {'major': 3, 'minor': 13, 'micro': 1, 'releaselevel': 'final', 'serial': 0}
  • {'major': 7, 'minor': 3, 'micro': 16, 'releaselevel': 'final', 'serial': 0}
  • 等等。
必需
其他属性 不允许
implementation.version.major
类型 数字
必需
implementation.version.minor
类型 数字
必需
implementation.version.micro
类型 数字
必需
implementation.version.releaselevel
类型 string(枚举 - alphabetacandidatefinal)
必需
implementation.version.serial
类型 数字
必需

解释器

类型 对象
描述 包含与 Python 解释器相关的详细信息的对象。

如果 Python 安装提供了解释器二进制文件,则此部分**必须**存在,否则此部分将不存在。

必需
其他属性 不允许

interpreter.path

类型 字符串
描述 Python 解释器的路径。可以是绝对路径,也可以是相对于 base_prefix 键中定义的路径的相对路径。
示例
  • /usr/bin/python
  • bin/python
  • 等等。
必需

ABI

类型 对象
描述 包含与 ABI 相关的详细信息的对象。
必需
其他属性 不允许

abi.flags

类型 数组
描述 构建配置标志,用于计算扩展后缀。

标志**必须**按照它们出现在扩展后缀中的顺序定义。

示例 ['t', 'd']等。
必需

abi.extension_suffix

类型 字符串
描述 针对当前实现版本构建的扩展使用的后缀。

如果 Python 实现支持扩展,则此字段**必须**存在,否则此条目将不存在。

示例
  • .cpython-314-x86_64-linux-gnu.so
  • 等等。
必需

abi.stable_abi_suffix

类型 字符串
描述 针对稳定 ABI 构建的扩展使用的后缀。

如果 Python 实现具有稳定的 ABI 扩展后缀,则此字段**必须**存在,否则此条目将不存在。

示例 .abi3.so等。
必需

后缀

类型 对象
描述 按类型分组的有效模块后缀。

此部分**应该**等效于 importlib.machinery.*_SUFFIXES 属性(如果实现提供了此类后缀)。但是,如果 Python 实现没有提供任何属性指定的类型后缀,则不需要存在等效的子部分。此外,如果 Python 实现提供了 importlib.machinery 模块上列出的以外的其他扩展类型,则**可以**为它们添加子部分。

示例
  • {'source': ['.py'], 'bytecode': ['.pyc'], 'optimized_bytecode': ['.pyc'], 'debug_bytecode': ['.pyc'], 'extensions': ['.cpython-313-x86_64-linux-gnu.so', '.abi3.so', '.so']}
  • 等等。
必需
其他属性 允许

libpython

类型 对象
描述 包含与 libpython 库相关的详细信息的对象。

如果 Python 安装提供了 libpython 库,则此部分**必须**存在,否则此部分将不存在。

必需
其他属性 不允许

libpython.dynamic

类型 字符串
描述 动态 libpython 库的路径。可以是绝对路径,也可以是相对于 base_prefix 键中定义的路径的相对路径。

如果 Python 安装提供了动态 libpython 库,则此字段**必须**存在,否则此条目将不存在。

示例
  • /usr/lib/libpython3.14.so.1.0
  • lib/libpython3.14.so.1.0
  • 等等。
必需

libpython.static

类型 字符串
描述 静态 libpython 库的路径。可以是绝对路径,也可以是相对于 base_prefix 键中定义的路径的相对路径。

如果 Python 安装提供了静态 libpython 库,则此字段**必须**存在,否则此条目将不存在。

示例
  • /usr/lib/python3.14/config-3.14-x86_64-linux-gnu/libpython3.14.a
  • lib/python3.14/config-3.14-x86_64-linux-gnu/libpython3.14.a
  • 等等。
必需

C API

类型 对象
描述 包含与 Python C API 相关的详细信息的对象(如果可用)。

如果 Python 实现提供了 C API,则此部分**必须**存在,否则此部分将不存在。

必需
其他属性 不允许

c_api.headers

类型 字符串
描述 C API 头文件的路径。可以是绝对路径,也可以是相对于 base_prefix 键中定义的路径的相对路径。
示例
  • /usr/include/python3.14
  • include/python3.14
  • 等等。
必需

c_api.pkgconfig_path

类型 字符串
描述 pkg-config 定义文件的路径。可以是绝对路径,也可以是相对于 base_prefix 键中定义的路径的相对路径。

如果 Python 实现为 C API 提供了 pkg-config 定义文件,则此字段**必须**存在,否则此部分将不存在。

示例
  • /usr/lib/pkgconfig
  • lib/pkgconfig
  • 等等。
必需

任意数据

类型 对象
描述 包含额外任意数据的对象。

这旨在用作一个备用方案,以包含此规范未涵盖的任何相关数据。实现可以选择在此部分中提供哪些数据。

必需
其他属性 允许

示例

 1{
 2  "schema_version": "1",
 3  "base_prefix": "/usr",
 4  "platform": "linux-x86_64",
 5  "language": {
 6    "version": "3.14"
 7  },
 8  "implementation": {
 9    "name": "cpython",
10    "version": {
11      "major": 3,
12      "minor": 14,
13      "micro": 0,
14      "releaselevel": "alpha",
15      "serial": 0
16    },
17    "hexversion": 51249312,
18    "cache_tag": "cpython-314",
19    "_multiarch": "x86_64-linux-gnu"
20  },
21  "interpreter": {
22    "path": "/usr/bin/python"
23  },
24  "abi": {
25    "flags": ["t", "d"],
26    "extension_suffix": ".cpython-314-x86_64-linux-gnu.so",
27    "stable_abi_suffix": ".abi3.so"
28  },
29  "suffixes": {
30    "source": [".py"],
31    "bytecode": [".pyc"],
32    "optimized_bytecode": [".pyc"],
33    "debug_bytecode": [".pyc"],
34    "extensions": [".cpython-314-x86_64-linux-gnu.so", ".abi3.so", ".so"]
35  },
36  "libpython": {
37    "dynamic": "/usr/lib/libpython3.14.so.1.0",
38    "static": "/usr/lib/python3.14/config-3.14-x86_64-linux-gnu/libpython3.14.a",
39    "link_to_libpython": true
40  },
41  "c_api": {
42    "headers": "/usr/include/python3.14",
43    "pkgconfig_path": "/usr/lib/pkgconfig"
44  }
45}

JSON模式

  1{
  2  "$schema": "https://json-schema.fullstack.org.cn/draft/2020-12/schema",
  3  "$id": "https://github.com/python/peps/blob/main/peps/pep-0739/python-build-info-v1.schema.json",
  4  "type": "object",
  5  "title": "Static description file for the build details of Python installations",
  6  "required": [
  7    "schema_version",
  8    "platform",
  9    "language",
 10    "implementation"
 11  ],
 12  "additionalProperties": false,
 13  "properties": {
 14    "schema_version": {
 15      "type": "string",
 16      "description": "Schema version.\n\nThis is a constant value and MUST be ``1``, when using the schema described here. Future iterations of this schema MUST update this value.",
 17      "const": "1"
 18    },
 19    "base_prefix": {
 20      "type": "string",
 21      "description": "Base prefix of the Python installation.\n\nEither an absolute path, or a relative path to directory where this file is contained.",
 22      "examples": [
 23        "/usr",
 24        "../.."
 25      ]
 26    },
 27    "platform": {
 28      "type": "string",
 29      "description": "System platform string.\n\nThis field SHOULD be equivalent to ``sysconfig.get_platform()``.",
 30      "examples": [
 31        "linux-x86_64"
 32      ]
 33    },
 34    "language": {
 35      "type": "object",
 36      "description": "Object containing details related to the Python language specification.\n\nIn addition to the required keys, implementations may choose to include extra keys with implementation-specific details.",
 37      "required": [
 38        "version"
 39      ],
 40      "additionalProperties": false,
 41      "properties": {
 42        "version": {
 43          "type": "string",
 44          "description": "String representation the Python language version — a version string consisting only of the *major* and *minor* components.\n\nThis field SHOULD be equivalent to ``sysconfig.get_python_version()``.",
 45          "examples": ["3.14"]
 46        }
 47      }
 48    },
 49    "implementation": {
 50      "type": "object",
 51      "description": "Object containing details related to Python implementation.\n\nThis section SHOULD be equivalent to :py:data:`sys.implementation`. It follows specification defined in PEP 421, meaning that on top of the required keys, implementation-specific keys can also exist, but must be prefixed with an underscore.",
 52      "required": [
 53        "name",
 54        "version",
 55        "hexversion",
 56        "cache_tag"
 57      ],
 58      "additionalProperties": true,
 59      "properties": {
 60        "name": {
 61          "type": "string",
 62          "description": "Lower-case name of the Python implementation.",
 63          "examples": ["cpython", "pypy"]
 64        },
 65        "version": {
 66          "type": "object",
 67          "description": "Object in the format of :py:data:`sys.version_info`, containing the implementation version.",
 68          "required": ["major", "minor", "micro", "releaselevel", "serial"],
 69          "additionalProperties": false,
 70          "examples": [
 71            {
 72              "major": 3,
 73              "minor": 13,
 74              "micro": 1,
 75              "releaselevel": "final",
 76              "serial": 0
 77            },
 78            {
 79              "major": 7,
 80              "minor": 3,
 81              "micro": 16,
 82              "releaselevel": "final",
 83              "serial": 0
 84            }
 85          ],
 86          "properties": {
 87            "major": {
 88              "type": "number"
 89            },
 90            "minor": {
 91              "type": "number"
 92            },
 93            "micro": {
 94              "type": "number"
 95            },
 96            "releaselevel": {
 97              "type": "string",
 98              "enum": ["alpha", "beta", "candidate", "final"]
 99            },
100            "serial": {
101              "type": "number"
102            }
103          }
104        }
105      }
106    },
107    "interpreter": {
108      "type": "object",
109      "description": "Object containing details Python interpreter.\n\nThis section MUST be present if the Python installation provides an interpreter binary, otherwise this section will be missing.",
110      "required": [
111        "path"
112      ],
113      "additionalProperties": false,
114      "properties": {
115        "path": {
116          "type": "string",
117          "description": "The path to the Python interprer. Either an absolute path, or a relative path to the path defined in the ``base_prefix`` key.",
118          "examples": [
119            "/usr/bin/python",
120            "bin/python"
121          ]
122        }
123      }
124    },
125    "abi": {
126      "type": "object",
127      "description": "Object containing details related to ABI.",
128      "required": [
129        "flags",
130        "extension_suffix"
131      ],
132      "additionalProperties": false,
133      "properties": {
134        "flags": {
135          "type": "array",
136          "description": "Build configuration flags, used to calculate the extension suffix.\n\nThe flags MUST be defined in the order they appear on the extension suffix.",
137          "additionalProperties": true,
138          "examples": [
139            ["t", "d"]
140          ]
141        },
142        "extension_suffix": {
143          "type": "string",
144          "description": "Suffix used for extensions built against the current implementation version.\n\nThis field MUST be present if the Python implementation supports extensions, otherwise this entry will be missing.",
145          "examples": [
146            ".cpython-314-x86_64-linux-gnu.so"
147          ]
148        },
149        "stable_abi_suffix": {
150          "type": "string",
151          "description": "Suffix used for extensions built against the stable ABI.\n\nThis field MUST be present if the Python implementation has a stable ABI extension suffix, otherwise this entry will be missing.",
152          "examples": [
153            ".abi3.so"
154          ]
155        }
156      }
157    },
158    "suffixes": {
159      "type": "object",
160      "description": "Valid module suffixes grouped by type.\n\nThis section SHOULD be equivalent to the ``importlib.machinery.*_SUFFIXES`` attributes, if the implementation provides such suffixes. However, if the Python implementation does not provide suffixes of the kind specified by any of the attributes, the equivalent sub-section is not required to be present. Additionally, if a Python implementation provides extension kinds other than the ones listed on ``importlib.machinery`` module, they MAY add a sub-section for them.",
161      "examples": [
162        {
163          "source": [".py"],
164          "bytecode": [".pyc"],
165          "optimized_bytecode": [".pyc"],
166          "debug_bytecode": [".pyc"],
167          "extensions": [".cpython-313-x86_64-linux-gnu.so", ".abi3.so", ".so"]
168        }
169      ]
170    },
171    "libpython": {
172      "type": "object",
173      "description": "Object containing details related to the ``libpython`` library.\n\nThis section MUST by present if Python installation provides a ``libpython`` library, otherwise this section will be missing.",
174      "additionalProperties": false,
175      "properties": {
176        "dynamic": {
177          "type": "string",
178          "description": "The path to the dynamic ``libpython`` library. Either an absolute path, or a relative path to the path defined in the ``base_prefix`` key.\n\nThis field MUST be present if the Python installation provides a dynamic ``libpython`` library, otherwise this entry will be missing.",
179          "examples": [
180            "/usr/lib/libpython3.14.so.1.0",
181            "lib/libpython3.14.so.1.0"
182          ]
183        },
184        "static": {
185          "type": "string",
186          "description": "The path to the static ``libpython`` library. Either an absolute path, or a relative path to the path defined in the ``base_prefix`` key.\n\nThis field MUST be present if the Python installation provides a static ``libpython`` library, otherwise this entry will be missing.",
187          "examples": [
188            "/usr/lib/python3.14/config-3.14-x86_64-linux-gnu/libpython3.14.a",
189            "lib/python3.14/config-3.14-x86_64-linux-gnu/libpython3.14.a"
190          ]
191        },
192        "link_to_libpython": {
193          "type": "boolean",
194          "description": "Should extensions built against a dynamic ``libpython`` link to it?\n\nThis field MUST be present if the Python installation provides a dynamic ``libpython`` library, otherwise this entry will be missing."
195        }
196      }
197    },
198    "c_api": {
199      "type": "object",
200      "description": "Object containing details related to the Python C API, if available.\n\nThis section MUST be present if the Python implementation provides a C API, otherwise this section will be missing.",
201      "required": [
202        "headers"
203      ],
204      "additionalProperties": false,
205      "properties": {
206        "headers": {
207          "type": "string",
208          "description": "The path to the C API headers. Either an absolute path, or a relative path to the path defined in the ``base_prefix`` key.",
209          "examples": [
210            "/usr/include/python3.14",
211            "include/python3.14"
212          ]
213        },
214        "pkgconfig_path": {
215          "type": "string",
216          "description": "The path to the pkg-config definition files. Either an absolute path, or a relative path to the path defined in the ``base_prefix`` key.\n\nThis field MUST be present if the Python implementation provides pkg-config definition files for the C API, otherwise this section will be missing.",
217          "examples": [
218            "/usr/lib/pkgconfig",
219            "lib/pkgconfig"
220          ]
221        }
222      }
223    },
224    "arbitrary_data": {
225      "type": "object",
226      "description": "Object containing extra arbitrary data.\n\nThis is meant to be used as an escape-hatch, to include any relevant data that is not covered by this specification. Implamentations may choose what data to provide in this section.",
227      "additionalProperties": true
228    }
229  }
230}

被拒绝的想法

扩展更大的范围

在本 PEP 的讨论中,主要请求之一是包含其他类型的信息,例如 site-packages 路径。PEP 作者认为,有关 Python 环境的信息应由单独的文件提供,在构建细节(在任何解释器实例中都应该是不变的)和可能发生变化的细节(如环境细节)之间创建清晰的分隔。


来源:https://github.com/python/peps/blob/main/peps/pep-0739.rst

上次修改时间:2024-09-12 02:43:59 GMT