diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7605714..85eaec6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: hooks: - id: isort - repo: https://github.com/psf/black - rev: 22.12.0 + rev: 23.1.0 hooks: - id: black - repo: https://github.com/PyCQA/flake8 diff --git a/fps/app.py b/fps/app.py index 3b4d38f..d4596db 100644 --- a/fps/app.py +++ b/fps/app.py @@ -31,7 +31,6 @@ def _get_pluggin_manager(hook_type: HookType) -> PluginManager: def _grouped_hookimpls_results( hook: pluggy._hooks._HookCaller, ) -> Dict[ModuleType, List[Callable]]: - plugins = [impl.plugin for impl in hook.get_hookimpls()] result = hook() assert len(plugins) == len(result) @@ -45,7 +44,6 @@ def _grouped_hookimpls_results( def _load_exceptions_handlers(app: FastAPI) -> None: - pm = _get_pluggin_manager(HookType.EXCEPTION) grouped_exceptions_handlers = _grouped_hookimpls_results(pm.hook.exception_handler) @@ -53,7 +51,6 @@ def _load_exceptions_handlers(app: FastAPI) -> None: app.add_exception_handler(RedirectException, _redirect_exception_handler) if grouped_exceptions_handlers: - pkg_names = { get_pkg_name(p, strip_fps=False) for p in grouped_exceptions_handlers } @@ -62,7 +59,7 @@ def _load_exceptions_handlers(app: FastAPI) -> None: for p, exceptions in grouped_exceptions_handlers.items(): p_name = Config.plugin_name(p) - for (exc_class, exc_handler) in exceptions: + for exc_class, exc_handler in exceptions: if exc_class in app.exception_handlers: logger.error( f"Redefinition of handler for '{exc_class}' exception is not allowed." @@ -80,7 +77,6 @@ def _load_exceptions_handlers(app: FastAPI) -> None: def _load_configurations() -> None: - Config.clear_names() Config.clear_models() @@ -97,12 +93,10 @@ def _load_configurations() -> None: grouped_plugin_names = _grouped_hookimpls_results(pm.hook.plugin_name) if plugin_name_impls: - pkg_names = {get_pkg_name(p, strip_fps=False) for p in grouped_plugin_names} logger.info(f"Loading names from plugin package(s) {pkg_names}") for p, plugin_names in grouped_plugin_names.items(): - if not plugin_names: name = Config.register_plugin_name(p) elif len(plugin_names) > 1: @@ -131,7 +125,6 @@ def _load_configurations() -> None: # config values, and load them from files config_impls = pm.hook.config.get_hookimpls() if config_impls: - grouped_configs = _grouped_hookimpls_results(pm.hook.config) pkg_names = {get_pkg_name(p, strip_fps=False) for p in grouped_plugin_names} logger.info(f"Loading configurations from plugin package(s) {pkg_names}") @@ -156,7 +149,6 @@ def _load_configurations() -> None: def _load_routers(app: FastAPI) -> None: - pm = _get_pluggin_manager(HookType.ROUTER) # Ensure any plugins package has a name registered @@ -306,7 +298,6 @@ async def __call__( def create_app(): - logging.getLogger("fps") configure_loggers(logging.root.manager.loggerDict.keys()) diff --git a/fps/config.py b/fps/config.py index 1abb79c..873fb64 100644 --- a/fps/config.py +++ b/fps/config.py @@ -51,7 +51,6 @@ class Config: class Config: - _models: Dict[Type[PluginModel], Tuple[str, PluginModel]] = {} _based_on: Dict[Type[PluginModel], List[str]] = {} _files: Dict[str, dict] = {} diff --git a/fps/hooks.py b/fps/hooks.py index 15827ca..31a6457 100644 --- a/fps/hooks.py +++ b/fps/hooks.py @@ -31,9 +31,9 @@ def router_callback() -> Tuple[APIRouter, Dict[str, Any]]: @pluggy.HookspecMarker(HookType.EXCEPTION.value) -def exception_handler() -> Tuple[ - typing.Union[int, typing.Type[Exception]], typing.Callable -]: +def exception_handler() -> ( + Tuple[typing.Union[int, typing.Type[Exception]], typing.Callable] +): pass @@ -41,9 +41,9 @@ def register_exception_handler( exc_class_or_status_code: typing.Union[int, typing.Type[Exception]], handler: typing.Callable, ): - def exception_handler_callback() -> Tuple[ - typing.Union[int, typing.Type[Exception]], typing.Callable - ]: + def exception_handler_callback() -> ( + Tuple[typing.Union[int, typing.Type[Exception]], typing.Callable] + ): return exc_class_or_status_code, handler return pluggy.HookimplMarker(HookType.EXCEPTION.value)( diff --git a/fps/logging.py b/fps/logging.py index 2ae00a5..1b3e302 100644 --- a/fps/logging.py +++ b/fps/logging.py @@ -17,7 +17,6 @@ class ColouredPercentStyle(PercentStyle): - validation_pattern = re.compile( r"%\(\w+\)[#0+ -]*(\*|\d+)?(\.(\*|\d+))?[diouxefgcrsa]|", re.I ) @@ -146,7 +145,6 @@ def colourized_formatter( def _set_loggers_config(loggers=(), level="info"): - filename = None log_level = level.upper() diff --git a/fps/utils.py b/fps/utils.py index ee0a9e8..0a943d8 100644 --- a/fps/utils.py +++ b/fps/utils.py @@ -10,7 +10,6 @@ def get_caller_module_name(stack_level: int = 1) -> str: - frm = inspect.stack()[stack_level] mod = inspect.getmodule(frm[0]) return mod.__name__ @@ -40,7 +39,6 @@ def get_pkg_name(plugin: Union[str, ModuleType], strip_fps: bool = True) -> str: def get_all_plugins_pkgs_names() -> Set[str]: - names = [] for dist in list(importlib_metadata.distributions()): for ep in dist.entry_points: diff --git a/plugins/helloworld/fps_helloworld/routes.py b/plugins/helloworld/fps_helloworld/routes.py index d7c127d..8404469 100644 --- a/plugins/helloworld/fps_helloworld/routes.py +++ b/plugins/helloworld/fps_helloworld/routes.py @@ -12,7 +12,6 @@ @r.get("/hello") async def root(name: str = "world", config=Depends(get_config)): - if config.random: name = " ".join((name, str(random.randint(0, 250)))) else: diff --git a/plugins/uvicorn/fps_uvicorn/cli.py b/plugins/uvicorn/fps_uvicorn/cli.py index 54822d9..48dd1de 100644 --- a/plugins/uvicorn/fps_uvicorn/cli.py +++ b/plugins/uvicorn/fps_uvicorn/cli.py @@ -83,7 +83,6 @@ def unnested_option(key: str, val: str, root: bool = True) -> Dict[str, Any]: def store_extra_options(options: List[str]): - if options: opts = parse_extra_options(options) f_name = "fps_cli_args.toml" diff --git a/tests/conftest.py b/tests/conftest.py index 7a959ad..58a08f7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,7 +11,6 @@ @pytest.fixture def config_content(): - yield "" diff --git a/tests/test_config.py b/tests/test_config.py index 5131e39..2350809 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -17,7 +17,6 @@ def hookimpl_config(func): def test_forbid_extras(config_file, plugin_manager): - with open(config_file, "w") as f: f.write("[fps]\nsome_extra = 'extra'") @@ -57,7 +56,6 @@ def plugin_name(): ), ) def test_plugin_names(app, plugins): - assert len(Config._plugin2name) == len(plugins) assert Config._plugin2name == {plugins[0]: "some-plugin"} @@ -106,7 +104,6 @@ class Plugin3Config(PluginModel): @classmethod @hookimpl_config def plugin_config(cls): - return cls.Plugin3Config @staticmethod @@ -128,7 +125,6 @@ def plugin_config(): ), ) def test_no_file(self, app, config_file, plugins): - assert self.Plugin3.Plugin3Config in Config._models assert Config._models[self.Plugin3.Plugin3Config] == ( "tests", @@ -153,7 +149,6 @@ def test_no_file(self, app, config_file, plugins): "config_content", (pytest.lazy_fixture(("fps_only_config",))) ) def test_fps_config(self, app, plugins, config_file, config_content): - assert self.Plugin3.Plugin3Config in Config._models assert Config._models[self.Plugin3.Plugin3Config] == ( "tests", @@ -181,7 +176,6 @@ def test_fps_config(self, app, plugins, config_file, config_content): "config_content", (pytest.lazy_fixture(("plugin_config",))) ) def test_plugin_config(self, app, plugins, config_file, config_content): - assert self.Plugin3.Plugin3Config in Config._models assert Config._models[self.Plugin3.Plugin3Config] == ( "tests",