Skip to content

Commit

Permalink
add isort to manage/sort imports
Browse files Browse the repository at this point in the history
  • Loading branch information
nemith committed Sep 22, 2023
1 parent d8c547c commit dd8793a
Show file tree
Hide file tree
Showing 29 changed files with 108 additions and 73 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pytest:
.PHONY: black
black:
poetry run black --check ${NORNIR_DIRS}
poetry run isort --check ${NORNIR_DIRS}

.PHONY: sphinx
sphinx:
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import sys
from typing import Dict

from nornir import __version__

from sphinx.application import Sphinx

from nornir import __version__

sys.path.insert(0, os.path.abspath("../"))


Expand Down
2 changes: 0 additions & 2 deletions docs/highlighter.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from IPython.core.magic import register_line_magic
from IPython.display import HTML

from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import get_lexer_for_filename


HTML_TEMPLATE = """<style>
{}
</style>
Expand Down
2 changes: 1 addition & 1 deletion nornir/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import logging.config
from typing import List, Optional, TYPE_CHECKING
from typing import TYPE_CHECKING, List, Optional

from nornir.core.configuration import Config
from nornir.core.inventory import Inventory
Expand Down
6 changes: 3 additions & 3 deletions nornir/core/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import sys
import warnings
from pathlib import Path
from typing import Any, Dict, Optional, Type, TYPE_CHECKING, List, TypeVar

from nornir.core.exceptions import ConflictingConfigurationWarning
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Type, TypeVar

import ruamel.yaml

from nornir.core.exceptions import ConflictingConfigurationWarning

if TYPE_CHECKING:
from nornir.core.deserializer.inventory import Inventory # noqa

Expand Down
2 changes: 1 addition & 1 deletion nornir/core/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, TYPE_CHECKING
from typing import TYPE_CHECKING, Dict

if TYPE_CHECKING:
from nornir.core.connection import Connection
Expand Down
18 changes: 7 additions & 11 deletions nornir/core/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@
Any,
Callable,
Dict,
ItemsView,
Iterator,
KeysView,
List,
Optional,
Set,
TypeVar,
Union,
KeysView,
ValuesView,
ItemsView,
Iterator,
TypeVar,
)

from nornir.core.configuration import Config
from nornir.core.plugins.connections import (
ConnectionPlugin,
ConnectionPluginRegister,
)
from nornir.core.exceptions import ConnectionAlreadyOpen, ConnectionNotOpen

from mypy_extensions import Arg, KwArg

from nornir.core.configuration import Config
from nornir.core.exceptions import ConnectionAlreadyOpen, ConnectionNotOpen
from nornir.core.plugins.connections import ConnectionPlugin, ConnectionPluginRegister

HostOrGroup = TypeVar("HostOrGroup", "Host", "Group")

Expand Down
3 changes: 1 addition & 2 deletions nornir/core/plugins/connections.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Any, Dict, Type, Optional, Protocol
from typing import Any, Dict, Optional, Protocol, Type

from nornir.core.configuration import Config
from nornir.core.plugins.register import PluginRegister


CONNECTIONS_PLUGIN_PATH = "nornir.plugins.connections"


Expand Down
3 changes: 1 addition & 2 deletions nornir/core/plugins/inventory.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Any, Type, Protocol
from typing import Any, Protocol, Type

from nornir.core.inventory import Inventory, TransformFunction
from nornir.core.plugins.register import PluginRegister


INVENTORY_PLUGIN_PATH = "nornir.plugins.inventory"
TRANSFORM_FUNCTION_PLUGIN_PATH = "nornir.plugins.transform_function"

Expand Down
7 changes: 2 additions & 5 deletions nornir/core/plugins/register.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import sys
from typing import Dict, TypeVar, Generic
from typing import Dict, Generic, TypeVar

from nornir.core.exceptions import (
PluginAlreadyRegistered,
PluginNotRegistered,
)
from nornir.core.exceptions import PluginAlreadyRegistered, PluginNotRegistered

if sys.version_info >= (3, 10):
from importlib import metadata
Expand Down
5 changes: 2 additions & 3 deletions nornir/core/plugins/runners.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Any, List, Type, Protocol
from typing import Any, List, Protocol, Type

from nornir.core.task import AggregatedResult, Task
from nornir.core.inventory import Host
from nornir.core.plugins.register import PluginRegister

from nornir.core.task import AggregatedResult, Task

RUNNERS_PLUGIN_PATH = "nornir.plugins.runners"

Expand Down
2 changes: 2 additions & 0 deletions nornir/core/processor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import List, Protocol

from typing_extensions import Protocol

from nornir.core.inventory import Host
from nornir.core.task import AggregatedResult, MultiResult, Task

Expand Down
2 changes: 1 addition & 1 deletion nornir/core/state.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Set, Optional
from typing import Any, Dict, Optional, Set


class GlobalState(object):
Expand Down
5 changes: 2 additions & 3 deletions nornir/core/task.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import logging
import traceback
from typing import Any, Callable, Dict, List, Optional, TYPE_CHECKING, Union, cast
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union, cast

from nornir.core.exceptions import NornirExecutionError
from nornir.core.exceptions import NornirSubTaskError
from nornir.core.exceptions import NornirExecutionError, NornirSubTaskError

if TYPE_CHECKING:
from nornir.core import Nornir
Expand Down
2 changes: 1 addition & 1 deletion nornir/init_nornir.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from nornir.core import Nornir
from nornir.core.configuration import Config
from nornir.core.inventory import Inventory
from nornir.core.plugins.connections import ConnectionPluginRegister
from nornir.core.plugins.inventory import (
InventoryPluginRegister,
TransformFunctionRegister,
)
from nornir.core.plugins.connections import ConnectionPluginRegister
from nornir.core.plugins.runners import RunnerPlugin, RunnersPluginRegister
from nornir.core.state import GlobalState

Expand Down
12 changes: 6 additions & 6 deletions nornir/plugins/inventory/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
import pathlib
from typing import Any, Dict, Type

import ruamel.yaml

from nornir.core.inventory import (
Inventory,
ConnectionOptions,
Defaults,
Group,
Groups,
Host,
Hosts,
Defaults,
ConnectionOptions,
HostOrGroup,
Hosts,
Inventory,
ParentGroups,
)

import ruamel.yaml

logger = logging.getLogger(__name__)


Expand Down
4 changes: 2 additions & 2 deletions nornir/plugins/runners/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import List
from concurrent.futures import ThreadPoolExecutor
from typing import List

from nornir.core.task import AggregatedResult, Task
from nornir.core.inventory import Host
from nornir.core.task import AggregatedResult, Task


class SerialRunner:
Expand Down
45 changes: 45 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ types-pkg-resources = "^0.1.3"
nornir-jinja2 = "0.2.0"
nornir-utils = "0.2.0"
nornir-napalm = "0.4.0"
isort = "^5.12.0"

[tool.poetry.group.docs.dependencies]
sphinx = "6.2.1"
Expand All @@ -56,3 +57,5 @@ nbsphinx = "0.9.2"
pygments = "2.16.1"
sphinx-issues = "3.0.1"

[tool.isort]
profile = "black"
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

import pytest

skip = pytest.mark.skipif(
Expand Down
22 changes: 11 additions & 11 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from typing import List
import os
from typing import List

import pytest
import ruamel.yaml

from nornir.core import Nornir
from nornir.core.inventory import (
Inventory,
Host,
Hosts,
ConnectionOptions,
Defaults,
Group,
Groups,
Defaults,
Host,
Hosts,
Inventory,
ParentGroups,
ConnectionOptions,
)
from nornir.core.task import AggregatedResult, Task
from nornir.core.state import GlobalState

import ruamel.yaml
import pytest

from nornir.core.task import AggregatedResult, Task

global_data = GlobalState(dry_run=True)

Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_InitNornir.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import logging
import logging.config
import os

import pytest

from nornir import InitNornir
from nornir.core.exceptions import ConflictingConfigurationWarning
from nornir.core.inventory import Inventory, Host, Hosts, Groups, Group, Defaults
from nornir.core.inventory import Defaults, Group, Groups, Host, Hosts, Inventory
from nornir.core.plugins.inventory import (
InventoryPluginRegister,
TransformFunctionRegister,
)


dir_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "test_InitNornir")

LOGGING_DICT = {
Expand Down
Loading

0 comments on commit dd8793a

Please sign in to comment.