isort 5 compatibility (#7786)

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.
This commit is contained in:
Will Hunt 2020-07-05 16:32:02 +01:00 committed by GitHub
parent 5cdca53aa0
commit 62b1ce8539
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 22 additions and 38 deletions

1
changelog.d/7786.misc Normal file
View file

@ -0,0 +1 @@
Update linting scripts and codebase to be compatible with `isort` v5.

View file

@ -2,9 +2,9 @@ import argparse
import json import json
import logging import logging
import sys import sys
import urllib2
import dns.resolver import dns.resolver
import urllib2
from signedjson.key import decode_verify_key_bytes, write_signing_keys from signedjson.key import decode_verify_key_bytes, write_signing_keys
from signedjson.sign import verify_signed_json from signedjson.sign import verify_signed_json
from unpaddedbase64 import decode_base64 from unpaddedbase64 import decode_base64

View file

@ -15,7 +15,7 @@ else
fi fi
echo "Linting these locations: $files" echo "Linting these locations: $files"
isort -y -rc $files isort $files
python3 -m black $files python3 -m black $files
./scripts-dev/config-lint.sh ./scripts-dev/config-lint.sh
flake8 $files flake8 $files

View file

@ -26,7 +26,6 @@ ignore=W503,W504,E203,E731,E501
[isort] [isort]
line_length = 88 line_length = 88
not_skip = __init__.py
sections=FUTURE,STDLIB,COMPAT,THIRDPARTY,TWISTED,FIRSTPARTY,TESTS,LOCALFOLDER sections=FUTURE,STDLIB,COMPAT,THIRDPARTY,TWISTED,FIRSTPARTY,TESTS,LOCALFOLDER
default_section=THIRDPARTY default_section=THIRDPARTY
known_first_party = synapse known_first_party = synapse

View file

@ -12,7 +12,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging import logging
from typing import Optional from typing import Optional
@ -22,7 +21,6 @@ from netaddr import IPAddress
from twisted.internet import defer from twisted.internet import defer
from twisted.web.server import Request from twisted.web.server import Request
import synapse.logging.opentracing as opentracing
import synapse.types import synapse.types
from synapse import event_auth from synapse import event_auth
from synapse.api.auth_blocking import AuthBlocking from synapse.api.auth_blocking import AuthBlocking
@ -35,6 +33,7 @@ from synapse.api.errors import (
) )
from synapse.api.room_versions import KNOWN_ROOM_VERSIONS from synapse.api.room_versions import KNOWN_ROOM_VERSIONS
from synapse.events import EventBase from synapse.events import EventBase
from synapse.logging import opentracing as opentracing
from synapse.types import StateMap, UserID from synapse.types import StateMap, UserID
from synapse.util.caches import register_cache from synapse.util.caches import register_cache
from synapse.util.caches.lrucache import LruCache from synapse.util.caches.lrucache import LruCache

View file

@ -16,6 +16,7 @@ from synapse.config._base import ConfigError
if __name__ == "__main__": if __name__ == "__main__":
import sys import sys
from synapse.config.homeserver import HomeServerConfig from synapse.config.homeserver import HomeServerConfig
action = sys.argv[1] action = sys.argv[1]

View file

@ -14,7 +14,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from __future__ import print_function from __future__ import print_function
# This file can't be called email.py because if it is, we cannot: # This file can't be called email.py because if it is, we cannot:
@ -145,8 +144,8 @@ class EmailConfig(Config):
or self.threepid_behaviour_email == ThreepidBehaviour.LOCAL or self.threepid_behaviour_email == ThreepidBehaviour.LOCAL
): ):
# make sure we can import the required deps # make sure we can import the required deps
import jinja2
import bleach import bleach
import jinja2
# prevent unused warnings # prevent unused warnings
jinja2 jinja2

View file

