gecko-dev/python
Mitchell Hentges 15510f9f26 Bug 1761150: Mach should use fresh system python, don't inherit sys.path r=ahal
Previously, when using the system Python packages, Mach would reuse the
values already existing in the `sys.path`. This had two benefits:
1. We didn't have to do work to calculate which paths the "system
   Python" specifically referred to.
2. This allowed us to support nested Mach calls
   (such as `./mach --virtualenv psutil ./mach build`).

However, it came with its own headaches, specifically around "consistent
imports" and Python subprocesses, such as in the following example
1. Mach runs "using system Python"
2. The "build" site (for example) would be activated. The current
   `sys.path` is included in the virtualenv's `mach.pth` file so that
   subprocesses will have access to the same packages as the primary
   Mach process
3. //Something// adds something to the `sys.path`
4. The build virtualenv is redundantly re-activated (such as due to
   generic setup code for some module). Though we don't physically
   re-activate the virtualenv, we //do// check that it's up-to-date to
   validate assumptions - **and it's not!** It's missing the
   //something// that was added to the `sys.path`.
5. We can't re-create the build virtualenv because it's already active,
   so:
6. An error is raised so that unexpected out-of-date-ness doesn't fly
   under the radar.

-----

This patch solves this by calculating the "system Python" paths in a
deterministic way. Then, even when using the system Python, the Mach and
command sites use define themselves in a consistent way.

This means that we can't do `./mach --virtualenv <venv> ./mach ...` to
shares `venv`'s packages with the whole new Mach process. Fortunately,
this has been replaced with  moving such packages into the nested Mach
command's requirements  definition instead.

TL;DR: more consistent, less failures. 👍

-----

One more detail, this time around the `sys_path()` function:
Ideally, we could calculate the standard library paths *and* the
"system" paths with only one Python subprocess. Unfortunately,
that's not the case:
* If `-S` isn't provided, then it's tricky to separate the standard
  library paths from the system paths
* If `-S` is provided, then doing `site.getsitepackages()` in a
  virtualenv returns the *system* site packages, not the virtualenv's.

To work around this, we call the external python twice, and in
parallel. This allows resolving the information we need while avoiding
performance costs.

Differential Revision: https://phabricator.services.mozilla.com/D143200
2022-04-12 18:40:14 +00:00
..
devtools/migrate-l10n Bug 1753413 - fx doc: Remove whitespaces, trailing lines & windows CR r=andi,perftest-reviewers,sparky 2022-02-03 18:34:58 +00:00
docs Bug 1659593: Make ./mach vendor python cross-platform r=ahal 2022-04-07 18:00:28 +00:00
gdbpp/gdbpp
l10n Bug 1732151 - Migrate dataReportingNotification strings to Fluent. r=preferences-reviewers,fluent-reviewers,flod 2022-03-24 15:57:54 +00:00
lldbutils
mach Bug 1761150: Mach should use fresh system python, don't inherit sys.path r=ahal 2022-04-12 18:40:14 +00:00
mozboot Bug 1588396 - Add 'pureos' to DEBIAN_DISTROS. r=mhentges 2022-04-11 15:01:30 +00:00
mozbuild Bug 1289641 - Vendor the vsdownload script. r=firefox-build-system-reviewers,mhentges 2022-04-11 23:00:08 +00:00
mozlint Bug 1756224: Update MozlintParser docs about default paths r=ahal 2022-03-09 15:52:48 +00:00
mozperftest Bug 1741975 - Have WPT tests available in taskcluster r=perftest-reviewers,sparky 2022-04-01 16:59:17 +00:00
mozrelease Bug 1755088: Replace all usages of unittest deprecated aliases r=webdriver-reviewers,ahal,whimboo 2022-02-17 15:21:41 +00:00
mozterm
mozversioncontrol Bug 1732795: Resolve upcoming pytest deprecations r=webdriver-reviewers,ahal,whimboo 2022-02-18 14:27:18 +00:00
sites Bug 1761150: Mach should use fresh system python, don't inherit sys.path r=ahal 2022-04-12 18:40:14 +00:00
mach_commands.py Bug 1717104: Activate virtualenv before running command r=perftest-reviewers,ahal,AlexandruIonescu 2022-03-23 14:50:45 +00:00
moz.build Bug 1724274: Move virtualenv dependency manifests to python/virtualenvs r=ahal 2022-03-24 14:04:34 +00:00
README

This directory contains common Python code.

The basic rule is that if Python code is cross-module (that's "module" in the
Mozilla meaning - as in "module ownership") and is MPL-compatible, it should
go here.

What should not go here:

* Vendored python modules (use third_party/python instead)
* Python that is not MPL-compatible (see other-licenses/)
* Python that has good reason to remain close to its "owning" (Mozilla)
  module (e.g. it is only being consumed from there).

Historical information can be found at
https://bugzilla.mozilla.org/show_bug.cgi?id=775243
https://bugzilla.mozilla.org/show_bug.cgi?id=1346025