Skip to content

Commit

Permalink
Enforce import sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
ff137 authored Oct 15, 2024
1 parent c90166c commit 3aa879e
Show file tree
Hide file tree
Showing 50 changed files with 287 additions and 252 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ jobs:
- name: Run format check
run: |
pipenv run yapf --diff --recursive .
- name: Run isort check
run: pipenv run isort --check-only --diff .
5 changes: 5 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[settings]
combine_as_imports = true
multi_line_output = 3
include_trailing_comma = true
src_paths = ["nats", "tests"]
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ pytest-cov = "*"
yapf = "*"
toml = "*" # see https://github.com/google/yapf/issues/936
exceptiongroup = "*"
isort = "*"
303 changes: 178 additions & 125 deletions Pipfile.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion benchmark/latency_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import asyncio
import sys
import time
from random import randint

import nats

Expand Down
1 change: 0 additions & 1 deletion benchmark/sub_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import asyncio
import sys
import time
from random import randint

import nats

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

import nats
from nats.errors import NoServersError, TimeoutError

Expand Down
3 changes: 2 additions & 1 deletion examples/basic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import asyncio

import nats
from nats.errors import TimeoutError
from common import args
from nats.errors import TimeoutError


async def main():
Expand Down
3 changes: 2 additions & 1 deletion examples/client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import asyncio
from datetime import datetime

from common import args
from nats.aio.client import Client as NATS
from nats.errors import ConnectionClosedError, TimeoutError
from common import args


class Client:
Expand Down
2 changes: 1 addition & 1 deletion examples/clustered.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
from datetime import datetime

import nats
from nats.aio.client import Client as NATS
from nats.aio.errors import ErrConnectionClosed, ErrNoServers, ErrTimeout


Expand Down
3 changes: 2 additions & 1 deletion examples/component.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import time
import signal
import time

import nats


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

import nats
from common import args

Expand Down
1 change: 1 addition & 0 deletions examples/context-manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio

import nats
from common import args

Expand Down
3 changes: 2 additions & 1 deletion examples/drain-sub.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
from nats.aio.client import Client as NATS

from common import args
from nats.aio.client import Client as NATS


async def main():
Expand Down
4 changes: 2 additions & 2 deletions examples/example.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncio
from nats.aio.client import Client as NATS
from nats.errors import ConnectionClosedError

from common import args
from nats.aio.client import Client as NATS
from nats.errors import ConnectionClosedError


async def main():
Expand Down
1 change: 1 addition & 0 deletions examples/jetstream.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio

import nats
from nats.errors import TimeoutError

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

import nats


Expand Down
1 change: 1 addition & 0 deletions examples/nats-pub/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import argparse
import asyncio
import sys

import nats


Expand Down
1 change: 1 addition & 0 deletions examples/nats-req/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import argparse
import asyncio
import sys

import nats


Expand Down
1 change: 1 addition & 0 deletions examples/nats-sub/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import asyncio
import signal
import sys

import nats


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

import nats
from common import args

Expand Down
1 change: 1 addition & 0 deletions examples/service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import signal

from nats.aio.client import Client as NATS


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

import nats


Expand Down
3 changes: 2 additions & 1 deletion examples/subscribe.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import asyncio
import signal
from nats.aio.client import Client as NATS

from common import args
from nats.aio.client import Client as NATS


async def main():
Expand Down
1 change: 1 addition & 0 deletions examples/tls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import ssl

from nats.aio.client import Client as NATS
from nats.errors import TimeoutError

Expand Down
3 changes: 2 additions & 1 deletion examples/wildcard.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
from nats.aio.client import Client as NATS

from common import args
from nats.aio.client import Client as NATS


async def run(loop):
Expand Down
1 change: 1 addition & 0 deletions nats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from __future__ import annotations

from typing import List, Union

from .aio.client import Client as NATS


Expand Down
23 changes: 6 additions & 17 deletions nats/aio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,16 @@
import json
import logging
import ssl
import time
import string
import time
from collections import UserString
from dataclasses import dataclass
from email.parser import BytesParser
from io import BytesIO
from random import shuffle
from secrets import token_hex
from typing import (
Any,
Awaitable,
Callable,
Dict,
List,
Literal,
Optional,
Tuple,
TypedDict,
Union,
)
from typing import Any, Awaitable, Callable, Dict, List, Optional, Tuple, Union
from urllib.parse import ParseResult, urlparse
from collections import UserString
from io import BytesIO