@ -13,7 +13,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging import logging
import time import time
import unicodedata import unicodedata
@ -24,7 +23,6 @@ import attr
import bcrypt # type: ignore[import] import bcrypt # type: ignore[import]
import pymacaroons import pymacaroons
import synapse.util.stringutils as stringutils
from synapse.api.constants import LoginType from synapse.api.constants import LoginType
from synapse.api.errors import ( from synapse.api.errors import (
AuthError, AuthError,
@ -45,6 +43,7 @@ from synapse.metrics.background_process_metrics import run_as_background_process
from synapse.module_api import ModuleApi from synapse.module_api import ModuleApi
from synapse.push.mailer import load_jinja2_templates from synapse.push.mailer import load_jinja2_templates
from synapse.types import Requester, UserID from synapse.types import Requester, UserID
from synapse.util import stringutils as stringutils
from synapse.util.threepids import canonicalise_email from synapse.util.threepids import canonicalise_email
from ._base import BaseHandler from ._base import BaseHandler

View file

@ -12,11 +12,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging import logging
import urllib import urllib
import xml.etree.ElementTree as ET
from typing import Dict, Optional, Tuple from typing import Dict, Optional, Tuple
from xml.etree import ElementTree as ET
from twisted.web.client import PartialDownloadError from twisted.web.client import PartialDownloadError

View file

@ -164,7 +164,6 @@ Gotchas
than one caller? Will all of those calling functions have be in a context than one caller? Will all of those calling functions have be in a context
with an active span? with an active span?
""" """
import contextlib import contextlib
import inspect import inspect
import logging import logging
@ -180,8 +179,8 @@ from twisted.internet import defer
from synapse.config import ConfigError from synapse.config import ConfigError
if TYPE_CHECKING: if TYPE_CHECKING:
from synapse.server import HomeServer
from synapse.http.site import SynapseRequest from synapse.http.site import SynapseRequest
from synapse.server import HomeServer
# Helper class # Helper class
@ -227,6 +226,7 @@ except ImportError:
tags = _DummyTagNames tags = _DummyTagNames
try: try:
from jaeger_client import Config as JaegerConfig from jaeger_client import Config as JaegerConfig
from synapse.logging.scopecontextmanager import LogContextScopeManager from synapse.logging.scopecontextmanager import LogContextScopeManager
except ImportError: except ImportError:
JaegerConfig = None # type: ignore JaegerConfig = None # type: ignore

View file

@ -33,8 +33,8 @@ from synapse.util.async_helpers import timeout_deferred
from synapse.util.metrics import Measure from synapse.util.metrics import Measure
if TYPE_CHECKING: if TYPE_CHECKING:
from synapse.server import HomeServer
from synapse.replication.tcp.handler import ReplicationCommandHandler from synapse.replication.tcp.handler import ReplicationCommandHandler
from synapse.server import HomeServer
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View file

@ -13,7 +13,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging import logging
from typing import Any, Dict, Iterable, Iterator, List, Optional, Set, Tuple, TypeVar from typing import Any, Dict, Iterable, Iterator, List, Optional, Set, Tuple, TypeVar
@ -149,10 +148,11 @@ class ReplicationCommandHandler:
using TCP. using TCP.
""" """
if hs.config.redis.redis_enabled: if hs.config.redis.redis_enabled:
import txredisapi
from synapse.replication.tcp.redis import ( from synapse.replication.tcp.redis import (
RedisDirectTcpReplicationClientFactory, RedisDirectTcpReplicationClientFactory,
) )
import txredisapi
logger.info( logger.info(
"Connecting to redis (host=%r port=%r)", "Connecting to redis (host=%r port=%r)",

View file

@ -13,7 +13,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import heapq import heapq
from collections import Iterable from collections import Iterable
from typing import List, Tuple, Type from typing import List, Tuple, Type
@ -22,7 +21,6 @@ import attr
from ._base import Stream, StreamUpdateResult, Token, current_token_without_instance from ._base import Stream, StreamUpdateResult, Token, current_token_without_instance
"""Handling of the 'events' replication stream """Handling of the 'events' replication stream
This stream contains rows of various types. Each row therefore contains a 'type' This stream contains rows of various types. Each row therefore contains a 'type'

View file

@ -12,11 +12,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging import logging
from io import BytesIO from io import BytesIO
import PIL.Image as Image from PIL import Image as Image
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View file

@ -19,7 +19,6 @@ Injectable secrets module for Synapse.
See https://docs.python.org/3/library/secrets.html#module-secrets for the API 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. used in Python 3.6, and the API emulated in Python 2.7.
""" """
import sys import sys
# secrets is available since python 3.6 # secrets is available since python 3.6
@ -31,8 +30,8 @@ if sys.version_info[0:2] >= (3, 6):
else: else:
import os
import binascii import binascii
import os
class Secrets(object): class Secrets(object):
def token_bytes(self, nbytes=32): def token_bytes(self, nbytes=32):

View file

@ -14,7 +14,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import itertools import itertools
import logging import logging
from collections import OrderedDict, namedtuple from collections import OrderedDict, namedtuple
@ -48,8 +47,8 @@ from synapse.util.frozenutils import frozendict_json_encoder
from synapse.util.iterutils import batch_iter from synapse.util.iterutils import batch_iter
if TYPE_CHECKING: if TYPE_CHECKING:
from synapse.storage.data_stores.main import DataStore
from synapse.server import HomeServer from synapse.server import HomeServer
from synapse.storage.data_stores.main import DataStore
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View file

@ -17,10 +17,10 @@ from typing import Any, Dict, Optional, Union
import attr import attr
import synapse.util.stringutils as stringutils
from synapse.api.errors import StoreError from synapse.api.errors import StoreError
from synapse.storage._base import SQLBaseStore from synapse.storage._base import SQLBaseStore
from synapse.types import JsonDict from synapse.types import JsonDict
from synapse.util import stringutils as stringutils
@attr.s @attr.s

View file

@ -12,12 +12,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from typing import Any, Iterable, Iterator, List, Tuple from typing import Any, Iterable, Iterator, List, Tuple
from typing_extensions import Protocol from typing_extensions import Protocol
""" """
Some very basic protocol definitions for the DB-API2 classes specified in PEP-249 Some very basic protocol definitions for the DB-API2 classes specified in PEP-249
""" """

View file

@ -29,7 +29,7 @@ from synapse.api.errors import Codes, SynapseError
if sys.version_info[:3] >= (3, 6, 0): if sys.version_info[:3] >= (3, 6, 0):
from typing import Collection from typing import Collection
else: else:
from typing import Sized, Iterable, Container from typing import Container, Iterable, Sized
T_co = TypeVar("T_co", covariant=True) T_co = TypeVar("T_co", covariant=True)

View file

@ -14,11 +14,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import mock import mock
import signedjson.key as key from signedjson import key as key, sign as sign
import signedjson.sign as sign
from twisted.internet import defer from twisted.internet import defer

View file

@ -12,8 +12,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import os import os
import shutil import shutil
import tempfile import tempfile
@ -25,8 +23,8 @@ from urllib import parse
from mock import Mock from mock import Mock
import attr import attr
import PIL.Image as Image
from parameterized import parameterized_class from parameterized import parameterized_class
from PIL import Image as Image
from twisted.internet.defer import Deferred from twisted.internet.defer import Deferred

View file

@ -13,7 +13,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from typing import Optional, Tuple from typing import Optional, Tuple
import synapse.server import synapse.server
@ -25,7 +24,6 @@ from synapse.types import Collection
from tests.test_utils import get_awaitable_result from tests.test_utils import get_awaitable_result
""" """
Utility functions for poking events into the storage of the server under test. Utility functions for poking events into the storage of the server under test.
""" """

View file

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