-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-75229: make ensurepip honour value of --prefix option #135488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
When cross-compiling, the local Python interpreter that is used to run `ensurepip` may not have the same value of `sys.prefix` as the value of the 'prefix' variable that is set in the Makefile. With the following values used to install Python locally for a later copy to the files hierarchy owned by the 'termux' application on an Android device: DESTDIR=/tmp/android prefix=/data/data/com.termux/files/usr/local 'make install' causes ensurepip to install pip in $(DESTDIR)/usr/local instead of the expected $(DESTDIR)/$(prefix) where is installed the standard library. The attached patch fixes the problem. The patch was implemented assuming that pip uses distutils for the installation (note that setup.py also uses the --prefix option in the Makefile), but I know nothing about pip so forgive me if the patch is wrong and please just assume it is just a way to demonstrate the problem. Fixes: python#75229 Fixes: https://bugs.python.org/issue31046 Co-authored-by: Pradyun Gedam <pradyunsg@gmail.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com> Co-authored-by: Zackery Spytz <zspytz@gmail.com> References: python#17634 Signed-off-by: Matěj Cepl <mcepl@cepl.eu>
When using `python -m ensurepip` with the `--root` option for staged installations, the generated pip script contained an incorrect shebang that pointed into the staging directory. This made the installation unusable once the staging directory was removed. This commit fixes the issue by using the internal pip `--executable` option to force the shebang to point to the correct, final interpreter path. It also corrects related pathing issues: - Removes the check that incorrectly disallowed using --root and --prefix together. - Defaults the installation prefix to `/` when --root is used alone, ensuring installation occurs at the base of the staging directory. References: python#17634 (comment) Signed-off-by: Matěj Cepl <mcepl@cepl.eu>
7b297a2
to
4b24401
Compare
Has this PR addressed the various concerns raised in #17634 or is it simply a copy of that PR, reopened by a new author? I'm concerned by the comment in the OP here:
I'm not sure who is expected to take responsibility for the correctness of this PR in the light of this statement? |
4b24401
to
5c4b65b
Compare
On Fri Jun 13, 2025 at 11:29 PM CEST, Paul Moore wrote:
Has this PR addressed the various concerns raised in #17634 or is it simply a copy of that PR, reopened by a new author?
I believe I have addressed those concerns in the second commit (the first comments is this PR squashed).
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the work improving this PR.
I've noticed two small issues, could you take them into consideration?
PS: the issue in Makefile.pre.in
is the reason a lot of tests are failing
# Handle installation paths. | ||
# If --root is given but not --prefix, we default to a prefix of "/" | ||
# so that the install happens at the root of the --root directory. | ||
# Otherwise, pip would use the configured sys.prefix, e.g. | ||
# /usr/local, and install into ${root}/usr/local/. | ||
effective_prefix = prefix | ||
if root and not prefix: | ||
effective_prefix = "/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usual use cases for ensurepip
are:
- installing pip on the current(host) system ->
sys.prefix
is the right prefix to use - installing pip in a packaging directory -> the Makefile always provides the prefix (given
Makefile.pre.in
is patched correctly by this PR)
Adding this override of the default prefix
would break the first use case without clear benefit to the second.
@@ -2336,7 +2336,7 @@ install: @FRAMEWORKINSTALLFIRST@ @INSTALLTARGETS@ @FRAMEWORKINSTALLLAST@ | |||
install|*) ensurepip="" ;; \ | |||
esac; \ | |||
$(RUNSHARED) $(PYTHON_FOR_BUILD) -m ensurepip \ | |||
$$ensurepip --root=$(DESTDIR)/ ; \ | |||
$$ensurepip --prefix=$(prefix) ; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We must preserve the --root
argument here.
$$ensurepip --prefix=$(prefix) ; \ | |
$$ensurepip --root=$(DESTDIR)/ --prefix=$(prefix) ; \ |
@@ -2347,7 +2347,7 @@ altinstall: commoninstall | |||
install|*) ensurepip="--altinstall" ;; \ | |||
esac; \ | |||
$(RUNSHARED) $(PYTHON_FOR_BUILD) -m ensurepip \ | |||
$$ensurepip --root=$(DESTDIR)/ ; \ | |||
$$ensurepip --prefix=$(prefix) ; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and also here
$$ensurepip --prefix=$(prefix) ; \ | |
$$ensurepip --root=$(DESTDIR)/ --prefix=$(prefix) ; \ |
When cross-compiling, the local Python interpreter that is used to run
ensurepip
may not have the same value ofsys.prefix
as the value of the 'prefix' variable that is set in the Makefile.With the following values used to install Python locally for a later copy to the files hierarchy owned by the 'termux' application on an Android device:
'make install' causes ensurepip to install pip in
$(DESTDIR)/usr/local
instead of the expected$(DESTDIR)/$(prefix)
where is installed the standard library.The attached patch fixes the problem. The patch was implemented assuming that pip uses
distutils
for the installation (note that setup.py also uses the --prefix option in the Makefile), but I know nothing about pip so forgive me if the patch is wrong and please just assume it is just a way to demonstrate the problem.Fixes: #75229
Co-authored-by: Pradyun Gedam pradyunsg@gmail.com
Co-authored-by: Erlend E. Aasland erlend.aasland@protonmail.com
Co-authored-by: Zackery Spytz zspytz@gmail.com
References: #17634
Signed-off-by: Matěj Cepl mcepl@cepl.eu