3.11 no longer builds with a configured empty prefix

未關閉
#101,668 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
c, python
領域
build-system

研究方向

使用 ./configure --prefix= 後執行 make 重現失敗,然後追蹤 Modules/getpath.py、Modules/getpath.c、Python/initconfig.c 和 Python/sysmodule.c 中的 prefix 值。將 C 到 Python 的轉換與 issue 中提到的早期行為進行比較。當 CPython 能在空的 prefix 下成功建置,且受影響的 prefix 屬性仍可使用時,即表示完成。

由索引模型根據 Issue 內容生成。

描述

build type-bug

Bug report

In 3.11 is not possible to build by running ./configure with an empty prefix:

./configure --prefix=

After such configuration, running make fails with something similar to the following:

./_bootstrap_python ./Programs/_freeze_module.py abc ./Lib/abc.py Python/frozen_modules/abc.h
Fatal Python error: init_import_site: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
  File "/home/etanol/Python-3.11.1/Lib/site.py", line 79, in <module>
    PREFIXES = [sys.prefix, sys.exec_prefix]
                ^^^^^^^^^^
AttributeError: module 'sys' has no attribute 'prefix'
Makefile:1200: recipe for target 'Python/frozen_modules/abc.h' failed

Possible explanation

The sys module takes attributes like sys.exec and sys.exec_prefix from the PyConfig structure. However, if any of those values is NULL, the attribute does not seem to be defined.

During path calculation, the result of evaluating (the frozen version of) getpath.py is copied back to PyConfig. But the prefix and similar fields are treated by converting None to NULL (from the C macro expansion).

The prefix indicated to ./configure is passed on when compiling getpath.c. But empty strings are converted to None. If the evaluation of (frozen) getpath.py assigns None to the prefix global variable (and similar) what gets transferred back to getpath.c ends up becoming NULL in PyConfig.

I think an empty prefix worked in 3.10, and earlier, because the transition from C compiler macro to Python value preserved empty strings. Empty C strings were converted to empty Python strings; but 3.11 converts empty C strings to None.

Considerations

Using dummy values for ./configure --prefix and then controlling installation target with make DESTDIR=... is a fairly common practice when creating binary packages. It's very convenient as a way to build software inside sandboxed environments.

However, it is certainly arguable that allowing for an empty prefix may not be of interest (it's just as common to run ./configure --prefix=/).

It is also beyond my understanding to determine if the fix should be about preserving empty strings in the C to Python conversion or perhaps the logic in getpath.py should be modified with a last resort check to avoid setting prefix (and similar) to None.

Your environment

  • CPython versions tested on: 3.11.1
  • Operating system and architecture: Ubuntu 18.04 x86-64
主要語言
Python
星號
77.2k
分支
36k
平均合併
1 天 9 小時
30 天內合併 PR
558

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

python/cpython 的其他 Issue

查看 python/cpython 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。