-
-
Notifications
You must be signed in to change notification settings - Fork 625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide the XonshImportEventLoader with all the functions that pkg_re… #3636
Changes from 2 commits
9bd858e
9de0303
342d942
3f9f08c
d15cd6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,20 @@ | |
|
||
This module registers the hooks it defines when it is imported. | ||
""" | ||
import builtins | ||
import contextlib | ||
import importlib | ||
import os | ||
import re | ||
import sys | ||
import types | ||
import builtins | ||
import contextlib | ||
import importlib | ||
from importlib.machinery import ModuleSpec | ||
from importlib.abc import MetaPathFinder, SourceLoader, Loader | ||
from importlib.machinery import ModuleSpec | ||
|
||
from xonsh.events import events | ||
from xonsh.execer import Execer | ||
from xonsh.platform import ON_WINDOWS, scandir | ||
from xonsh.lazyasd import lazyobject | ||
from xonsh.platform import ON_WINDOWS, scandir | ||
|
||
|
||
@lazyobject | ||
|
@@ -270,6 +270,24 @@ def find_spec(self, fullname, path, target=None): | |
return spec | ||
|
||
|
||
_XIEVL_WRAPPED_ATTRIBUTES = [ | ||
"load_module", | ||
"module_repr", | ||
"get_data", | ||
"get_resource_filename", | ||
"get_resource_stream", | ||
"get_resource_string", | ||
"has_resource", | ||
"has_metadata", | ||
"get_metadata", | ||
"get_metadata_lines", | ||
"resource_isdir", | ||
"metadata_isdir", | ||
"resource_listdir", | ||
"metadata_listdir", | ||
] | ||
|
||
|
||
class XonshImportEventLoader(Loader): | ||
"""A class that dispatches loader calls to another loader and fires relevant | ||
xonsh events. | ||
|
@@ -295,13 +313,10 @@ def exec_module(self, module): | |
events.on_import_post_exec_module.fire(module=module) | ||
return rtn | ||
|
||
def load_module(self, fullname): | ||
"""Legacy module loading, provided for backwards compatibility.""" | ||
return self.loader.load_module(fullname) | ||
|
||
def module_repr(self, module): | ||
"""Legacy module repr, provided for backwards compatibility.""" | ||
return self.loader.module_repr(module) | ||
def __getattribute__(self, name): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this over There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops! That's my fault. @astronouth7303 is right - There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Argh, right! It worked and I did not think twice... |
||
if name in _XIEVL_WRAPPED_ATTRIBUTES: | ||
return getattr(self.loader, name) | ||
return object.__getattribute__(self, name) | ||
|
||
|
||
def install_import_hooks(): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a frozenset