Bug 1225660 - python311-pip package installs in /usr/lib by default
Summary: python311-pip package installs in /usr/lib by default
Status: IN_PROGRESS
Alias: None
Product: openSUSE Tumbleweed
Classification: openSUSE
Component: Python (show other bugs)
Version: Current
Hardware: Other Other
: P5 - None : Normal (vote)
Target Milestone: ---
Assignee: Daniel Garcia
QA Contact: E-mail List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-30 10:46 UTC by Daniel Garcia
Modified: 2024-07-10 09:20 UTC (History)
1 user (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Garcia 2024-05-30 10:46:16 UTC
In tumbleweed installing a package with pip3 as root installs in the system path /usr/lib. It should install in /usr/local/lib instead.

Possibly related to this patch:
https://build.opensuse.org/projects/devel:languages:python:Factory/packages/python311/files/F00251-change-user-install-location.patch?expand=1
Comment 1 Daniel Garcia 2024-06-04 06:20:16 UTC
I've been working in an initial implementation of this with two patches, one for the python interpreter and another one for the python-pip:

 * python311: https://build.opensuse.org/projects/home:dgarcia:usr-local/packages/python311/files/bsc1225660-add-local-posix-path-scheme.patch?expand=1
 * python-pip: https://build.opensuse.org/projects/home:dgarcia:usr-local/packages/python-pip/files/install-usr-local.patch?expand=1

With this patch, pip installs by default in "/usr/local/", and the usage to create rpm packages works as expected installing in "/usr/".

In any case, the usage of pip with installed system packages will lead to override or remove installed files by packages, because when removing, pip looks for the python module in any installation path. But that's how pip works, and if the user mess around with the system as root, we can't prevent system breakage.
Comment 2 Daniel Garcia 2024-06-04 06:55:12 UTC
(In reply to Daniel Garcia from comment #1)
> I've been working in an initial implementation of this with two patches, one
> for the python interpreter and another one for the python-pip
> 

Maybe it's easier to do it just in the pip code, using the "prefix" argument:

   # pip installations by default to local
   if prefix is None and scheme_name == "posix_prefix" and "RPM_BUILD_ROOT" not in os.environ:
       prefix = "/usr/local"

https://build.opensuse.org/projects/home:dgarcia:usr-local/packages/python-pip/files/install-usr-local.patch?expand=1
Comment 3 Matej Cepl 2024-06-04 07:11:54 UTC
(In reply to Daniel Garcia from comment #1)
> I've been working in an initial implementation of this with two patches, one
> for the python interpreter and another one for the python-pip:
> 
>  * python311:
> https://build.opensuse.org/projects/home:dgarcia:usr-local/packages/
> python311/files/bsc1225660-add-local-posix-path-scheme.patch?expand=1

Is this supposed to replace https://build.opensuse.org/projects/home:dgarcia:usr-local/packages/python311/files/F00251-change-user-install-location.patch?expand=1  or is it building on the top of it?
Comment 4 Daniel Garcia 2024-06-04 07:45:18 UTC
(In reply to Matej Cepl from comment #3)
> (In reply to Daniel Garcia from comment #1)
> > I've been working in an initial implementation of this with two patches, one
> > for the python interpreter and another one for the python-pip:
> > 
> >  * python311:
> > https://build.opensuse.org/projects/home:dgarcia:usr-local/packages/
> > python311/files/bsc1225660-add-local-posix-path-scheme.patch?expand=1
> 
> Is this supposed to replace
> https://build.opensuse.org/projects/home:dgarcia:usr-local/packages/
> python311/files/F00251-change-user-install-location.patch?expand=1  or is it
> building on the top of it?

It's on top of it. This is just for the "pip" installation. The F00251 is for packages installed using distutils directly.

We don't have this patch in python312 because distutils was removed from cpython now, and now the way to install packages is using pip, so I think that patching pip could be enough.

Maybe it could be also good to patch _distutils in the python-setuptools package.
Comment 5 Daniel Garcia 2024-06-05 11:16:43 UTC
Fedora does all the changes in cpython with a patch. I'm testing this patch with our python311 [1] package and it requires also a change in python-rpm-macros [2].

[1] https://build.opensuse.org/projects/home:dgarcia:usr-local-cpython/packages/python311/files/F00251-change-user-install-location.patch?expand=1
[2] https://github.com/openSUSE/python-rpm-macros/commit/6a2a3e37ecbd86c53662408a3448c56c86de8662
Comment 6 Daniel Garcia 2024-06-17 07:16:46 UTC
Update of python-rpm-macros to support the patch on cpython on its way to factory:
 * https://build.opensuse.org/request/show/1181251
Comment 7 Daniel Garcia 2024-07-02 12:03:58 UTC
I've been testing and this is not needed for python38 and python39. For the rest of python interpreters I've just updated the patch (get it back for python312) and, with this, it's working as expected, installing in /usr/local when using pip outside of rpm build environment.

 * https://build.opensuse.org/request/show/1184844
 * https://build.opensuse.org/request/show/1184845
 * https://build.opensuse.org/request/show/1184846
Comment 8 OBSbugzilla Bot 2024-07-10 06:25:02 UTC
This is an autogenerated message for OBS integration:
This bug (1225660) was mentioned in
https://build.opensuse.org/request/show/1186495 Factory / python312