-
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make CinderX work with optimized Python builds (again)
Summary: D62604340 introduced a step to the build where `sed` is used to edit `site.py` to *enable* CinderX in the 3.12 distribution as needed. Unfortunately this doesn't work in optimized builds. Those builds "deep-freeze" a number of startup Python libraries including `site.py` in a state *before* the edit is made. To fix this, move the CinderX initialization code into a Python module that's not in the frozen libraries, and only include this in the distribution if CinderX is desired. During Python startup, if the `init_cinderx` does not exist then proceed without it leaving the set of imported modules unchanged. This resolves the issue D62604340 was trying to address. Reviewed By: itamaro Differential Revision: D65584596 fbshipit-source-id: 212dbe22a93fa44d33750166b80d03bffa559502
- Loading branch information
1 parent
20d2153
commit cf9e37a
Showing
2 changed files
with
30 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# This file is deliberately not included in the set of deep-frozen bootstrap | ||
# libraries so it can easily be excluded from the distribution to avoid | ||
# attempting to initialize CinderX. This is desirable because this code imports | ||
# importlib.util and some tests are surprised when they find this unexpectedly | ||
# loaded as part of bootstrap. | ||
|
||
import importlib.util | ||
|
||
# `cinderx` is the Python module in fbcode/cinderx/PythonLib which wraps the | ||
# `_cinderx` C++ extension in fbcode/cinderx/_cinderx.cpp. Both need to be | ||
# available to load CinderX. | ||
if not ( | ||
importlib.util.find_spec("cinderx") is None | ||
or importlib.util.find_spec("_cinderx") is None | ||
): | ||
try: | ||
import cinderx | ||
|
||
cinderx.init() | ||
except Exception as e: | ||
raise RuntimeError("Failed to initialize CinderX module") from e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters