Skip to content

Commit a9dcc50

Browse files
DinoVmeta-codesync[bot]
authored andcommitted
Let install specify opt-in / opt-out list
Summary: Adds support for an opt-in / opt-out list Reviewed By: alexmalyshev Differential Revision: D96375277 fbshipit-source-id: 47705fa0dee1016bb23debd67eca22cca70e42e4
1 parent 84371da commit a9dcc50

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

cinderx/PythonLib/cinderx/compiler/strict/pyrefly_loader.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
from .loader import StrictSourceFileLoader
2121

2222

23+
OPT_OUT_LIST: set[str] | None = None
24+
OPT_IN_LIST: set[str] | None = None
25+
26+
2327
class PyreflyLoader(StrictSourceFileLoader):
2428
pyrefly_type_dir: str | None = None
2529

@@ -40,8 +44,8 @@ def ensure_compiler(
4044
else:
4145
pyrefly = None
4246
comp = cls.compiler = PyreflyCompiler(
43-
static_opt_out=None,
44-
static_opt_in=None,
47+
static_opt_out=OPT_OUT_LIST,
48+
static_opt_in=OPT_IN_LIST,
4549
path=path,
4650
stub_path=stub_path,
4751
allow_list_prefix=allow_list_prefix,
@@ -54,6 +58,10 @@ def ensure_compiler(
5458
return comp
5559

5660
def should_force_strict(self) -> bool:
61+
if OPT_IN_LIST is not None:
62+
return self.name in OPT_IN_LIST
63+
if OPT_OUT_LIST is not None:
64+
return self.name not in OPT_OUT_LIST
5765
return True
5866

5967

@@ -112,11 +120,20 @@ def _get_supported_file_loaders(
112120
return [extensions, source, bytecode]
113121

114122

115-
def install(enable_patching: bool = False, pyrefly_type_dir: str | None = None) -> None:
123+
def install(
124+
enable_patching: bool = False,
125+
pyrefly_type_dir: str | None = None,
126+
opt_in_list: set[str] | None = None,
127+
opt_out_list: set[str] | None = None,
128+
) -> None:
116129
"""Installs a loader which is capable of loading and validating strict modules"""
117130
PyreflyLoader.pyrefly_type_dir = pyrefly_type_dir
118131
supported_loaders = _get_supported_file_loaders(enable_patching)
119132

133+
global OPT_IN_LIST, OPT_OUT_LIST
134+
OPT_IN_LIST = opt_in_list
135+
OPT_OUT_LIST = opt_out_list
136+
120137
for index, hook in enumerate(sys.path_hooks):
121138
if not isinstance(hook, type):
122139
sys.path_hooks.insert(index, FileFinder.path_hook(*supported_loaders))

0 commit comments

Comments
 (0)