Skip to content

Commit

Permalink
Merge pull request #94 from jupyter-server/pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
[pre-commit.ci] pre-commit autoupdate
  • Loading branch information
davidbrochart authored Feb 7, 2023
2 parents 6480db6 + 660d814 commit 8a2a697
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 1 addition & 10 deletions fps/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -45,15 +44,13 @@ 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)

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
}
Expand All @@ -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."
Expand All @@ -80,7 +77,6 @@ def _load_exceptions_handlers(app: FastAPI) -> None:


def _load_configurations() -> None:

Config.clear_names()
Config.clear_models()

Expand All @@ -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:
Expand Down Expand Up @@ -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}")
Expand All @@ -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
Expand Down Expand Up @@ -306,7 +298,6 @@ async def __call__(


def create_app():

logging.getLogger("fps")
configure_loggers(logging.root.manager.loggerDict.keys())

Expand Down
1 change: 0 additions & 1 deletion fps/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}
Expand Down
12 changes: 6 additions & 6 deletions fps/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ 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


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)(
Expand Down
2 changes: 0 additions & 2 deletions fps/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


class ColouredPercentStyle(PercentStyle):

validation_pattern = re.compile(
r"%\(\w+\)[#0+ -]*(\*|\d+)?(\.(\*|\d+))?[diouxefgcrsa]|", re.I
)
Expand Down Expand Up @@ -146,7 +145,6 @@ def colourized_formatter(


def _set_loggers_config(loggers=(), level="info"):

filename = None
log_level = level.upper()

Expand Down
2 changes: 0 additions & 2 deletions fps/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion plugins/helloworld/fps_helloworld/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion plugins/uvicorn/fps_uvicorn/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

@pytest.fixture
def config_content():

yield ""


Expand Down
6 changes: 0 additions & 6 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'")

Expand Down Expand Up @@ -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"}

Expand Down Expand Up @@ -106,7 +104,6 @@ class Plugin3Config(PluginModel):
@classmethod
@hookimpl_config
def plugin_config(cls):

return cls.Plugin3Config

@staticmethod
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 8a2a697

Please sign in to comment.