Skip to content

Commit

Permalink
isort 5 compatibility (matrix-org#7786)
Browse files Browse the repository at this point in the history
The CI appears to use the latest version of isort, which is a problem when isort gets a major version bump. Rather than try to pin the version, I've done the necessary to make isort5 happy with synapse.
  • Loading branch information
Half-Shot authored Jul 5, 2020
1 parent 5cdca53 commit 62b1ce8
Show file tree
Hide file tree
Showing 23 changed files with 22 additions and 38 deletions.
1 change: 1 addition & 0 deletions changelog.d/7786.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update linting scripts and codebase to be compatible with `isort` v5.
2 changes: 1 addition & 1 deletion scripts-dev/check_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import json
import logging
import sys
import urllib2

import dns.resolver
import urllib2
from signedjson.key import decode_verify_key_bytes, write_signing_keys
from signedjson.sign import verify_signed_json
from unpaddedbase64 import decode_base64
Expand Down
2 changes: 1 addition & 1 deletion scripts-dev/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ else
fi

echo "Linting these locations: $files"
isort -y -rc $files
isort $files
python3 -m black $files
./scripts-dev/config-lint.sh
flake8 $files
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ ignore=W503,W504,E203,E731,E501

[isort]
line_length = 88
not_skip = __init__.py
sections=FUTURE,STDLIB,COMPAT,THIRDPARTY,TWISTED,FIRSTPARTY,TESTS,LOCALFOLDER
default_section=THIRDPARTY
known_first_party = synapse
Expand Down
3 changes: 1 addition & 2 deletions synapse/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
from typing import Optional

Expand All @@ -22,7 +21,6 @@
from twisted.internet import defer
from twisted.web.server import Request

import synapse.logging.opentracing as opentracing
import synapse.types
from synapse import event_auth
from synapse.api.auth_blocking import AuthBlocking
Expand All @@ -35,6 +33,7 @@
)
from synapse.api.room_versions import KNOWN_ROOM_VERSIONS
from synapse.events import EventBase
from synapse.logging import opentracing as opentracing
from synapse.types import StateMap, UserID
from synapse.util.caches import register_cache
from synapse.util.caches.lrucache import LruCache
Expand Down
1 change: 1 addition & 0 deletions synapse/config/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

if __name__ == "__main__":
import sys

from synapse.config.homeserver import HomeServerConfig

action = sys.argv[1]
Expand Down
3 changes: 1 addition & 2 deletions synapse/config/emailconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function

# This file can't be called email.py because if it is, we cannot:
Expand Down Expand Up @@ -145,8 +144,8 @@ def read_config(self, config, **kwargs):
or self.threepid_behaviour_email == ThreepidBehaviour.LOCAL
):
# make sure we can import the required deps
import jinja2
import bleach
import jinja2

# prevent unused warnings
jinja2
Expand Down
3 changes: 1 addition & 2 deletions synapse/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import time
import unicodedata
Expand All @@ -24,7 +23,6 @@
import bcrypt # type: ignore[import]
import pymacaroons

