Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove PY3.8 support; Add PY3.13 support #979

Merged
merged 7 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
shell: bash
strategy:
matrix:
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]
python-version: [ '3.9', '3.10', '3.11', '3.12', '3.13' ]
platform: [ubuntu-latest, macos-13, windows-2019]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ What Nornir brings to the table is that it takes care of dealing with your inven
Install
=======

Please note that Nornir requires Python 3.8 or higher. Install Nornir with pip.
Please note that Nornir requires Python 3.9 or higher. Install Nornir with pip.

```
pip install nornir
Expand Down
104 changes: 52 additions & 52 deletions docs/tutorial/processors.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -234,117 +234,117 @@
"output_type": "stream",
"text": [
"{\n",
" \"hi!\": {\n",
" \"started\": true,\n",
" \"bye!\": {\n",
" \"completed\": true,\n",
" \"host1.bma\": {\n",
" \"completed\": true,\n",
" \"result\": \"bye! my name is host1.bma\"\n",
" },\n",
" \"host1.cmh\": {\n",
" \"completed\": true,\n",
" \"result\": \"hi! my name is host1.cmh\"\n",
" \"result\": \"bye! my name is host1.cmh\"\n",
" },\n",
" \"host2.cmh\": {\n",
" \"host2.bma\": {\n",
" \"completed\": true,\n",
" \"result\": \"hi! my name is host2.cmh\"\n",
" \"result\": \"bye! my name is host2.bma\"\n",
" },\n",
" \"spine00.cmh\": {\n",
" \"host2.cmh\": {\n",
" \"completed\": true,\n",
" \"result\": \"hi! my name is spine00.cmh\"\n",
" \"result\": \"bye! my name is host2.cmh\"\n",
" },\n",
" \"spine01.cmh\": {\n",
" \"leaf00.bma\": {\n",
" \"completed\": true,\n",
" \"result\": \"hi! my name is spine01.cmh\"\n",
" \"result\": \"bye! my name is leaf00.bma\"\n",
" },\n",
" \"leaf00.cmh\": {\n",
" \"completed\": true,\n",
" \"result\": \"hi! my name is leaf00.cmh\"\n",
" \"result\": \"bye! my name is leaf00.cmh\"\n",
" },\n",
" \"leaf01.cmh\": {\n",
" \"leaf01.bma\": {\n",
" \"completed\": true,\n",
" \"result\": \"hi! my name is leaf01.cmh\"\n",
" \"result\": \"bye! my name is leaf01.bma\"\n",
" },\n",
" \"host1.bma\": {\n",
" \"leaf01.cmh\": {\n",
" \"completed\": true,\n",
" \"result\": \"hi! my name is host1.bma\"\n",
" \"result\": \"bye! my name is leaf01.cmh\"\n",
" },\n",
" \"host2.bma\": {\n",
" \"spine00.bma\": {\n",
" \"completed\": true,\n",
" \"result\": \"hi! my name is host2.bma\"\n",
" \"result\": \"bye! my name is spine00.bma\"\n",
" },\n",
" \"spine00.bma\": {\n",
" \"spine00.cmh\": {\n",
" \"completed\": true,\n",
" \"result\": \"hi! my name is spine00.bma\"\n",
" \"result\": \"bye! my name is spine00.cmh\"\n",
" },\n",
" \"spine01.bma\": {\n",
" \"completed\": true,\n",
" \"result\": \"hi! my name is spine01.bma\"\n",
" \"result\": \"bye! my name is spine01.bma\"\n",
" },\n",
" \"leaf00.bma\": {\n",
" \"spine01.cmh\": {\n",
" \"completed\": true,\n",
" \"result\": \"hi! my name is leaf00.bma\"\n",
" \"result\": \"bye! my name is spine01.cmh\"\n",
" },\n",
" \"leaf01.bma\": {\n",
" \"started\": true\n",
" },\n",
" \"hi!\": {\n",
" \"completed\": true,\n",
" \"host1.bma\": {\n",
" \"completed\": true,\n",
" \"result\": \"hi! my name is leaf01.bma\"\n",
" \"result\": \"hi! my name is host1.bma\"\n",
" },\n",
" \"completed\": true\n",
" },\n",
" \"bye!\": {\n",
" \"started\": true,\n",
" \"host1.cmh\": {\n",
" \"completed\": true,\n",
" \"result\": \"bye! my name is host1.cmh\"\n",
" \"result\": \"hi! my name is host1.cmh\"\n",
" },\n",
" \"host2.cmh\": {\n",
" \"host2.bma\": {\n",
" \"completed\": true,\n",
" \"result\": \"bye! my name is host2.cmh\"\n",
" \"result\": \"hi! my name is host2.bma\"\n",
" },\n",
" \"spine00.cmh\": {\n",
" \"host2.cmh\": {\n",
" \"completed\": true,\n",
" \"result\": \"bye! my name is spine00.cmh\"\n",
" \"result\": \"hi! my name is host2.cmh\"\n",
" },\n",
" \"spine01.cmh\": {\n",
" \"leaf00.bma\": {\n",
" \"completed\": true,\n",
" \"result\": \"bye! my name is spine01.cmh\"\n",
" \"result\": \"hi! my name is leaf00.bma\"\n",
" },\n",
" \"leaf00.cmh\": {\n",
" \"completed\": true,\n",
" \"result\": \"bye! my name is leaf00.cmh\"\n",
" },\n",
" \"leaf01.cmh\": {\n",
" \"completed\": true,\n",
" \"result\": \"bye! my name is leaf01.cmh\"\n",
" \"result\": \"hi! my name is leaf00.cmh\"\n",
" },\n",
" \"host1.bma\": {\n",
" \"leaf01.bma\": {\n",
" \"completed\": true,\n",
" \"result\": \"bye! my name is host1.bma\"\n",
" \"result\": \"hi! my name is leaf01.bma\"\n",
" },\n",
" \"host2.bma\": {\n",
" \"leaf01.cmh\": {\n",
" \"completed\": true,\n",
" \"result\": \"bye! my name is host2.bma\"\n",
" \"result\": \"hi! my name is leaf01.cmh\"\n",
" },\n",
" \"spine00.bma\": {\n",
" \"completed\": true,\n",
" \"result\": \"bye! my name is spine00.bma\"\n",
" \"result\": \"hi! my name is spine00.bma\"\n",
" },\n",
" \"spine01.bma\": {\n",
" \"spine00.cmh\": {\n",
" \"completed\": true,\n",
" \"result\": \"bye! my name is spine01.bma\"\n",
" \"result\": \"hi! my name is spine00.cmh\"\n",
" },\n",
" \"leaf00.bma\": {\n",
" \"spine01.bma\": {\n",
" \"completed\": true,\n",
" \"result\": \"bye! my name is leaf00.bma\"\n",
" \"result\": \"hi! my name is spine01.bma\"\n",
" },\n",
" \"leaf01.bma\": {\n",
" \"spine01.cmh\": {\n",
" \"completed\": true,\n",
" \"result\": \"bye! my name is leaf01.bma\"\n",
" \"result\": \"hi! my name is spine01.cmh\"\n",
" },\n",
" \"completed\": true\n",
" \"started\": true\n",
" }\n",
"}\n"
]
}
],
"source": [
"import json\n",
"print(json.dumps(data, indent=4))"
"print(json.dumps(data, indent=4, sort_keys=True))"
]
},
{
Expand Down
38 changes: 22 additions & 16 deletions nornir/core/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
import warnings
from pathlib import Path
from typing import Any, Dict, List, Optional, Type, TypeVar
from typing import Any, Dict, Generic, List, Optional, Type, TypeVar

import ruamel.yaml

Expand All @@ -16,7 +16,7 @@
T = TypeVar("T")


class Parameter:
class Parameter(Generic[T]):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looked like the recommended way to enforce type consistency i.e. that a Parameter that was a 'str' was consistently required to be a 'str').

There were some mypy issues until I did this.

def __init__(
self,
envvar: str,
Expand Down Expand Up @@ -47,14 +47,18 @@ def resolve(self, value: Optional[T]) -> T:

if v is None:
v = self.default

if not isinstance(v, self.type):
raise TypeError(f"Expected type {self.type}, got {type(v)}")

return v


class SSHConfig:
__slots__ = ("config_file",)

class Parameters:
config_file = Parameter(default=DEFAULT_SSH_CONFIG, envvar="NORNIR_SSH_CONFIG_FILE")
config_file = Parameter[str](default=DEFAULT_SSH_CONFIG, envvar="NORNIR_SSH_CONFIG_FILE")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a secondary requirement of using Parameter(Generic[T])


def __init__(self, config_file: Optional[str] = None) -> None:
self.config_file = self.Parameters.config_file.resolve(config_file)
Expand All @@ -67,10 +71,12 @@ class InventoryConfig:
__slots__ = "options", "plugin", "transform_function", "transform_function_options"

class Parameters:
plugin = Parameter(typ=str, default="SimpleInventory", envvar="NORNIR_INVENTORY_PLUGIN")
options = Parameter(default={}, envvar="NORNIR_INVENTORY_OPTIONS")
transform_function = Parameter(typ=str, envvar="NORNIR_INVENTORY_TRANSFORM_FUNCTION")
transform_function_options = Parameter(
plugin = Parameter[str](
typ=str, default="SimpleInventory", envvar="NORNIR_INVENTORY_PLUGIN"
)
options = Parameter[Dict[str, Any]](default={}, envvar="NORNIR_INVENTORY_OPTIONS")
transform_function = Parameter[str](typ=str, envvar="NORNIR_INVENTORY_TRANSFORM_FUNCTION")
transform_function_options = Parameter[Dict[str, Any]](
default={}, envvar="NORNIR_INVENTORY_TRANSFORM_FUNCTION_OPTIONS"
)

Expand Down Expand Up @@ -101,15 +107,15 @@ class LoggingConfig:
__slots__ = "enabled", "format", "level", "log_file", "loggers", "to_console"

class Parameters:
enabled = Parameter(default=True, envvar="NORNIR_LOGGING_ENABLED")
level = Parameter(default="INFO", envvar="NORNIR_LOGGING_LEVEL")
log_file = Parameter(default="nornir.log", envvar="NORNIR_LOGGING_LOG_FILE")
format = Parameter(
enabled = Parameter[bool](default=True, envvar="NORNIR_LOGGING_ENABLED")
level = Parameter[str](default="INFO", envvar="NORNIR_LOGGING_LEVEL")
log_file = Parameter[str](default="nornir.log", envvar="NORNIR_LOGGING_LOG_FILE")
format = Parameter[str](
default="%(asctime)s - %(name)12s - %(levelname)8s - %(funcName)10s() - %(message)s",
envvar="NORNIR_LOGGING_FORMAT",
)
to_console = Parameter(default=False, envvar="NORNIR_LOGGING_TO_CONSOLE")
loggers = Parameter(default=["nornir"], envvar="NORNIR_LOGGING_LOGGERS")
to_console = Parameter[bool](default=False, envvar="NORNIR_LOGGING_TO_CONSOLE")
loggers = Parameter[List[str]](default=["nornir"], envvar="NORNIR_LOGGING_LOGGERS")

def __init__(
self,
Expand Down Expand Up @@ -194,8 +200,8 @@ class RunnerConfig:
__slots__ = ("options", "plugin")

class Parameters:
plugin = Parameter(default="threaded", envvar="NORNIR_RUNNER_PLUGIN")
options = Parameter(default={}, envvar="NORNIR_RUNNER_OPTIONS")
plugin = Parameter[str](default="threaded", envvar="NORNIR_RUNNER_PLUGIN")
options = Parameter[Dict[str, Any]](default={}, envvar="NORNIR_RUNNER_OPTIONS")

def __init__(
self, plugin: Optional[str] = None, options: Optional[Dict[str, Any]] = None
Expand All @@ -214,7 +220,7 @@ class CoreConfig:
__slots__ = ("raise_on_error",)

class Parameters:
raise_on_error = Parameter(default=False, envvar="NORNIR_CORE_RAISE_ON_ERROR")
raise_on_error = Parameter[bool](default=False, envvar="NORNIR_CORE_RAISE_ON_ERROR")

def __init__(self, raise_on_error: Optional[bool] = None) -> None:
self.raise_on_error = self.Parameters.raise_on_error.resolve(raise_on_error)
Expand Down
Loading
Loading