Skip to content

Commit

Permalink
Add property for optional runner
Browse files Browse the repository at this point in the history
  • Loading branch information
ogenstad committed Jun 8, 2024
1 parent 3bafdd9 commit a801978
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 9 additions & 1 deletion nornir/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import TYPE_CHECKING, Any, Callable, Dict, Generator, List, Optional, Type

from nornir.core.configuration import Config
from nornir.core.exceptions import PluginNotRegistered
from nornir.core.inventory import Inventory
from nornir.core.plugins.runners import RunnerPlugin
from nornir.core.processor import Processor, Processors
Expand Down Expand Up @@ -46,7 +47,7 @@ def __init__(
self.inventory = inventory
self.config = config or Config()
self.processors = processors or Processors()
self.runner = runner
self._runner = runner

def __enter__(self) -> "Nornir":
return self
Expand Down Expand Up @@ -168,6 +169,13 @@ def close_connections_task(task):

self.run(task=close_connections_task, on_good=on_good, on_failed=on_failed)

@property
def runner(self) -> RunnerPlugin:
if self._runner:
return self._runner

raise PluginNotRegistered("Runner plugin not registered")

@classmethod
def get_validators(cls) -> Generator[Callable[["Nornir"], "Nornir"], None, None]:
yield cls.validate
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ warn_redundant_casts = True
[mypy-nornir.core]
disallow_untyped_defs = False
disallow_incomplete_defs = False
strict_optional = False

[mypy-tests.*]
ignore_errors = True

0 comments on commit a801978

Please sign in to comment.