If you install Portage in a venv and then run it with PORTAGE_CONFIGROOT!=/ and ROOT!=/, the resulting config becomes broken. API calls don't match any repositories, and e.g. emerge fails to start with: ``` !!! /tmp/.venv/etc/portage/make.profile is not a symlink and will probably prevent most merges. !!! It should point into a profile within /tmp/pytest-of-mgorny/pytest-0/root0/usr/portage/profiles/ !!! (You can safely ignore this message when syncing. It's harmless.) !!! Your current profile is invalid. If you have just changed your profile !!! configuration, you should revert back to the previous configuration. !!! Allowed actions are limited to --help, --info, --search, --sync, and !!! --version. ``` This is apparently because of the logic in portage/__init__.py. The create_trees() function first creates settings instance with the correct config_root. Then it determines that ROOT != '/' and replaces settings with a "clean" object that ignores config_root. Then everything falls apart because it goes looking for make.profile inside the venv.
My reproducer: git clone https://github.com/mgorny/gentoopm cd gentoopm tox Basically, tests work just fine with Gentoo-installed Portage but fail when run inside venv. You can then use e.g.: . .tox/py310/bin/activate export PORTAGE_CONFIGROOT=/tmp/pytest-of-<username>/pytest-current/rootcurrent/ export ROOT=${PORTAGE_CONFIGROOT} emerge