mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-30 05:44:27 +02:00
fix: defer plugin entrypoint loading until runtime
Fixes simonw/sqlite-utils#713
This commit is contained in:
parent
8d74ffc932
commit
974fe2f82f
3 changed files with 11 additions and 4 deletions
|
|
@ -14,7 +14,7 @@ from sqlite_utils.db import (
|
||||||
NoTable,
|
NoTable,
|
||||||
quote_identifier,
|
quote_identifier,
|
||||||
)
|
)
|
||||||
from sqlite_utils.plugins import pm, get_plugins
|
from sqlite_utils.plugins import ensure_plugins_loaded, pm, get_plugins
|
||||||
from sqlite_utils.utils import maximize_csv_field_size_limit
|
from sqlite_utils.utils import maximize_csv_field_size_limit
|
||||||
from sqlite_utils import recipes
|
from sqlite_utils import recipes
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
@ -3264,6 +3264,7 @@ def plugins_list():
|
||||||
click.echo(json.dumps(get_plugins(), indent=2))
|
click.echo(json.dumps(get_plugins(), indent=2))
|
||||||
|
|
||||||
|
|
||||||
|
ensure_plugins_loaded()
|
||||||
pm.hook.register_commands(cli=cli)
|
pm.hook.register_commands(cli=cli)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ from typing import (
|
||||||
Tuple,
|
Tuple,
|
||||||
)
|
)
|
||||||
import uuid
|
import uuid
|
||||||
from sqlite_utils.plugins import pm
|
from sqlite_utils.plugins import ensure_plugins_loaded, pm
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from sqlite_dump import iterdump # type: ignore[import-not-found]
|
from sqlite_dump import iterdump # type: ignore[import-not-found]
|
||||||
|
|
@ -382,6 +382,7 @@ class Database:
|
||||||
self._registered_functions: set = set()
|
self._registered_functions: set = set()
|
||||||
self.use_counts_table = use_counts_table
|
self.use_counts_table = use_counts_table
|
||||||
if execute_plugins:
|
if execute_plugins:
|
||||||
|
ensure_plugins_loaded()
|
||||||
pm.hook.prepare_connection(conn=self.conn)
|
pm.hook.prepare_connection(conn=self.conn)
|
||||||
self.strict = strict
|
self.strict = strict
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,15 @@ from . import hookspecs
|
||||||
|
|
||||||
pm: pluggy.PluginManager = pluggy.PluginManager("sqlite_utils")
|
pm: pluggy.PluginManager = pluggy.PluginManager("sqlite_utils")
|
||||||
pm.add_hookspecs(hookspecs)
|
pm.add_hookspecs(hookspecs)
|
||||||
|
_plugins_loaded = False
|
||||||
|
|
||||||
if not getattr(sys, "_called_from_test", False):
|
|
||||||
# Only load plugins if not running tests
|
def ensure_plugins_loaded() -> None:
|
||||||
|
global _plugins_loaded
|
||||||
|
if _plugins_loaded or getattr(sys, "_called_from_test", False):
|
||||||
|
return
|
||||||
pm.load_setuptools_entrypoints("sqlite_utils")
|
pm.load_setuptools_entrypoints("sqlite_utils")
|
||||||
|
_plugins_loaded = True
|
||||||
|
|
||||||
|
|
||||||
def get_plugins() -> List[Dict[str, Union[str, List[str]]]]:
|
def get_plugins() -> List[Dict[str, Union[str, List[str]]]]:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue