Bug #13841
closedpython tools should not add user's site directory
100%
Description
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 pkg
.
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 pkg
% 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: joao.moreiradsc@gmail.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 nightly
/ bldenv
.
Both of these options are available in Python 2.7 and above.
Updated by Andy Fiddaman almost 2 years ago
I've tested this by running the tools under python 2.7, 3.7 and 3.9 both with and without a fake pkg
module in my user's local lib directory, all worked as expected.
Updated by Electric Monk almost 2 years ago
- Status changed from New to Closed
- % Done changed from 0 to 100
git commit 3f770aab815d6900f53f0b0f317aaf74a8f95018
commit 3f770aab815d6900f53f0b0f317aaf74a8f95018 Author: Andy Fiddaman <omnios@citrus-it.co.uk> Date: 2021-06-23T22:06:10.000Z 13841 python tools should not add user's site directory Reviewed by: Matt Fiddaman <illumos@m.fiddaman.uk> Reviewed by: Toomas Soome <tsoome@me.com> Approved by: Dan McDonald <danmcd@joyent.com>