Skip to content

Commit

Permalink
Clean up imports ordering.
Browse files Browse the repository at this point in the history
Follow recommendations from flake8 regarding import order and
grouping.  Put two blank lines after the top import block in each
file.

Import CanError directly from can package in canopen.sdo.client
instead of from canopen.network, where it was not even used.
  • Loading branch information
acolomb committed Oct 18, 2024
1 parent c781a22 commit ffbd10f
Show file tree
Hide file tree
Showing 34 changed files with 89 additions and 54 deletions.
12 changes: 9 additions & 3 deletions canopen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
from canopen.network import Network, NodeScanner
from canopen.node import RemoteNode, LocalNode
from canopen.sdo import SdoCommunicationError, SdoAbortedError
from canopen.objectdictionary import import_od, export_od, ObjectDictionary, ObjectDictionaryError
from canopen.node import LocalNode, RemoteNode
from canopen.objectdictionary import (
ObjectDictionary,
ObjectDictionaryError,
export_od,
import_od,
)
from canopen.profiles.p402 import BaseNode402
from canopen.sdo import SdoAbortedError, SdoCommunicationError

try:
from canopen._version import version as __version__
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion canopen/emcy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import struct
import logging
import struct
import threading
import time
from typing import Callable, List, Optional
Expand Down
4 changes: 2 additions & 2 deletions canopen/lss.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import time
import struct
import queue
import struct
import time

import canopen.network

Expand Down
14 changes: 7 additions & 7 deletions canopen/network.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from __future__ import annotations

from collections.abc import MutableMapping
import logging
import threading
from collections.abc import MutableMapping
from typing import Callable, Dict, Final, Iterator, List, Optional, Union

import can
from can import Listener
from can import CanError

from canopen.node import RemoteNode, LocalNode
from canopen.sync import SyncProducer
from canopen.timestamp import TimeProducer
from canopen.nmt import NmtMaster
from canopen.lss import LssMaster
from canopen.objectdictionary.eds import import_from_node
from canopen.nmt import NmtMaster
from canopen.node import LocalNode, RemoteNode
from canopen.objectdictionary import ObjectDictionary
from canopen.objectdictionary.eds import import_from_node
from canopen.sync import SyncProducer
from canopen.timestamp import TimeProducer


logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion canopen/nmt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import threading
import logging
import struct
import threading
import time
from typing import Callable, Optional, TYPE_CHECKING

Expand Down
2 changes: 1 addition & 1 deletion canopen/node/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from canopen.node.remote import RemoteNode
from canopen.node.local import LocalNode
from canopen.node.remote import RemoteNode
11 changes: 6 additions & 5 deletions canopen/node/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
from typing import Dict, Union

import canopen.network
from canopen.node.base import BaseNode
from canopen.sdo import SdoServer, SdoAbortedError
from canopen.pdo import PDO, TPDO, RPDO
from canopen.nmt import NmtSlave
from canopen import objectdictionary
from canopen.emcy import EmcyProducer
from canopen.nmt import NmtSlave
from canopen.node.base import BaseNode
from canopen.objectdictionary import ObjectDictionary
from canopen import objectdictionary
from canopen.pdo import PDO, RPDO, TPDO
from canopen.sdo import SdoAbortedError, SdoServer


logger = logging.getLogger(__name__)

Expand Down
11 changes: 6 additions & 5 deletions canopen/node/remote.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from __future__ import annotations

import logging
from typing import Union, TextIO
from typing import TextIO, Union

import canopen.network
from canopen.sdo import SdoClient, SdoCommunicationError, SdoAbortedError
from canopen.nmt import NmtMaster
from canopen.emcy import EmcyConsumer
from canopen.pdo import TPDO, RPDO, PDO
from canopen.objectdictionary import ODRecord, ODArray, ODVariable, ObjectDictionary
from canopen.nmt import NmtMaster
from canopen.node.base import BaseNode
from canopen.objectdictionary import ODArray, ODRecord, ODVariable, ObjectDictionary
from canopen.pdo import PDO, RPDO, TPDO
from canopen.sdo import SdoAbortedError, SdoClient, SdoCommunicationError


logger = logging.getLogger(__name__)

Expand Down
6 changes: 4 additions & 2 deletions canopen/objectdictionary/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
"""
Object Dictionary module
"""

from __future__ import annotations

import logging
import struct
from collections.abc import Mapping, MutableMapping
from typing import Dict, Iterator, List, Optional, TextIO, Union
from collections.abc import MutableMapping, Mapping
import logging

from canopen.objectdictionary.datatypes import *
from canopen.objectdictionary.datatypes import IntegerN, UnsignedN
from canopen.utils import pretty_index


logger = logging.getLogger(__name__)


Expand Down
1 change: 1 addition & 0 deletions canopen/objectdictionary/datatypes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import struct


BOOLEAN = 0x1
INTEGER8 = 0x2
INTEGER16 = 0x3
Expand Down
3 changes: 2 additions & 1 deletion canopen/objectdictionary/eds.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import copy
import logging
import re
from configparser import RawConfigParser, NoOptionError, NoSectionError
from configparser import NoOptionError, NoSectionError, RawConfigParser

from canopen import objectdictionary
from canopen.objectdictionary import ObjectDictionary, datatypes
from canopen.sdo import SdoClient


logger = logging.getLogger(__name__)

# Object type. Don't confuse with Data type
Expand Down
3 changes: 2 additions & 1 deletion canopen/objectdictionary/epf.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import xml.etree.ElementTree as etree
import logging
import xml.etree.ElementTree as etree

