-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
3,628 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,45 @@ | ||
import sys | ||
from importlib.machinery import ModuleSpec | ||
import importlib.abc | ||
|
||
class CustomModule: | ||
pass | ||
|
||
class CustomFinder: | ||
def find_spec(self, name, path=None, target=None): | ||
print('Finding', name, path, target) | ||
if name == 'mymod': | ||
return ModuleSpec(name, CustomLoader()) | ||
|
||
class CustomLoader: | ||
def create_module(self, name): | ||
print('Creating', name) | ||
return CustomModule() | ||
|
||
def exec_module(self, mod): | ||
print(vars(mod)) | ||
print('Executing', mod) | ||
|
||
sys.meta_path.insert(0, CustomFinder()) | ||
|
||
import mymod | ||
|
||
print(mymod) | ||
|
||
|
||
|
||
class CustomImporter(importlib.abc.InspectLoader): | ||
def find_spec(self, name, path=None, target=None): | ||
print('Finding', name, path, target) | ||
if name == 'zzmod': | ||
return ModuleSpec(name, self) | ||
|
||
def get_source(self, name): | ||
return 'p = 3' | ||
|
||
sys.meta_path.insert(0, CustomImporter()) | ||
|
||
import zzmod | ||
|
||
print(zzmod) | ||
print(zzmod.p) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
print('importing bar') |
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,4 @@ | ||
import package | ||
|
||
import package.foo | ||
import package.bar |
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,2 @@ | ||
print('importing package') | ||
__path__.append('./another_directory') |
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 @@ | ||
print('importing foo') |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.