Commit graph

3 commits

Author SHA1 Message Date
Maxim Cournoyer 223cc96e5b
sitecustomize.py: Honor .pth files.
Fixes <https://issues.guix.gnu.org/52269>.

* gnu/packages/aux-files/python/sitecustomize.py: Use site.addsitedirs to add
the site directories; this takes care of the .pth files.  Make sure the added
items still appear before Python's own 'site-packages' directory.
2022-01-10 11:44:26 -05:00
Maxim Cournoyer 874188c0ab
aux-files: sitecustomize: Cleanup and add explanatory comments.
Fixes <https://issues.guix.gnu.org/50105>.

* gnu/packages/aux-files/python/sitecustomize.py: Add a comment explaining the
general idea, and use sys.prefix instead of sys.executable.

(major_minor): Use the unpacking operator (*) to provide the arguments.
(site_packages_prefix): Use os.path.join to form the path.
(python_site): Likewise.  Use sys.prefix instead of sys.executable.
(all_sites_raw): Split on os.path.pathsep.
(sys.path): Directly splice the result in the list.

Suggested-by: Hartmut Goebel <h.goebel@crazy-compilers.com>
Reported-by: Mathieu Othacehe <othacehe@gnu.org>
Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
2021-11-11 10:31:32 -05:00
Maxim Cournoyer cb72f9a773
gnu: python: Replace PYTHONPATH by GUIX_PYTHONPATH.
Using PYTHONPATH as a mean to discover the Python packages had the following
issues:

        1. It is not versioned, so different versions of Python would clash if
        installed in a shared profile.

        2. It would interfere with the host Python site on foreign
        distributions, sometimes preventing a a user to login their GDM
        session (!).

        3. It would take precedence over user installed Python packages
        installed through pip.

        4. It would leak into Python virtualenvs, which are supposed to create
        isolated Python environments.

This changes fixes the above issues by making use of a sitecustomize.py
module.  The newly introduced GUIX_PYTHONPATH environment variable is read
from the environment, filtered for the current Python version of the
interpreter, and spliced in 'sys.path' just before Python's own site location,
which provides the expected behavior.

* gnu/packages/aux-files/python/sitecustomize.py: New file.
* Makefile.am: Register it.
* gnu/packages/python.scm (customize-site)
(guix-pythonpath-search-path): New procedures.
(python-2.7)[phases]{install-sitecustomize.py}: New phase.
[native-inputs]{sitecustomize.py}: New input.
[native-search-paths]: Replace PYTHONPATH with GUIX_PYTHONPATH.
(python-3.9)[native-search-paths]: Likewise.
[phases]{install-sitecustomize}: Override with correct version.
[native-search-paths]: Replace PYTHONPATH with GUIX_PYTHONPATH.
* gnu/packages/commencement.scm (python-boot0):
[phases]{install-sitecustomize}: Likewise.
[native-inputs]{sitecustomize.py}: New input.
[native-search-paths]: Replace PYTHONPATH with GUIX_PYTHONPATH.
* guix/build/python-build-system.scm (site-packages): Do not add a trailing
'/'.

squash! gnu: python: Replace PYTHONPATH by GUIX_PYTHONPATH.
2021-02-01 11:53:42 -05:00