-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: We had support for having modules excluded from lazy importing things. This was set via `importlib.set_lazy_imports(excluding=...)`. This diff adds support for pinning eager imports explicitly via `importlib.set_lazy_imports(eager=...)`. The difference between the two is that with the former, any imports inside modules in the `excluding` container would be eagerly imported. With the later, anything listed in the `eager` container would always be eagerly imported, no matter where it's imported. Modules in this container have to be exact matches to whatever is being imported. One caveat to be aware is that `importlib.set_lazy_imports(eager={"foo.bar.baz"})` will make `import foo.bar.baz` or `from foo.bar import baz` eager, but not `import foo.bar.baz.plugh`, even if that import would imply importing `foo.bar.baz`. Differential Revision: D57794109 fbshipit-source-id: 9e5c3ecd31853929f4c5bdc9bf3994d38d8d9c36
- Loading branch information
1 parent
4dacb0b
commit 96342a1
Showing
11 changed files
with
151 additions
and
31 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,38 @@ | ||
# Copyright (c) Meta, Inc. and its affiliates. All Rights Reserved | ||
# File added for Lazy Imports | ||
|
||
import self | ||
if self._lazy_imports: | ||
self.skipTest("Test relevant only when running with global lazy imports disabled") | ||
|
||
import importlib | ||
|
||
importlib.set_lazy_imports(eager=[ | ||
"test.lazyimports.data.metasyntactic.foo", | ||
"test.lazyimports.data.metasyntactic.waldo", | ||
"test.lazyimports.data.metasyntactic.plugh.Plugh", | ||
]) | ||
|
||
import test.lazyimports.data.metasyntactic.foo as foo | ||
self.assertFalse(importlib.is_lazy_import(globals(), "foo")) # should be eager | ||
|
||
from test.lazyimports.data.metasyntactic.foo import bar | ||
self.assertFalse(importlib.is_lazy_import(globals(), "bar")) # maybe this should have been lazy? | ||
|
||
from test.lazyimports.data.metasyntactic.waldo import Waldo | ||
self.assertFalse(importlib.is_lazy_import(globals(), "Waldo")) # maybe this should have been lazy? | ||
|
||
import test.lazyimports.data.metasyntactic.waldo.fred as fred | ||
self.assertTrue(importlib.is_lazy_import(globals(), "fred")) # this should be lazy | ||
|
||
from test.lazyimports.data.metasyntactic.waldo.fred import Fred | ||
self.assertTrue(importlib.is_lazy_import(globals(), "Fred")) # this should be lazy | ||
|
||
from test.lazyimports.data.metasyntactic.waldo import fred | ||
self.assertFalse(importlib.is_lazy_import(globals(), "fred")) # maybe this should have been lazy? | ||
|
||
import test.lazyimports.data.metasyntactic.plugh as plugh | ||
self.assertTrue(importlib.is_lazy_import(globals(), "plugh")) # this should be lazy | ||
|
||
from test.lazyimports.data.metasyntactic.plugh import Plugh | ||
self.assertFalse(importlib.is_lazy_import(globals(), "Plugh")) # explicitly eager |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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