from canopen import objectdictionary
from canopen.objectdictionary import ObjectDictionary


logger = logging.getLogger(__name__)

DATA_TYPES = {
Expand Down
12 changes: 7 additions & 5 deletions canopen/pdo/base.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
from __future__ import annotations
import threading

import binascii
import logging
import math
from typing import Callable, Dict, Iterator, List, Optional, Union, TYPE_CHECKING
import threading
from collections.abc import Mapping
import logging
import binascii
from typing import Callable, Dict, Iterator, List, Optional, TYPE_CHECKING, Union

import canopen.network
from canopen.sdo import SdoAbortedError
from canopen import objectdictionary
from canopen import variable
from canopen.sdo import SdoAbortedError

if TYPE_CHECKING:
from canopen import LocalNode, RemoteNode
from canopen.pdo import RPDO, TPDO
from canopen.sdo import SdoRecord


PDO_NOT_VALID = 1 << 31
RTR_NOT_ALLOWED = 1 << 30

Expand Down
1 change: 1 addition & 0 deletions canopen/profiles/p402.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from canopen.pdo import PdoMap
from canopen.sdo import SdoCommunicationError


logger = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion canopen/profiles/tools/test_p402_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""

from canopen.objectdictionary import ObjectDictionary
from canopen.profiles.p402 import State402, BaseNode402
from canopen.profiles.p402 import BaseNode402, State402


if __name__ == '__main__':
Expand Down
6 changes: 3 additions & 3 deletions canopen/sdo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from canopen.sdo.base import SdoVariable, SdoRecord, SdoArray
from canopen.sdo.base import SdoArray, SdoRecord, SdoVariable
from canopen.sdo.client import SdoClient
from canopen.sdo.server import SdoServer
from canopen.sdo.exceptions import SdoAbortedError, SdoCommunicationError
from canopen.sdo.server import SdoServer

# Compatibility
from canopen.sdo.base import Variable, Record, Array
from canopen.sdo.base import Array, Record, Variable
2 changes: 1 addition & 1 deletion canopen/sdo/base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

import binascii
from typing import Iterator, Optional, Union
from collections.abc import Mapping
from typing import Iterator, Optional, Union

import canopen.network
from canopen import objectdictionary
Expand Down
12 changes: 7 additions & 5 deletions canopen/sdo/client.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import struct
import logging
import io
import time
import logging
import queue
import struct
import time

from can import CanError

from canopen.network import CanError
from canopen import objectdictionary
from canopen.sdo.base import SdoBase
from canopen.utils import pretty_index
from canopen.sdo.constants import *
from canopen.sdo.exceptions import *
from canopen.utils import pretty_index


logger = logging.getLogger(__name__)

Expand Down
1 change: 1 addition & 0 deletions canopen/sdo/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from canopen.sdo.constants import *
from canopen.sdo.exceptions import *


logger = logging.getLogger(__name__)


Expand Down
3 changes: 2 additions & 1 deletion canopen/timestamp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import time
import struct
import time
from typing import Optional


# 1 Jan 1984
OFFSET = 441763200

Expand Down
1 change: 1 addition & 0 deletions canopen/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Additional utility functions for canopen."""

from typing import Optional, Union


Expand Down
3 changes: 2 additions & 1 deletion canopen/variable.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import logging
from typing import Union
from collections.abc import Mapping
from typing import Union

from canopen import objectdictionary
from canopen.utils import pretty_index


logger = logging.getLogger(__name__)


Expand Down
7 changes: 4 additions & 3 deletions examples/simple_ds402_node.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import canopen
import sys
import os
import sys
import time
import traceback

import time
import canopen


try:

Expand Down
3 changes: 2 additions & 1 deletion test/test_eds.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import canopen
from canopen.objectdictionary.eds import _signed_int_from_hex
from canopen.utils import pretty_index
from .util import SAMPLE_EDS, DATATYPES_EDS, tmp_file

from .util import DATATYPES_EDS, SAMPLE_EDS, tmp_file


class TestEDS(unittest.TestCase):
Expand Down
1 change: 1 addition & 0 deletions test/test_emcy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from contextlib import contextmanager

import can

import canopen
from canopen.emcy import EmcyError

Expand Down
1 change: 1 addition & 0 deletions test/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import unittest

import canopen

from .util import SAMPLE_EDS


Expand Down
5 changes: 3 additions & 2 deletions test/test_network.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import logging
import threading
import time
import unittest

import canopen
import can

import canopen

from .util import SAMPLE_EDS


Expand Down
4 changes: 3 additions & 1 deletion test/test_nmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import unittest

import can

import canopen
from canopen.nmt import COMMAND_TO_STATE, NMT_STATES, NMT_COMMANDS, NmtError
from canopen.nmt import COMMAND_TO_STATE, NMT_COMMANDS, NMT_STATES, NmtError

from .util import SAMPLE_EDS


Expand Down
1 change: 1 addition & 0 deletions test/test_od.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest

from canopen import objectdictionary as od


Expand Down
1 change: 1 addition & 0 deletions test/test_pdo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest

import canopen

from .util import SAMPLE_EDS, tmp_file


Expand Down
3 changes: 2 additions & 1 deletion test/test_sdo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import canopen
import canopen.objectdictionary.datatypes as dt
from canopen.objectdictionary import ODVariable
from .util import SAMPLE_EDS, DATATYPES_EDS

from .util import DATATYPES_EDS, SAMPLE_EDS


TX = 1
Expand Down
1 change: 1 addition & 0 deletions test/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import unittest

import can

import canopen


Expand Down
Loading

0 comments on commit ffbd10f

Please sign in to comment.