try:
from fast_mail_parser import parse_email
Expand All @@ -54,7 +43,6 @@
from nats.protocol.parser import (
AUTHORIZATION_VIOLATION,
PERMISSIONS_ERR,
PING,
PONG,
STALE_CONNECTION,
Parser,
Expand Down Expand Up @@ -537,6 +525,7 @@ def _setup_nkeys_connect(self) -> None:
def _setup_nkeys_jwt_connect(self) -> None:
assert self._user_credentials, "_user_credentials required"
import os

import nkeys

creds: Credentials = self._user_credentials
Expand Down Expand Up @@ -641,7 +630,7 @@ def _setup_nkeys_seed_connect(self) -> None:
assert (
self._nkeys_seed or self._nkeys_seed_str
), "Client.connect must be called first"
import os

import nkeys

def _get_nkeys_seed() -> nkeys.KeyPair:
Expand Down
2 changes: 1 addition & 1 deletion nats/aio/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import datetime
import json
from dataclasses import dataclass
from typing import TYPE_CHECKING, List, Optional, Dict, Union
from typing import TYPE_CHECKING, Dict, List, Optional, Union

from nats.errors import Error, MsgAlreadyAckdError, NotJSMessageError

Expand Down
1 change: 0 additions & 1 deletion nats/aio/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from uuid import uuid4

from nats import errors

# Default Pending Limits of Subscriptions
from nats.aio.msg import Msg

Expand Down
2 changes: 1 addition & 1 deletion nats/aio/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import abc
import asyncio
import ssl
from typing import List, Optional, Union
from urllib.parse import ParseResult
from typing import List, Union, Optional

try:
import aiohttp
Expand Down
2 changes: 1 addition & 1 deletion nats/js/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from dataclasses import dataclass, fields, replace
from enum import Enum
from typing import Any, Dict, Optional, TypeVar, List, Iterable, Iterator
from typing import Any, Dict, Iterable, Iterator, List, Optional, TypeVar

_NANOSECOND = 10**9

Expand Down
14 changes: 11 additions & 3 deletions nats/js/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@
import time
from email.parser import BytesParser
from secrets import token_hex
from typing import TYPE_CHECKING, Awaitable, Callable, Optional, List, Dict, Any
from typing import (
TYPE_CHECKING,
Any,
Awaitable,
Callable,
Dict,
List,
Optional,
)

import nats.errors
import nats.js.errors
Expand All @@ -29,17 +37,17 @@
from nats.js.errors import (
BadBucketError,
BucketNotFoundError,
FetchTimeoutError,
InvalidBucketNameError,
NotFoundError,
FetchTimeoutError,
)
from nats.js.kv import KeyValue
from nats.js.manager import JetStreamManager
from nats.js.object_store import (
VALID_BUCKET_RE,
OBJ_ALL_CHUNKS_PRE_TEMPLATE,
OBJ_ALL_META_PRE_TEMPLATE,
OBJ_STREAM_TEMPLATE,
VALID_BUCKET_RE,
ObjectStore,
)

Expand Down
2 changes: 1 addition & 1 deletion nats/js/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, NoReturn, Optional, Dict
from typing import TYPE_CHECKING, Any, Dict, NoReturn, Optional

import nats.errors
from nats.js import api
Expand Down
2 changes: 1 addition & 1 deletion nats/js/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import base64
import json
from email.parser import BytesParser
from typing import TYPE_CHECKING, Any, List, Optional, Dict, Iterable
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional

from nats.errors import NoRespondersError
from nats.js import api
Expand Down
14 changes: 7 additions & 7 deletions nats/js/object_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@
# limitations under the License.
#

import asyncio
import base64
import re
import io
import json
import re
from dataclasses import dataclass
from datetime import datetime, timezone
from hashlib import sha256
from dataclasses import dataclass
import json
import asyncio
from typing import TYPE_CHECKING, Optional, Union, List
from typing import TYPE_CHECKING, List, Optional, Union

import nats.errors
from nats.js import api
from nats.js.errors import (
BadObjectMetaError,
DigestMismatchError,
LinkIsABucketError,
NotFoundError,
ObjectAlreadyExists,
ObjectDeletedError,
ObjectNotFoundError,
NotFoundError,
LinkIsABucketError,
)
from nats.js.kv import MSG_ROLLUP_SUBJECT

Expand Down
5 changes: 3 additions & 2 deletions nats/micro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
#

from dataclasses import replace
from nats.aio.client import Client
from typing import Optional

from nats.aio.client import Client

from .request import Handler, Request
from .service import Service, ServiceConfig
from .request import Request, Handler


async def add_service(
Expand Down
Loading

0 comments on commit 3aa879e

Please sign in to comment.