diff --git a/.travis.yml b/.travis.yml index 8dede9f..15e5195 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,8 @@ python: - "3.7" - "3.8" # command to install dependencies -install: "pip install pytest pytest-black pytest-cov pytest-mypy pytest-pylint pytest-flake8 coveralls" +install: "pip install pytest pytest-black pytest-cov pylint-isort pytest-mypy pytest-pylint pytest-flake8 coveralls" # command to run tests -script: pytest --black --pylint --pylint-jobs=4 --mypy --cov=pyrad3 --flake8 +script: pytest --black --isort --pylint --pylint-jobs=4 --mypy --flake8 --cov=pyrad3 after_success: - coveralls diff --git a/pyproject.toml b/pyproject.toml index e1a3fea..5071e86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,6 @@ build-backend = "poetry.core.masonry.api" name = "pyrad3" version = "0.1.0" license = "MIT OR Apache-2.0" -requires-python = ">=3.7" readme = "README.md" description = "RADIUS tools" keywords = ["AAA", "authentication", "authorization", "accounting", "RADIUS"] @@ -35,10 +34,14 @@ include = [ [tool.poetry.urls] repository = "https://github.com/pyradius/pyrad3" +[tool.poetry.dependencies] +python = "^3.7" + [tool.poetry.dev-dependencies] +black = "^19.3.10b0" pytest = "^5.4" -pytest-black = "^0.30" +pytest-black = "^0.3.10" pytest-cov = "^2.10" pytest-mypy = "^0.6" pytest-pylint = "^0.17" @@ -49,5 +52,13 @@ line-length = 80 include = '\.py' +[tool.isort] +multi_line_output = 3 +include_trailing_comma = true +use_parentheses = true +line_length = 88 +combine_as_imports = true + + [tool.pylint.messages_control] disable = "bad-continuation" diff --git a/shell.nix b/shell.nix index ad4c0f7..b705fa4 100644 --- a/shell.nix +++ b/shell.nix @@ -8,10 +8,12 @@ pkgs.mkShell { pkgs.python3 pkgs.python3Packages.coveralls pkgs.python3Packages.black + pkgs.python3Packages.poetry pkgs.python3Packages.pytest pkgs.python3Packages.pytest-black pkgs.python3Packages.pytestcov pkgs.python3Packages.pytest-flake8 + pkgs.python3Packages.pytest-isort pkgs.python3Packages.pytest-mypy pkgs.python3Packages.pytest-pylint ]; diff --git a/src/pyrad3/client.py b/src/pyrad3/client.py index 1cfd3c2..3e635bc 100644 --- a/src/pyrad3/client.py +++ b/src/pyrad3/client.py @@ -3,16 +3,15 @@ """Implementation of a simple but extensible RADIUS Client""" -from typing import cast, Optional, Union -from ipaddress import IPv4Address, IPv6Address - import select import socket import time +from ipaddress import IPv4Address, IPv6Address +from typing import Optional, Union, cast import pyrad3.packet as P -from pyrad3.dictionary import Dictionary from pyrad3 import host +from pyrad3.dictionary import Dictionary SUPPORTED_SEND_TYPES = [ P.Code.AccessRequest, diff --git a/src/pyrad3/dictionary.py b/src/pyrad3/dictionary.py index 0614aef..3578c4f 100644 --- a/src/pyrad3/dictionary.py +++ b/src/pyrad3/dictionary.py @@ -6,21 +6,11 @@ Classes and Types to parse and represent a RADIUS dictionary. """ -from enum import IntEnum, Enum, auto -from dataclasses import dataclass -from os.path import dirname, isabs, join, normpath -from typing import ( - Dict, - Generator, - IO, - List, - Optional, - Sequence, - Tuple, - Union, -) - import logging +from dataclasses import dataclass +from enum import Enum, IntEnum, auto +from os.path import dirname, isabs, join, normpath +from typing import IO, Dict, Generator, List, Optional, Sequence, Tuple, Union LOG = logging.getLogger(__name__) diff --git a/src/pyrad3/host.py b/src/pyrad3/host.py index 2c2a747..4341da4 100644 --- a/src/pyrad3/host.py +++ b/src/pyrad3/host.py @@ -3,8 +3,8 @@ """Interface Class for RADIUS Clients and Servers""" -from pyrad3.dictionary import Dictionary from pyrad3 import packet +from pyrad3.dictionary import Dictionary class Host: # pylint: disable=too-many-arguments,too-many-instance-attributes diff --git a/src/pyrad3/packet.py b/src/pyrad3/packet.py index ffbc700..9628973 100644 --- a/src/pyrad3/packet.py +++ b/src/pyrad3/packet.py @@ -3,23 +3,22 @@ """Class for RADIUS Packet""" +import hashlib +import hmac from collections import OrderedDict from secrets import token_bytes from typing import Any, Dict, Optional, Sequence, Tuple, Union -import hashlib -import hmac - -from pyrad3.host import Host from pyrad3.code import Code +from pyrad3.host import Host from pyrad3.utils import ( - PacketError, Attribute, - parse_header, - parse_attributes, + PacketError, calculate_authenticator, - validate_pap_password, + parse_attributes, + parse_header, validate_chap_password, + validate_pap_password, ) HMAC = hmac.new diff --git a/src/pyrad3/tools.py b/src/pyrad3/tools.py index df826f6..8075d1b 100644 --- a/src/pyrad3/tools.py +++ b/src/pyrad3/tools.py @@ -3,17 +3,16 @@ """Collections of functions to en- and decode RADIUS Attributes""" -from typing import Optional, Union +import struct from ipaddress import ( IPv4Address, IPv4Network, IPv6Address, IPv6Network, - ip_network, ip_address, + ip_network, ) - -import struct +from typing import Optional, Union def encode_string(string: str) -> bytes: diff --git a/src/pyrad3/utils.py b/src/pyrad3/utils.py index 5539abc..7e5b7c2 100644 --- a/src/pyrad3/utils.py +++ b/src/pyrad3/utils.py @@ -3,15 +3,14 @@ """Collection of functions to deal with RADIUS packet en- and decoding.""" -from collections import namedtuple -from typing import List, Optional, Tuple, Union - import hashlib import secrets import struct +from collections import namedtuple +from typing import List, Optional, Tuple, Union -from pyrad3.dictionary import Dictionary from pyrad3.code import Code +from pyrad3.dictionary import Dictionary RANDOM_GENERATOR = secrets.SystemRandom() MD5 = hashlib.md5 diff --git a/tests/test_dictionary.py b/tests/test_dictionary.py index 98feb83..ed5b9d1 100644 --- a/tests/test_dictionary.py +++ b/tests/test_dictionary.py @@ -4,6 +4,7 @@ from io import StringIO import pytest + from pyrad3.dictionary import Dictionary, ParseError diff --git a/tests/test_parse_header.py b/tests/test_parse_header.py index acd9d75..2b13f55 100644 --- a/tests/test_parse_header.py +++ b/tests/test_parse_header.py @@ -2,11 +2,12 @@ # SPDX-License-Identifier: MIT OR Apache-2.0 import struct +from ipaddress import IPv4Address, IPv4Network, IPv6Address, IPv6Network -from ipaddress import IPv4Address, IPv6Address, IPv4Network, IPv6Network -from pyrad3 import dictionary, utils import pytest +from pyrad3 import dictionary, utils + # @pytest.mark.parametrize("header", [ # b""]) # def test_valid_header(header):