python tools should not add user's site directory
I came across a system where the user's local python lib contained a module called
pkg at a higher version than the system's IPS
When building gate, package validation failed with:
Traceback (most recent call last): File "/data/omnios-build/omniosorg/bloody/illumos/usr/src/tools/proto/root_i386-nd/opt/onbld/bin/validate_pkg", line 41, in <module> from pkg import actions ImportError: cannot import name 'actions' from 'pkg' (/data/omnios-build/.local/lib/python3.9/site-packages/pkg/__init__.py)
This is a different
% ls ~/.local/lib/python3.9/site-packages/pkg __init__.py pkgformat.py __pycache__/ pkglist.py apt_data_set_generator.py repo.py apt_repo.py repomd.py apt_runner.py runner.py aptmd.py version.py metalink.py
% python -mpip show pkg Name: pkg Version: 0.2 Summary: Python scripts dealing with software packages used in building applications and systems Home-page: https://github.com/joaomdsc/pkg Author: João Moreira de Sá Coutinho Author-email: email@example.com License: UNKNOWN Location: /data/omnios-build/.local/lib/python3.9/site-packages Requires: Required-by:
Fundamentally, I don't think the python tools should be looking for modules in the building user's local python lib. This can be avoided using python's
-s option or by setting the
PYTHONNOUSERSITE environment variable.
-s Don't add user site directory to sys.path. PYTHONNOUSERSITE If this is set to a non-empty string it is equivalent to specifying the -s option (Don't add the user site directory to sys.path).
For a consistent build environment, we should also consider adding:
-E Ignore environment variables like PYTHONPATH and PYTHONHOME that modify the behaviour of the interpreter.
or unset these in
Both of these options are available in Python 2.7 and above.
Updated by Electric Monk 7 months ago
- Status changed from New to Closed
- % Done changed from 0 to 100
commit 3f770aab815d6900f53f0b0f317aaf74a8f95018 Author: Andy Fiddaman <firstname.lastname@example.org> Date: 2021-06-23T22:06:10.000Z 13841 python tools should not add user's site directory Reviewed by: Matt Fiddaman <email@example.com> Reviewed by: Toomas Soome <firstname.lastname@example.org> Approved by: Dan McDonald <email@example.com>