import synapse.util.stringutils as stringutils
from synapse.api.constants import LoginType
from synapse.api.errors import (
AuthError,
Expand All @@ -45,6 +43,7 @@
from synapse.module_api import ModuleApi
from synapse.push.mailer import load_jinja2_templates
from synapse.types import Requester, UserID
from synapse.util import stringutils as stringutils
from synapse.util.threepids import canonicalise_email

from ._base import BaseHandler
Expand Down
3 changes: 1 addition & 2 deletions synapse/handlers/cas_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import urllib
import xml.etree.ElementTree as ET
from typing import Dict, Optional, Tuple
from xml.etree import ElementTree as ET

from twisted.web.client import PartialDownloadError

Expand Down
4 changes: 2 additions & 2 deletions synapse/logging/opentracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ def set_fates(clotho, lachesis, atropos, father="Zues", mother="Themis"):
than one caller? Will all of those calling functions have be in a context
with an active span?
"""

import contextlib
import inspect
import logging
Expand All @@ -180,8 +179,8 @@ def set_fates(clotho, lachesis, atropos, father="Zues", mother="Themis"):
from synapse.config import ConfigError

if TYPE_CHECKING:
from synapse.server import HomeServer
from synapse.http.site import SynapseRequest
from synapse.server import HomeServer

# Helper class

Expand Down Expand Up @@ -227,6 +226,7 @@ class _DummyTagNames(object):
tags = _DummyTagNames
try:
from jaeger_client import Config as JaegerConfig

from synapse.logging.scopecontextmanager import LogContextScopeManager
except ImportError:
JaegerConfig = None # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion synapse/replication/tcp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
from synapse.util.metrics import Measure

if TYPE_CHECKING:
from synapse.server import HomeServer
from synapse.replication.tcp.handler import ReplicationCommandHandler
from synapse.server import HomeServer

logger = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions synapse/replication/tcp/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
from typing import Any, Dict, Iterable, Iterator, List, Optional, Set, Tuple, TypeVar

Expand Down Expand Up @@ -149,10 +148,11 @@ def start_replication(self, hs):
using TCP.
"""
if hs.config.redis.redis_enabled:
import txredisapi

from synapse.replication.tcp.redis import (
RedisDirectTcpReplicationClientFactory,
)
import txredisapi

logger.info(
"Connecting to redis (host=%r port=%r)",
Expand Down
2 changes: 0 additions & 2 deletions synapse/replication/tcp/streams/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import heapq
from collections import Iterable
from typing import List, Tuple, Type
Expand All @@ -22,7 +21,6 @@

from ._base import Stream, StreamUpdateResult, Token, current_token_without_instance


"""Handling of the 'events' replication stream
This stream contains rows of various types. Each row therefore contains a 'type'
Expand Down
3 changes: 1 addition & 2 deletions synapse/rest/media/v1/thumbnailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
from io import BytesIO

import PIL.Image as Image
from PIL import Image as Image

logger = logging.getLogger(__name__)

Expand Down
3 changes: 1 addition & 2 deletions synapse/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
See https://docs.python.org/3/library/secrets.html#module-secrets for the API
used in Python 3.6, and the API emulated in Python 2.7.
"""

import sys

# secrets is available since python 3.6
Expand All @@ -31,8 +30,8 @@ def Secrets():


else:
import os
import binascii
import os

class Secrets(object):
def token_bytes(self, nbytes=32):
Expand Down
3 changes: 1 addition & 2 deletions synapse/storage/data_stores/main/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import itertools
import logging
from collections import OrderedDict, namedtuple
Expand Down Expand Up @@ -48,8 +47,8 @@
from synapse.util.iterutils import batch_iter

if TYPE_CHECKING:
from synapse.storage.data_stores.main import DataStore
from synapse.server import HomeServer
from synapse.storage.data_stores.main import DataStore


logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/data_stores/main/ui_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

import attr

import synapse.util.stringutils as stringutils
from synapse.api.errors import StoreError
from synapse.storage._base import SQLBaseStore
from synapse.types import JsonDict
from synapse.util import stringutils as stringutils


@attr.s
Expand Down
2 changes: 0 additions & 2 deletions synapse/storage/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Any, Iterable, Iterator, List, Tuple

from typing_extensions import Protocol


"""
Some very basic protocol definitions for the DB-API2 classes specified in PEP-249
"""
Expand Down
2 changes: 1 addition & 1 deletion synapse/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
if sys.version_info[:3] >= (3, 6, 0):
from typing import Collection
else:
from typing import Sized, Iterable, Container
from typing import Container, Iterable, Sized

T_co = TypeVar("T_co", covariant=True)

Expand Down
4 changes: 1 addition & 3 deletions tests/handlers/test_e2e_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import mock

import signedjson.key as key
import signedjson.sign as sign
from signedjson import key as key, sign as sign

from twisted.internet import defer

Expand Down
4 changes: 1 addition & 3 deletions tests/rest/media/v1/test_media_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import os
import shutil
import tempfile
Expand All @@ -25,8 +23,8 @@
from mock import Mock

import attr
import PIL.Image as Image
from parameterized import parameterized_class
from PIL import Image as Image

from twisted.internet.defer import Deferred

Expand Down
2 changes: 0 additions & 2 deletions tests/test_utils/event_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Optional, Tuple

import synapse.server
Expand All @@ -25,7 +24,6 @@

from tests.test_utils import get_awaitable_result


"""
Utility functions for poking events into the storage of the server under test.
"""
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ commands =

[testenv:check_isort]
skip_install = True
deps = isort
commands = /bin/sh -c "isort -c -df -sp setup.cfg -rc synapse tests scripts-dev scripts"
deps = isort==5.0.3
commands = /bin/sh -c "isort -c --df --sp setup.cfg synapse tests scripts-dev scripts"

[testenv:check-newsfragment]
skip_install = True
Expand Down

0 comments on commit 62b1ce8

Please sign in to comment.