diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 18edd38..84e8298 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,6 +24,13 @@ repos: language: system require_serial: true types_or: [python, pyi] + - id: isort + name: isort + args: ["--check", "--diff"] + entry: poetry run isort + language: system + require_serial: true + types_or: [python, pyi] - id: reuse name: reuse entry: poetry run reuse diff --git a/examples/test_client.py b/examples/test_client.py index fac62be..5006852 100644 --- a/examples/test_client.py +++ b/examples/test_client.py @@ -20,22 +20,20 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +from asyncio import ensure_future, gather, get_event_loop +import base64 +import hashlib import logging import struct import time -from asyncio import get_event_loop, gather, ensure_future from colorlog import ColoredFormatter - from secret_handshake.network import SHSClient + from ssb.muxrpc import MuxRPCAPI, MuxRPCAPIException from ssb.packet_stream import PacketStream, PSMessageType from ssb.util import load_ssb_secret -import hashlib -import base64 - - api = MuxRPCAPI() diff --git a/examples/test_server.py b/examples/test_server.py index 8150f6b..46ac6b4 100644 --- a/examples/test_server.py +++ b/examples/test_server.py @@ -20,14 +20,14 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +from asyncio import ensure_future, gather, get_event_loop import logging -from asyncio import gather, get_event_loop, ensure_future from colorlog import ColoredFormatter - from secret_handshake import SHSServer -from ssb.packet_stream import PacketStream + from ssb.muxrpc import MuxRPCAPI +from ssb.packet_stream import PacketStream from ssb.util import load_ssb_secret api = MuxRPCAPI() diff --git a/poetry.lock b/poetry.lock index 47ca8af..95092f8 100644 --- a/poetry.lock +++ b/poetry.lock @@ -509,20 +509,20 @@ files = [ [[package]] name = "isort" -version = "4.3.21" +version = "5.12.0" description = "A Python utility / library to sort Python imports." optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +python-versions = ">=3.8.0" files = [ - {file = "isort-4.3.21-py2.py3-none-any.whl", hash = "sha256:6e811fcb295968434526407adb8796944f1988c5b65e8139058f2014cbe100fd"}, - {file = "isort-4.3.21.tar.gz", hash = "sha256:54da7e92468955c4fceacd0c86bd0ec997b0e1ee80d97f67c35a78b719dccab1"}, + {file = "isort-5.12.0-py3-none-any.whl", hash = "sha256:f84c2818376e66cf843d497486ea8fed8700b340f308f076c6fb1229dff318b6"}, + {file = "isort-5.12.0.tar.gz", hash = "sha256:8bef7dde241278824a6d83f44a544709b065191b95b6e50894bdc722fcba0504"}, ] [package.extras] -pipfile = ["pipreqs", "requirementslib"] -pyproject = ["toml"] -requirements = ["pip-api", "pipreqs"] -xdg-home = ["appdirs (>=1.4.0)"] +colors = ["colorama (>=0.4.3)"] +pipfile-deprecated-finder = ["pip-shims (>=0.5.2)", "pipreqs", "requirementslib"] +plugins = ["setuptools"] +requirements-deprecated-finder = ["pip-api", "pipreqs"] [[package]] name = "jinja2" @@ -1241,4 +1241,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "68f8505b0bc199dbcf9d3ea4ae37ee43f36128d05427ea99bd3a09fb201bcd72" +content-hash = "4eb60a723d8be38d3d197522f58d19f4bdae3887bd006d13ab87fb058c75b467" diff --git a/pyproject.toml b/pyproject.toml index e65c003..b00849c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ black = "^23.10.1" check-manifest = "^0.39" commitizen = "^3.12.0" coverage = "^7.3.2" -isort = "^4.3.20" +isort = "^5.12.0" pep257 = "^0.7.0" pytest = "^7.4.3" pytest-asyncio = "^0.21.1" @@ -45,6 +45,11 @@ skip_covered = true fail_under = 70 omit = ["examples/*"] +[tool.isort] +force_sort_within_sections = true +line_length = 120 +profile = "black" + [tool.pytest.ini_options] addopts = ["--cov=.", "--no-cov-on-fail"] python_files = ["tests/test_*.py"] diff --git a/ssb/feed/__init__.py b/ssb/feed/__init__.py index f09dad4..75be4ca 100644 --- a/ssb/feed/__init__.py +++ b/ssb/feed/__init__.py @@ -20,6 +20,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from .models import Feed, LocalFeed, Message, LocalMessage, NoPrivateKeyException +from .models import Feed, LocalFeed, LocalMessage, Message, NoPrivateKeyException __all__ = ("Feed", "LocalFeed", "Message", "LocalMessage", "NoPrivateKeyException") diff --git a/ssb/feed/models.py b/ssb/feed/models.py index 097b516..9114c4b 100644 --- a/ssb/feed/models.py +++ b/ssb/feed/models.py @@ -20,16 +20,15 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -import datetime from base64 import b64encode -from collections import namedtuple, OrderedDict +from collections import OrderedDict, namedtuple +import datetime from hashlib import sha256 from simplejson import dumps, loads from ssb.util import tag - OrderedMsg = namedtuple("OrderedMsg", ("previous", "author", "sequence", "timestamp", "hash", "content")) diff --git a/ssb/packet_stream.py b/ssb/packet_stream.py index bb18504..8e3c390 100644 --- a/ssb/packet_stream.py +++ b/ssb/packet_stream.py @@ -20,18 +20,16 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -import logging -import struct from asyncio import Event, Queue from enum import Enum -from time import time +import logging from math import ceil +import struct +from time import time -import simplejson from async_generator import async_generator, yield_ - from secret_handshake import SHSClient, SHSServer - +import simplejson logger = logging.getLogger("packet_stream") diff --git a/ssb/util.py b/ssb/util.py index 281d248..e6e0270 100644 --- a/ssb/util.py +++ b/ssb/util.py @@ -20,11 +20,11 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -import os -import yaml from base64 import b64decode, b64encode +import os from nacl.signing import SigningKey +import yaml class ConfigException(Exception): diff --git a/tests/test_feed.py b/tests/test_feed.py index 146c12a..c32521e 100644 --- a/tests/test_feed.py +++ b/tests/test_feed.py @@ -23,11 +23,10 @@ from base64 import b64decode from collections import OrderedDict -import pytest from nacl.signing import SigningKey, VerifyKey +import pytest -from ssb.feed import LocalMessage, LocalFeed, Feed, Message, NoPrivateKeyException - +from ssb.feed import Feed, LocalFeed, LocalMessage, Message, NoPrivateKeyException SERIALIZED_M1 = b"""{ "previous": null, diff --git a/tests/test_packet_stream.py b/tests/test_packet_stream.py index f6bdbdd..79f95c3 100644 --- a/tests/test_packet_stream.py +++ b/tests/test_packet_stream.py @@ -20,13 +20,13 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +from asyncio import Event, ensure_future, gather import json -from asyncio import ensure_future, gather, Event -import pytest from nacl.signing import SigningKey - +import pytest from secret_handshake.network import SHSDuplexStream + from ssb.packet_stream import PacketStream, PSMessageType diff --git a/tests/test_util.py b/tests/test_util.py index f45d4d7..a5f33c8 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -25,8 +25,7 @@ from unittest.mock import mock_open, patch import pytest -from ssb.util import load_ssb_secret, ConfigException - +from ssb.util import ConfigException, load_ssb_secret CONFIG_FILE = """ ## Comments should be supported too