diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8d45122..674e2c7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,3 +30,10 @@ repos: language: system types: [python] require_serial: true + - id: isort + name: isort + args: ["--check", "--diff"] + entry: poetry run isort + language: system + require_serial: true + types_or: [python, pyi] diff --git a/examples/test_client.py b/examples/test_client.py index 8c0939c..6a93925 100644 --- a/examples/test_client.py +++ b/examples/test_client.py @@ -1,15 +1,15 @@ """Example SSB Client""" +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 diff --git a/examples/test_server.py b/examples/test_server.py index b91b3f6..4c5b74a 100644 --- a/examples/test_server.py +++ b/examples/test_server.py @@ -1,13 +1,13 @@ """Test SSB server""" -import logging from asyncio import get_event_loop +import logging 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 a219809..80fda8f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -526,20 +526,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" @@ -1269,4 +1269,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "63b3d6f54c99a6722a3d0d5cf9eac68bdb5ef0ea7c58957dd76494529870186c" +content-hash = "4c675f7bcb417a7a7d8cf065f804c796ccc476edffc79e99dbed152ff94c6d58" diff --git a/pyproject.toml b/pyproject.toml index 6a3078c..ab1b21e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ colorlog = "^6.7.0" [tool.poetry.group.dev.dependencies] check-manifest = "^0.39" 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" @@ -42,6 +42,11 @@ skip_covered = true fail_under = 70 omit = ["examples/*"] +[tool.isort] +force_sort_within_sections = true +line_length = 120 +profile = "black" + [tool.pylint.format] max-line-length = 120 diff --git a/ssb/feed/__init__.py b/ssb/feed/__init__.py index ccbf48f..5d54d34 100644 --- a/ssb/feed/__init__.py +++ b/ssb/feed/__init__.py @@ -1,5 +1,5 @@ """Feed related functionality""" -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 9344f5b..958fd3c 100644 --- a/ssb/feed/models.py +++ b/ssb/feed/models.py @@ -1,15 +1,14 @@ """Feed models""" -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 969f7c8..a78b5ad 100644 --- a/ssb/packet_stream.py +++ b/ssb/packet_stream.py @@ -1,15 +1,14 @@ """Packet streams""" -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 - logger = logging.getLogger("packet_stream") diff --git a/ssb/util.py b/ssb/util.py index d97cb93..7d969c3 100644 --- a/ssb/util.py +++ b/ssb/util.py @@ -3,8 +3,8 @@ from base64 import b64decode, b64encode import os -import yaml from nacl.signing import SigningKey +import yaml class ConfigException(Exception): diff --git a/tests/test_feed.py b/tests/test_feed.py index d111cf1..63c0b3a 100644 --- a/tests/test_feed.py +++ b/tests/test_feed.py @@ -3,11 +3,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 5b5e016..5dff5cf 100644 --- a/tests/test_packet_stream.py +++ b/tests/test_packet_stream.py @@ -1,11 +1,11 @@ """Tests for the packet stream""" +from asyncio import Event, ensure_future, gather import json -from asyncio import ensure_future, gather, Event 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 3766f28..d3594f8 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -5,8 +5,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