diff --git a/personal_data/fetchers/__init__.py b/personal_data/fetchers/__init__.py index bdce392..255ebf2 100644 --- a/personal_data/fetchers/__init__.py +++ b/personal_data/fetchers/__init__.py @@ -21,11 +21,16 @@ def get_modules(backend_dir: Path) -> Iterator[str]: if name != '__init__': yield name +FETCHER_MODULES_LOADED = False + def load_fetcher_modules() -> None: - backend_dir = Path(__name__.replace(r'.', '/')) - for module in get_modules(backend_dir): - load_backend(module) + global FETCHER_MODULES_LOADED + if not FETCHER_MODULES_LOADED: + backend_dir = Path(__name__.replace(r'.', '/')) + for module in get_modules(backend_dir): + load_backend(module) + FETCHER_MODULES_LOADED = True load_fetcher_modules() diff --git a/personal_data/main.py b/personal_data/main.py index 5c623af..ce2fc04 100644 --- a/personal_data/main.py +++ b/personal_data/main.py @@ -7,7 +7,7 @@ from pathlib import Path import requests import requests_cache -from . import data, notification, util +from . import data, notification, util, fetchers logger = logging.getLogger(__name__) @@ -73,6 +73,7 @@ def get_session( def available_scrapers() -> list[type[data.Scraper]]: + fetchers.load_fetcher_modules() subclasses = [] class_queue = [data.Scraper] while class_queue: diff --git a/test/test_init.py b/test/test_init.py new file mode 100644 index 0000000..19b8563 --- /dev/null +++ b/test/test_init.py @@ -0,0 +1,3 @@ +def test_init(): + import personal_data + assert personal_data.__version__ is not None