Closed Bug 1712151 Opened 3 years ago Closed 2 years ago

Validate in CI virtualenvs don't have dependency collisions with "global" virtualenv, or between vendored + pypi'd deps

Categories

(Firefox Build System :: Mach Core, enhancement, P2)

enhancement

Tracking

(firefox94 fixed)

RESOLVED FIXED
94 Branch
Tracking Status
firefox94 --- fixed

People

(Reporter: mhentges, Assigned: mhentges)

References

(Blocks 2 open bugs)

Details

Attachments

(4 files)

First, some backstory: there's a two different ways of activating the command's virtual environment:

  1. Use an independent Python process.
  2. Re-use the existing process and activate the new virtualenv within it.

Using an independent Python process fully insulates the command (and its dependencies) from the global mach operations' dependencies. However, in addition to the performance hit (roughly ~100ms Python startup time on a fast Linux machine), it has some inflexibilities:

  1. Passing data (moz.build parsed goodies, context, etc) becomes more difficult - it has to be encoded, transferred to the other process, and decoded.
  2. Behaviour that would be trivial in a single Python process becomes harder:
    • Having sentry capture exceptions from either mach or the active command.
    • Passing a glean handle into virtualenvs (we'd have to ensure that commands are using the same version of glean as global mach, as well as find a nice way of sharing the initialization logic).

Now, the downside of re-using the same python process is that import state is maintained: if we import glean-sdk==38.0.1 (mach venv), and that imports glean_parser==3.2.0 (mach venv), and that imports PyYAML==3.13 (mach venv), then import yaml will always return PyYAML==3.13 from the (mach venv), even after the virtualenv changes. (Technically, imports can be re-loaded, but then that can cause issues if glean-sdk performs an import from within a function and gets the wrong package).

Fortunately, this issue is completely manageable - if we validate that each virtualenv's dependencies are compatible with the global mach venv's dependencies, then we won't have issues.

From my perspective, the "validation" technique is the most manageable: we still get to write a single cohesive Python application, but we are able to have the different commands have their own distinct dependencies which are incompatible with each other.

This ticket is to capture the automatic validation of the command virtualenvs in CI.
Note that, due to system-specific requirements, we probably need to run these tests in:

  • All supported Pythons (Python 3.6 through 3.9)
  • All primary platforms (Mac, Windows, Linux)
Priority: -- → P2
Summary: Validate in CI that "global mach" virtualenv doesn't have dependency collisions with any command virtualenv → Validate in CI virtualenvs don't have dependency collisions with "global" virtualenv, or between vendored + pypi'd deps
Depends on: 1724273

We're going to need to validate command dependency compatibility with both:

  • Global Mach dependencies and
  • Python testing dependencies

The existing version of pyasn1-modules (0.1.5) is incompatible with
our version of pyasn1 (0.4.8).

By bumping pyasn1-modules to 0.2.8, we now meet its compatibility
requirements.

Depends on D122896

Add pystache to vendor requirements.in so that it's vendored according
to ./mach vendor python "ignore" rules.
This ensures that sufficient files are vendored such that installing the
package from it's setup.py file is possible.

Depends on D122897

We vendor glean_parser==3.6.0, and that was incompatible with
glean-sdk==36.0.0's requirement of glean_parser==2.5.0.
glean-sdk==40.0.0 expects glean_parser==3.6.0, which is perfect.

Depends on D122898

This adds two main compatibility guarantees:

  1. Vendored dependencies <=> Pypi-downloaded dependencies
  2. Global Mach dependencies <=> command-specific dependencies

As part of this, a new vendored: action was added to the virtualenv
definition format. Otherwise similar to pth: paths, vendored:
packages are assumed to be "pip install"-able.

Some validation (the .dist-info check) was added to requirements.py
to verify that pth: and vendored: are correctly used. However, I
couldn't add a setup.py check because some of our un-installable
internal modules (mozbase, etc) have out-of-date and potentially
inaccurate setup.py files. Though it would be nice to leverage each
internal module as an independent package with its own scoped set of
dependencies, that's a project for another time.

Depends on D122899

Assignee: nobody → mhentges
Status: NEW → ASSIGNED
Pushed by mhentges@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/3f85c601e434
Bump glean-sdk version to 40.0.0 r=ahal
Blocks: 1715639
Pushed by mhentges@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/9ccf99dae3c7
Use compatible version of pyasn1-modules r=ahal
https://hg.mozilla.org/integration/autoland/rev/2c6edefd8417
Vendor pystache automatically r=ahal
Pushed by mhentges@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/c196c1ecdff7
Use compatible version of pyasn1-modules r=ahal
https://hg.mozilla.org/integration/autoland/rev/089c1a0d9ec8
Vendor pystache automatically r=ahal
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 94 Branch
Keywords: leave-open
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Pushed by mhentges@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/7adf7e2136a3
Add test to verify virtualenv compatibility r=ahal
Flags: needinfo?(mhentges)
Pushed by mhentges@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/1860400b41c4
Add test to verify virtualenv compatibility r=ahal

Note that, due to system-specific requirements, we probably need to run these tests in:

  • All supported Pythons (Python 3.6 through 3.9)
  • All primary platforms (Mac, Windows, Linux)

I'm going to defer the cross-platform-test part of this ticket.

Status: REOPENED → RESOLVED
Closed: 3 years ago2 years ago
Resolution: --- → FIXED
Blocks: 1724273
No longer depends on: 1724273
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: