gecko-dev/tools/phabricator
Mitchell Hentges 37a1a70a52 Bug 1730712: Maintain sys.path consistency in nested Mach calls r=ahal
This patch resolves cases like the following:
1. The system Python has `zstandard`.
2. `MOZ_AUTOMATION=1 ./mach python --virtualenv psutil <script>`
   is run, adding `psutil` to the import scope.
3. `<script>` runs Mach a _second_ time, and this time Mach needs to
   be able to import `zstandard` (in this case, it should be able
   to fetch it from the system Python's site-packages).

The previous behaviour would add the "site-packages" of the //invoking//
Python interpreter, but ancestor packages would get dropped.

To rectify this issue, this patch changes "import inheritance" to keep
more of the `sys.path`, rather than just
`<external-python>.all_site_packages_dirs()`.

Note: the original implementation of this patch passed forward *all*
of the `sys.path` when creating virtualenvs. However, this caused issues
when Mach ran `pip`, because `pip` was no longer able to discover the
"standard library" (it was failing because it assumed all paths defined
in a virtualenv's site were non-standard-library paths, and the original
implementation broke that assumption).

As part of this, a distinction was defined between the "current" Python
interpreter (external_python) and the top-level Python interpreter
(original_python). This was needed to enable discovering which paths
are "standard library paths".

Differential Revision: https://phabricator.services.mozilla.com/D134201
2021-12-29 21:10:22 +00:00
..
mach_commands.py Bug 1730712: Maintain sys.path consistency in nested Mach calls r=ahal 2021-12-29 21:10:22 +00:00