Skip to content

Commit 6f76d66

Browse files
alexmalyshevmeta-codesync[bot]
authored andcommitted
Add CINDERX_DISABLE escape hatch to force use of CinderX stubs
Summary: Makes it easy to disable the CinderX native extension for testing purposes. Reviewed By: yoney Differential Revision: D92896835 fbshipit-source-id: 2cd377f9e27053d03dda852522d20191ac60a0b2
1 parent d5e7460 commit 6f76d66

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

cinderx/PythonLib/cinderx/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626
_import_error: ImportError | None = None
2727

2828

29+
def is_force_disabled() -> bool:
30+
"""
31+
Check that the _cinderx native extension hasn't been forcefully disabled
32+
via an explicit environment variable.
33+
"""
34+
35+
cinderx_disable = environ.get("CINDERX_DISABLE", "")
36+
return cinderx_disable != "" and cinderx_disable != "0"
37+
38+
2939
def is_supported_runtime() -> bool:
3040
"""
3141
Check that the current Python runtime will be able to load the _cinderx
@@ -48,6 +58,11 @@ def is_supported_runtime() -> bool:
4858

4959

5060
try:
61+
if is_force_disabled():
62+
raise ImportError(
63+
"The _cinderx native extension has been forcibly disabled with CINDERX_DISABLE in the environment"
64+
)
65+
5166
# Currently if we try to import _cinderx on runtimes without our internal patches
5267
# the import will crash. This is meant to go away in the future.
5368
if not is_supported_runtime():

0 commit comments

Comments
 (0)