sitecustomize.py in mach virtualenv import mach_bootstrap which is not available
Categories
(Firefox Build System :: General, defect)
Tracking
(firefox-esr78 fixed, firefox81 fixed, firefox82 fixed, firefox83 fixed)
People
(Reporter: glandium, Assigned: rstewart)
References
Details
Attachments
(2 files)
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
jcristau
:
approval-mozilla-beta+
pascalc
:
approval-mozilla-release+
jcristau
:
approval-mozilla-esr78+
|
Details | Review |
Reporter | ||
Comment 1•5 years ago
|
||
I was writing a commit message for a simple fix, but it turns out there's more to it.
- sitecustomize.py contains an import of the mach_bootstrap module, but that can only work when populate_local_paths is set, which is not the case for the mach virtualenv. So in theory, the import shouldn't be there if populate_local_paths is set (that's what I was fixing in my local commit).
- the code the mach_bootstrap module import is meant to trigger is there to avoid loading .pyc files when there isn't a corresponding .py file in the same directory. That is actually not necessary with python 3, which puts the .pyc files in a separate
__pycache__
directory, and if the corresponding .py file disappears, the .pyc files in there are ignored. But it's still necessary in python 2. It would actually be good to have the mach python2 virtualenv have this workaround so the simple workaround is not enough... (see bug 1188224)
Ricky, WDYT?
Assignee | ||
Comment 2•5 years ago
|
||
Mike, did you see this at HEAD, or only atop https://phabricator.services.mozilla.com/D92173?
Weird how nobody's caught this until now. That virtualenv
works perfectly for me, so I can only assume that the sitecustomize
isn't actually getting run on my machine... That's something to follow up on, first of all. I wonder if my patch introduced the issue or if this problem has been around for longer.
Setting populate_local_paths
in the .mozbuild
virtualenv
s is a non-starter. That would make it unnecessarily difficult to do work on multiple trees. i.e., there's a reason we don't populate_local_paths
.
So I'm in favor of doing the following:
-
Don't
import mach_bootstrap
in the.mozbuild
virtualenv
s. It'll get imported anyway whenmach
starts up. -
Only do the
import mach_bootstrap
logic for the in-objdir
Python 2virtualenv
. -
As a follow-up, figure out why my (and everyone's?)
.mozbuild
virtualenv
'ssitecustomize
package isn't working.
Assignee | ||
Comment 3•5 years ago
|
||
Before, this would be written to sitecustomize.py
irrespective of the value of populate_local_paths
. This doesn't make sense -- since the local paths aren't included in the virtualenv
's PYTHONPATH
when Python starts up, it doesn't know how to import mach_bootstrap
. Since on mach
startup the import hook will be loaded anyway, and the virtualenv
s in ~/.mozbuild
(i.e. the only virtualenv
s for which we don't populate_local_paths
) are just used to run mach
, this is fine and won't regress anything.
Also, since the import
hook is only necessary for Python 2, add a couple conditional checks to get rid of the added overhead when we're running with Python 3.
Updated•5 years ago
|
Updated•5 years ago
|
Assignee | ||
Comment 4•5 years ago
|
||
Evidently sitecustomize
ignores some errors under certain mysterious circumstances. :(
-
If I
import mach_bootstrap
in my~/.mozbuild
sitecustomize
, the Python works fine (but the failure to importmach_bootstrap
gets silently ignored). -
If I
import
a package that DEFINITELY does not exist ANYWHERE, likemach_bootstrap_asdlfkjsdfkjdf
, then again, the Python works fine and the failure is silently ignored. -
If I throw some other exception, e.g. by dividing by zero, then finally the Python fails to start up and prints a helpful message.
I can't find this behavior documented -- at least, not exactly. There's this:
After these path manipulations, an attempt is made to import a module named sitecustomize, which can perform arbitrary site-specific customizations. It is typically created by a system administrator in the site-packages directory. If this import fails with an ImportError or its subclass exception, and the exception’s name attribute equals to 'sitecustomize', it is silently ignored.
... but the .name
attribute of the exception thrown would be mach_bootstrap
, not sitecustomize
, so this doesn't really make sense. I assume that the old virtualenv
we're using doesn't emulate this behavior exactly, which would explain why you're encountering the problem now. So I assume no other work is required on our end and any other possible issues like this would be addressed by the virtualenv
upgrade.
Assignee | ||
Comment 5•5 years ago
|
||
ImportError
s when importing sitecustomize
used to be unilaterally ignored until Python 3.7.
Comment 8•5 years ago
|
||
bugherder |
Reporter | ||
Comment 10•5 years ago
|
||
Considering bug 1669639, we may want to uplift this to all branches, including esr.
Assignee | ||
Comment 11•5 years ago
|
||
The change to python/mozbuild/mozbuild/virtualenv.py
probably won't uplift cleanly in general (it involves the populate_local_paths
machinery that was introduced in the last couple months and has gone through several iterations), but the change to build/mach_bootstrap.py
will, and that's what matters at least with respect to bug 1669639. So I can get another patch going just for the uplift.
Assignee | ||
Comment 12•5 years ago
|
||
Assignee | ||
Comment 13•5 years ago
|
||
Comment on attachment 9180270 [details]
Bug 1668718 - Don't set import
hook for Python 3 in mach bootstrap
Beta/Release Uplift Approval Request
- User impact if declined: Builds can fail a la bug 1669639.
- Is this code covered by automated tests?: Yes
- Has the fix been verified in Nightly?: Yes
- Needs manual test from QE?: No
- If yes, steps to reproduce:
- List of other uplifts needed: None
- Risk to taking this patch: Low
- Why is the change risky/not risky? (and alternatives if risky): This gets rid of code that was relevant in Python 2 but not Python 3 (Python 3 being what we use to build).
- String changes made/needed:
ESR Uplift Approval Request
- If this is not a sec:{high,crit} bug, please state case for ESR consideration: Without this patch, builds can fail a la bug 1669639.
- User impact if declined: Builds can fail a la bug 1669639.
- Fix Landed on Version: 83
- Risk to taking this patch: Low
- Why is the change risky/not risky? (and alternatives if risky): This gets rid of code that was relevant in Python 2 but not Python 3 (Python 3 being what we use to build).
- String or UUID changes made by this patch:
Comment 14•5 years ago
|
||
Comment on attachment 9180270 [details]
Bug 1668718 - Don't set import
hook for Python 3 in mach bootstrap
a=npotb
Comment 15•5 years ago
|
||
bugherder uplift |
Comment 16•5 years ago
|
||
bugherder uplift |
Comment 17•5 years ago
|
||
Comment on attachment 9180270 [details]
Bug 1668718 - Don't set import
hook for Python 3 in mach bootstrap
Approved for 81.0.2, thanks.
![]() |
||
Comment 18•5 years ago
|
||
bugherder uplift |
Comment 19•5 years ago
|
||
Comment on attachment 9179358 [details]
Bug 1668718 - Don't import mach_bootstrap
for virtualenv
s that don't have populate_local_paths
set, or in Python 3
ESR Uplift Approval Request
- If this is not a sec:{high,crit} bug, please state case for ESR consideration: Resolves local-build sharp edge
- User impact if declined: Without this patch, local builds will fail if using system, read-only python.
If using write-able python, causes import warnings to appear whenever python is run (even outside of Firefox) - Fix Landed on Version: 83
- Risk to taking this patch: Low
- Why is the change risky/not risky? (and alternatives if risky): Build patch
- String or UUID changes made by this patch:
Updated•5 years ago
|
Description
•