use lambdas so imports dont run, use __qualname__
This commit is contained in:
parent
48865039bf
commit
e79f51c25d
3 changed files with 13 additions and 6 deletions
|
@ -8,8 +8,8 @@ def import_source(factory: Callable[[], Any], default: Any) -> Any:
|
||||||
try:
|
try:
|
||||||
res = factory()
|
res = factory()
|
||||||
return res
|
return res
|
||||||
except ImportError: # presumable means the user hasn't installed the module
|
except ModuleNotFoundError: # presumable means the user hasn't installed the module
|
||||||
warn(f"Module {factory.__name__} could not be imported, or isn't configured propertly")
|
warn(f"Module {factory.__qualname__} could not be imported, or isn't configured propertly")
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ def import_source_iter(factory: Callable[[], Iterator[T]], default: Optional[Ite
|
||||||
try:
|
try:
|
||||||
res = factory()
|
res = factory()
|
||||||
yield from res
|
yield from res
|
||||||
except ImportError: # presumable means the user hasn't installed the module
|
except ModuleNotFoundError: # presumable means the user hasn't installed the module
|
||||||
warn(f"Module {factory.__name__} could not be imported, or isn't configured propertly")
|
warn(f"Module {factory.__qualname__} could not be imported, or isn't configured propertly")
|
||||||
yield from default
|
yield from default
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,13 @@ since that allows for easier overriding using namespace packages
|
||||||
https://github.com/karlicoss/HPI/issues/102
|
https://github.com/karlicoss/HPI/issues/102
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# For now, including this here, since importing the module
|
||||||
|
# causes .rexport to be imported, which requires rexport
|
||||||
|
REQUIRES = [
|
||||||
|
'git+https://github.com/karlicoss/rexport',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
# TODO: add warning here
|
# TODO: add warning here
|
||||||
|
|
||||||
from .rexport import *
|
from .rexport import *
|
||||||
|
|
|
@ -16,14 +16,14 @@ def _rexport_import() -> Any:
|
||||||
return source
|
return source
|
||||||
|
|
||||||
def _rexport_comments() -> Iterator[Comment]:
|
def _rexport_comments() -> Iterator[Comment]:
|
||||||
yield from imp(_rexport_import().comments)
|
yield from imp(lambda: _rexport_import().comments())
|
||||||
|
|
||||||
def _pushshift_import() -> Any:
|
def _pushshift_import() -> Any:
|
||||||
from . import pushshift as source
|
from . import pushshift as source
|
||||||
return source
|
return source
|
||||||
|
|
||||||
def _pushshift_comments() -> Iterator[Comment]:
|
def _pushshift_comments() -> Iterator[Comment]:
|
||||||
yield from imp(_pushshift_import().comments)
|
yield from imp(lambda: _pushshift_import().comments())
|
||||||
|
|
||||||
# Merged functions
|
# Merged functions
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue