Sort imports

I don't want to ever have to sort imports again. It's a poor use of
developer time. Automate this with a pre-commit hook, and check this on
CI.

Developers: I suggest you configure your editor to use
`reorder_python_imports`. It uses the standard sorting, and detects
first/third party libs well.
This commit is contained in:
Hugo Osvaldo Barrera 2020-06-09 14:34:45 +02:00
parent 9cb1f8d704
commit b1b4dd92fe
52 changed files with 196 additions and 156 deletions

View file

@ -14,6 +14,10 @@ repos:
hooks:
- id: flake8
additional_dependencies: [flake8-import-order, flake8-bugbear]
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.3.0
hooks:
- id: reorder-python-imports
- repo: local
hooks:
- id: update-travis

View file

@ -1,5 +1,4 @@
#!/usr/bin/env python
import itertools
import json

View file

@ -4,9 +4,9 @@ Vdirsyncer synchronizes calendars and contacts.
Please refer to https://vdirsyncer.pimutils.org/en/stable/packaging.html for
how to package vdirsyncer.
'''
from setuptools import Command, find_packages, setup
from setuptools import Command
from setuptools import find_packages
from setuptools import setup
requirements = [

View file

@ -1,14 +1,11 @@
'''
Test suite for vdirsyncer.
'''
import hypothesis.strategies as st
import urllib3.exceptions
from vdirsyncer.vobject import normalize_item
import urllib3
import urllib3.exceptions
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

View file

@ -5,10 +5,10 @@ import logging
import os
import click_log
from hypothesis import HealthCheck, Verbosity, settings
import pytest
from hypothesis import HealthCheck
from hypothesis import settings
from hypothesis import Verbosity
@pytest.fixture(autouse=True)

View file

@ -1,21 +1,23 @@
import random
import uuid
import textwrap
from urllib.parse import quote as urlquote, unquote as urlunquote
import uuid
from urllib.parse import quote as urlquote
from urllib.parse import unquote as urlunquote
import hypothesis.strategies as st
import pytest
from hypothesis import given
import pytest
from .. import assert_item_equals
from .. import EVENT_TEMPLATE
from .. import normalize_item
from .. import printable_characters_strategy
from .. import TASK_TEMPLATE
from .. import VCARD_TEMPLATE
from vdirsyncer import exceptions
from vdirsyncer.storage.base import normalize_meta_value
from vdirsyncer.vobject import Item
from .. import EVENT_TEMPLATE, TASK_TEMPLATE, VCARD_TEMPLATE, \
assert_item_equals, normalize_item, printable_characters_strategy
def get_server_mixin(server_name):
from . import __name__ as base

View file

@ -1,7 +1,7 @@
import pytest
import uuid
import pytest
@pytest.fixture
def slow_create_collection(request):

View file

@ -1,19 +1,15 @@
import os
import uuid
import os
import pytest
import requests
import requests.exceptions
from .. import get_server_mixin
from .. import StorageTests
from tests import assert_item_equals
from vdirsyncer import exceptions
from vdirsyncer.vobject import Item
from .. import StorageTests, get_server_mixin
dav_server = os.environ.get('DAV_SERVER', 'skip')
ServerMixin = get_server_mixin(dav_server)

View file

@ -2,18 +2,17 @@ import datetime
from textwrap import dedent
import pytest
import requests
import requests.exceptions
from tests import EVENT_TEMPLATE, TASK_TEMPLATE, VCARD_TEMPLATE
from . import dav_server
from . import DAVStorageTests
from .. import format_item
from tests import EVENT_TEMPLATE
from tests import TASK_TEMPLATE
from tests import VCARD_TEMPLATE
from vdirsyncer import exceptions
from vdirsyncer.storage.dav import CalDAVStorage
from . import DAVStorageTests, dav_server
from .. import format_item
class TestCalDAVStorage(DAVStorageTests):
storage_class = CalDAVStorage

View file

@ -1,8 +1,7 @@
import pytest
from vdirsyncer.storage.dav import CardDAVStorage
from . import DAVStorageTests
from vdirsyncer.storage.dav import CardDAVStorage
class TestCardDAVStorage(DAVStorageTests):

View file

@ -1,6 +1,8 @@
import pytest
from vdirsyncer.storage.dav import _BAD_XML_CHARS, _merge_xml, _parse_xml
from vdirsyncer.storage.dav import _BAD_XML_CHARS
from vdirsyncer.storage.dav import _merge_xml
from vdirsyncer.storage.dav import _parse_xml
def test_xml_utilities():

View file

@ -9,7 +9,6 @@ https://docs.djangoproject.com/en/1.10/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)

View file

@ -13,11 +13,10 @@ Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import include, url
from rest_framework_nested import routers
from django.conf.urls import include
from django.conf.urls import url
from journal import views
from rest_framework_nested import routers
router = routers.DefaultRouter()
router.register(r'journals', views.JournalViewSet)

View file

@ -6,7 +6,6 @@ It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application

View file

@ -1,14 +1,13 @@
import shutil
import os
import shutil
import sys
import pytest
import requests
from vdirsyncer.storage.etesync import EtesyncContacts, EtesyncCalendars
from .. import StorageTests
from vdirsyncer.storage.etesync import EtesyncCalendars
from vdirsyncer.storage.etesync import EtesyncContacts
pytestmark = pytest.mark.skipif(os.getenv('ETESYNC_TESTS', '') != 'true',

View file

@ -1,7 +1,8 @@
import os
import pytest
import uuid
import pytest
try:
caldav_args = {
# Those credentials are configured through the Travis UI

View file

@ -1,10 +1,9 @@
import os
import shutil
import subprocess
import time
import shutil
import pytest
import requests
testserver_repo = os.path.dirname(__file__)

View file

@ -2,11 +2,10 @@ import subprocess
import pytest
from . import StorageTests
from vdirsyncer.storage.filesystem import FilesystemStorage
from vdirsyncer.vobject import Item
from . import StorageTests
class TestFilesystemStorage(StorageTests):
storage_class = FilesystemStorage

View file

@ -1,11 +1,10 @@
import pytest
from requests import Response
from tests import normalize_item
from vdirsyncer.exceptions import UserError
from vdirsyncer.storage.http import HttpStorage, prepare_auth
from vdirsyncer.storage.http import HttpStorage
from vdirsyncer.storage.http import prepare_auth
def test_list(monkeypatch):

View file

@ -1,13 +1,11 @@
import pytest
from requests import Response
import vdirsyncer.storage.http
from . import StorageTests
from vdirsyncer.storage.base import Storage
from vdirsyncer.storage.singlefile import SingleFileStorage
from . import StorageTests
class CombinedStorage(Storage):
'''A subclass of HttpStorage to make testing easier. It supports writes via

View file

@ -1,8 +1,7 @@
import pytest
from vdirsyncer.storage.memory import MemoryStorage
from . import StorageTests
from vdirsyncer.storage.memory import MemoryStorage
class TestMemoryStorage(StorageTests):

View file

@ -1,8 +1,7 @@
import pytest
from vdirsyncer.storage.singlefile import SingleFileStorage
from . import StorageTests
from vdirsyncer.storage.singlefile import SingleFileStorage
class TestSingleFileStorage(StorageTests):

View file

@ -1,8 +1,7 @@
from textwrap import dedent
from click.testing import CliRunner
import pytest
from click.testing import CliRunner
import vdirsyncer.cli as cli

View file

@ -3,7 +3,8 @@ from textwrap import dedent
import pytest
from vdirsyncer import cli, exceptions
from vdirsyncer import cli
from vdirsyncer import exceptions
from vdirsyncer.cli.config import Config

View file

@ -3,9 +3,9 @@ import sys
from textwrap import dedent
import hypothesis.strategies as st
from hypothesis import example, given
import pytest
from hypothesis import example
from hypothesis import given
def test_simple_run(tmpdir, runner):

View file

@ -1,6 +1,7 @@
from vdirsyncer import exceptions
from vdirsyncer.cli.utils import handle_cli_error, \
storage_instance_from_config, storage_names
from vdirsyncer.cli.utils import handle_cli_error
from vdirsyncer.cli.utils import storage_instance_from_config
from vdirsyncer.cli.utils import storage_names
def test_handle_cli_error(capsys):

View file

@ -1,11 +1,12 @@
import sys
import logging
import sys
import click_log
import pytest
import requests
from vdirsyncer import http, utils
from vdirsyncer import http
from vdirsyncer import utils
@pytest.fixture(autouse=True)

View file

@ -1,10 +1,10 @@
import hypothesis.strategies as st
import pytest
from hypothesis import given
import pytest
from vdirsyncer import exceptions
from vdirsyncer.cli.fetchparams import STRATEGIES, expand_fetch_params
from vdirsyncer.cli.fetchparams import expand_fetch_params
from vdirsyncer.cli.fetchparams import STRATEGIES
@pytest.fixture

View file

@ -1,7 +1,7 @@
import pytest
from hypothesis import assume, given
import hypothesis.strategies as st
import pytest
from hypothesis import assume
from hypothesis import given
from vdirsyncer.sync.status import SqliteStatus

View file

@ -1,17 +1,22 @@
from copy import deepcopy
import hypothesis.strategies as st
from hypothesis import assume
from hypothesis.stateful import Bundle, RuleBasedStateMachine, rule
import pytest
from hypothesis import assume
from hypothesis.stateful import Bundle
from hypothesis.stateful import rule
from hypothesis.stateful import RuleBasedStateMachine
from tests import blow_up, uid_strategy
from vdirsyncer.storage.memory import MemoryStorage, _random_string
from tests import blow_up
from tests import uid_strategy
from vdirsyncer.storage.memory import _random_string
from vdirsyncer.storage.memory import MemoryStorage
from vdirsyncer.sync import sync as _sync
from vdirsyncer.sync.exceptions import BothReadOnly, IdentConflict, \
PartialSync, StorageEmpty, SyncConflict
from vdirsyncer.sync.exceptions import BothReadOnly
from vdirsyncer.sync.exceptions import IdentConflict
from vdirsyncer.sync.exceptions import PartialSync
from vdirsyncer.sync.exceptions import StorageEmpty
from vdirsyncer.sync.exceptions import SyncConflict
from vdirsyncer.sync.status import SqliteStatus
from vdirsyncer.vobject import Item

View file

@ -1,12 +1,13 @@
import hypothesis.strategies as st
from hypothesis import example, given
import pytest
from hypothesis import example
from hypothesis import given
from tests import blow_up
from vdirsyncer.exceptions import UserError
from vdirsyncer.metasync import MetaSyncConflict, logger, metasync
from vdirsyncer.metasync import logger
from vdirsyncer.metasync import metasync
from vdirsyncer.metasync import MetaSyncConflict
from vdirsyncer.storage.base import normalize_meta_value
from vdirsyncer.storage.memory import MemoryStorage

View file

@ -1,10 +1,12 @@
from hypothesis import HealthCheck, given, settings
import pytest
from hypothesis import given
from hypothesis import HealthCheck
from hypothesis import settings
from tests import uid_strategy
from vdirsyncer.repair import IrreparableItem, repair_item, repair_storage
from vdirsyncer.repair import IrreparableItem
from vdirsyncer.repair import repair_item
from vdirsyncer.repair import repair_storage
from vdirsyncer.storage.memory import MemoryStorage
from vdirsyncer.utils import href_safe
from vdirsyncer.vobject import Item

View file

@ -1,16 +1,20 @@
from textwrap import dedent
import hypothesis.strategies as st
from hypothesis import assume, given
from hypothesis.stateful import Bundle, RuleBasedStateMachine, rule
import pytest
from tests import BARE_EVENT_TEMPLATE, EVENT_TEMPLATE, \
EVENT_WITH_TIMEZONE_TEMPLATE, VCARD_TEMPLATE, normalize_item, \
uid_strategy
from hypothesis import assume
from hypothesis import given
from hypothesis.stateful import Bundle
from hypothesis.stateful import rule
from hypothesis.stateful import RuleBasedStateMachine
import vdirsyncer.vobject as vobject
from tests import BARE_EVENT_TEMPLATE
from tests import EVENT_TEMPLATE
from tests import EVENT_WITH_TIMEZONE_TEMPLATE
from tests import normalize_item
from tests import uid_strategy
from tests import VCARD_TEMPLATE
_simple_split = [

View file

@ -3,10 +3,10 @@ import logging
import sys
import click
import click_log
from .. import BUGTRACKER_HOME, __version__
from .. import __version__
from .. import BUGTRACKER_HOME
cli_logger = logging.getLogger(__name__)

View file

@ -6,10 +6,12 @@ from itertools import chain
from click_threading import get_ui_worker
from .. import exceptions
from .. import PROJECT_HOME
from ..utils import cached_property
from ..utils import expand_path
from .fetchparams import expand_fetch_params
from .utils import storage_class_from_config
from .. import PROJECT_HOME, exceptions
from ..utils import cached_property, expand_path
GENERAL_ALL = frozenset(['status_path'])

View file

@ -3,12 +3,14 @@ import json
import logging
import sys
from .utils import handle_collection_not_found, handle_storage_init_error, \
load_status, save_status, storage_class_from_config, \
storage_instance_from_config
from .. import exceptions
from ..utils import cached_property
from .utils import handle_collection_not_found
from .utils import handle_storage_init_error
from .utils import load_status
from .utils import save_status
from .utils import storage_class_from_config
from .utils import storage_instance_from_config
# Increase whenever upgrade potentially breaks discovery cache and collections

View file

@ -4,7 +4,8 @@ import click
from . import AppContext
from .. import exceptions
from ..utils import expand_path, synchronized
from ..utils import expand_path
from ..utils import synchronized
SUFFIX = '.fetch'

View file

@ -1,13 +1,19 @@
import functools
import json
from .. import exceptions
from .. import sync
from .config import CollectionConfig
from .discover import collections_for_pair, storage_class_from_config, \
storage_instance_from_config
from .utils import JobFailed, cli_logger, get_status_name, \
handle_cli_error, load_status, manage_sync_status, save_status
from .. import exceptions, sync
from .discover import collections_for_pair
from .discover import storage_class_from_config
from .discover import storage_instance_from_config
from .utils import cli_logger
from .utils import get_status_name
from .utils import handle_cli_error
from .utils import JobFailed
from .utils import load_status
from .utils import manage_sync_status
from .utils import save_status
def prepare_pair(wq, pair_name, collections, config, callback, **kwargs):

View file

@ -7,18 +7,21 @@ import os
import queue
import sys
import click
import click_threading
from atomicwrites import atomic_write
import click
import click_threading
from . import cli_logger
from .. import BUGTRACKER_HOME, DOCS_HOME, exceptions
from ..sync.exceptions import IdentConflict, PartialSync, StorageEmpty, \
SyncConflict
from .. import BUGTRACKER_HOME
from .. import DOCS_HOME
from .. import exceptions
from ..sync.exceptions import IdentConflict
from ..sync.exceptions import PartialSync
from ..sync.exceptions import StorageEmpty
from ..sync.exceptions import SyncConflict
from ..sync.status import SqliteStatus
from ..utils import expand_path, get_storage_init_args
from ..utils import expand_path
from ..utils import get_storage_init_args
STATUS_PERMISSIONS = 0o600

View file

@ -2,8 +2,10 @@ import logging
import requests
from . import __version__
from . import DOCS_HOME
from . import exceptions
from .utils import expand_path
from . import DOCS_HOME, exceptions, __version__
logger = logging.getLogger(__name__)

View file

@ -1,7 +1,8 @@
import logging
from os.path import basename
from .utils import generate_href, href_safe
from .utils import generate_href
from .utils import href_safe
logger = logging.getLogger(__name__)

View file

@ -2,17 +2,21 @@ import datetime
import logging
import urllib.parse as urlparse
import xml.etree.ElementTree as etree
from inspect import getfullargspec
import requests
from requests.exceptions import HTTPError
from .base import Storage, normalize_meta_value
from .. import exceptions, http, utils
from ..http import USERAGENT, prepare_auth, \
prepare_client_cert, prepare_verify
from .. import exceptions
from .. import http
from .. import utils
from ..http import prepare_auth
from ..http import prepare_client_cert
from ..http import prepare_verify
from ..http import USERAGENT
from ..vobject import Item
from .base import normalize_meta_value
from .base import Storage
dav_logger = logging.getLogger(__name__)

View file

@ -1,8 +1,8 @@
import binascii
import contextlib
import functools
import logging
import os
import binascii
import atomicwrites
import click

View file

@ -5,10 +5,14 @@ import subprocess
from atomicwrites import atomic_write
from .base import Storage, normalize_meta_value
from .. import exceptions
from ..utils import checkdir, expand_path, generate_href, get_etag_from_file
from ..utils import checkdir
from ..utils import expand_path
from ..utils import generate_href
from ..utils import get_etag_from_file
from ..vobject import Item
from .base import normalize_meta_value
from .base import Storage
logger = logging.getLogger(__name__)

View file

@ -3,15 +3,16 @@ import logging
import os
import urllib.parse as urlparse
from atomicwrites import atomic_write
import click
from atomicwrites import atomic_write
from click_threading import get_ui_worker
from . import base, dav
from . import base
from . import dav
from .. import exceptions
from ..utils import checkdir, expand_path, open_graphical_browser
from ..utils import checkdir
from ..utils import expand_path
from ..utils import open_graphical_browser
logger = logging.getLogger(__name__)

View file

@ -1,10 +1,14 @@
import urllib.parse as urlparse
from .base import Storage
from .. import exceptions
from ..http import USERAGENT, prepare_auth, \
prepare_client_cert, prepare_verify, request
from ..vobject import Item, split_collection
from ..http import prepare_auth
from ..http import prepare_client_cert
from ..http import prepare_verify
from ..http import request
from ..http import USERAGENT
from ..vobject import Item
from ..vobject import split_collection
from .base import Storage
class HttpStorage(Storage):

View file

@ -1,8 +1,8 @@
import random
from .base import Storage, normalize_meta_value
from .. import exceptions
from .base import normalize_meta_value
from .base import Storage
def _random_string():

View file

@ -7,10 +7,14 @@ import os
from atomicwrites import atomic_write
from .base import Storage
from .. import exceptions
from ..utils import checkfile, expand_path, get_etag_from_file
from ..vobject import Item, join_collection, split_collection
from ..utils import checkfile
from ..utils import expand_path
from ..utils import get_etag_from_file
from ..vobject import Item
from ..vobject import join_collection
from ..vobject import split_collection
from .base import Storage
logger = logging.getLogger(__name__)

View file

@ -15,10 +15,13 @@ import logging
from ..exceptions import UserError
from ..utils import uniq
from .status import SubStatus, ItemMetadata
from .exceptions import BothReadOnly, IdentAlreadyExists, PartialSync, \
StorageEmpty, SyncConflict
from .exceptions import BothReadOnly
from .exceptions import IdentAlreadyExists
from .exceptions import PartialSync
from .exceptions import StorageEmpty
from .exceptions import SyncConflict
from .status import ItemMetadata
from .status import SubStatus
sync_logger = logging.getLogger(__name__)

View file

@ -1,7 +1,7 @@
import abc
import contextlib
import sys
import sqlite3
import sys
from .exceptions import IdentAlreadyExists

View file

@ -2,7 +2,6 @@ import functools
import os
import sys
import uuid
from inspect import getfullargspec
from . import exceptions

View file

@ -1,7 +1,9 @@
import hashlib
from itertools import chain, tee
from itertools import chain
from itertools import tee
from .utils import cached_property, uniq
from .utils import cached_property
from .utils import uniq
IGNORE_PROPS = (