diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 31ef1eac..72792d1a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -28,5 +28,7 @@ jobs: - run: pip install --upgrade tox - name: Run black code formatter (https://black.readthedocs.io/en/stable/) run: tox -e black -- --check + - name: Run isort import order checker (https://pycqa.github.io/isort/) + run: tox -e isort -- --check - name: Run flake8 (https://flake8.pycqa.org/en/latest/) run: tox -e flake8 diff --git a/imapclient/config.py b/imapclient/config.py index 1de42d32..ad398c22 100644 --- a/imapclient/config.py +++ b/imapclient/config.py @@ -2,13 +2,12 @@ # Released subject to the New BSD License # Please see http://en.wikipedia.org/wiki/BSD_licenses +import configparser import json -from os import environ, path import ssl - -import configparser import urllib.parse import urllib.request +from os import environ, path import imapclient diff --git a/imapclient/fixed_offset.py b/imapclient/fixed_offset.py index dd6d9b17..cc0e4804 100644 --- a/imapclient/fixed_offset.py +++ b/imapclient/fixed_offset.py @@ -3,7 +3,7 @@ # Please see http://en.wikipedia.org/wiki/BSD_licenses import time -from datetime import tzinfo, timedelta +from datetime import timedelta, tzinfo ZERO = timedelta(0) diff --git a/imapclient/imapclient.py b/imapclient/imapclient.py index 7faac861..f49d8bea 100644 --- a/imapclient/imapclient.py +++ b/imapclient/imapclient.py @@ -5,24 +5,22 @@ import functools import imaplib import itertools +import re import select import socket import sys -import re import warnings from collections import namedtuple -from datetime import datetime, date +from datetime import date, datetime +from logging import getLogger, LoggerAdapter from operator import itemgetter -from logging import LoggerAdapter, getLogger -from . import exceptions -from . import imap4 -from . import response_lexer -from . import tls +from . import exceptions, imap4, response_lexer, tls from .datetime_util import datetime_to_INTERNALDATE, format_criteria_date -from .imap_utf7 import encode as encode_utf7, decode as decode_utf7 -from .response_parser import parse_response, parse_message_list, parse_fetch_response -from .util import to_bytes, to_unicode, assert_imap_protocol, chunk +from .imap_utf7 import decode as decode_utf7 +from .imap_utf7 import encode as encode_utf7 +from .response_parser import parse_fetch_response, parse_message_list, parse_response +from .util import assert_imap_protocol, chunk, to_bytes, to_unicode if hasattr(select, "poll"): POLL_SUPPORT = True diff --git a/imapclient/interact.py b/imapclient/interact.py index eb1e79be..d90d1014 100644 --- a/imapclient/interact.py +++ b/imapclient/interact.py @@ -7,7 +7,7 @@ import argparse from getpass import getpass -from .config import parse_config_file, create_client_from_config, get_config_defaults +from .config import create_client_from_config, get_config_defaults, parse_config_file def command_line(): diff --git a/imapclient/response_parser.py b/imapclient/response_parser.py index 8d48fd9f..921ed00a 100644 --- a/imapclient/response_parser.py +++ b/imapclient/response_parser.py @@ -16,9 +16,9 @@ from collections import defaultdict from .datetime_util import parse_to_datetime -from .response_lexer import TokenSource -from .response_types import BodyData, Envelope, Address, SearchIds from .exceptions import ProtocolError +from .response_lexer import TokenSource +from .response_types import Address, BodyData, Envelope, SearchIds __all__ = ["parse_response", "parse_message_list"] diff --git a/imapclient/testable_imapclient.py b/imapclient/testable_imapclient.py index 7a3e2b11..e297200e 100644 --- a/imapclient/testable_imapclient.py +++ b/imapclient/testable_imapclient.py @@ -2,9 +2,10 @@ # Released subject to the New BSD License # Please see http://en.wikipedia.org/wiki/BSD_licenses -from .imapclient import IMAPClient from unittest.mock import Mock +from .imapclient import IMAPClient + class TestableIMAPClient(IMAPClient): """Wrapper of :py:class:`imapclient.IMAPClient` that mocks all diff --git a/livetest.py b/livetest.py index bb28c4f8..b09d6759 100644 --- a/livetest.py +++ b/livetest.py @@ -19,17 +19,17 @@ from datetime import datetime from email.utils import make_msgid -from imapclient.config import parse_config_file, create_client_from_config +from imapclient.config import create_client_from_config, parse_config_file from imapclient.exceptions import IMAPClientError from imapclient.fixed_offset import FixedOffset from imapclient.imapclient import ( - IMAPClient, + _dict_bytes_normaliser, DELETED, + IMAPClient, RECENT, - _dict_bytes_normaliser, SocketTimeout, ) -from imapclient.response_types import Envelope, Address +from imapclient.response_types import Address, Envelope from imapclient.util import to_bytes, to_unicode # TODO cleaner verbose output: avoid "__main__" and separator between classes diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..cf7dc5e3 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,4 @@ +[tool.isort] +profile = "black" +multi_line_output = 3 +order_by_type = false diff --git a/requirements-dev.txt b/requirements-dev.txt index 432d7506..acda464c 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,3 +1,4 @@ sphinx black==22.3.0 flake8==4.0.1 +isort==5.12.0 diff --git a/tests/imapclient_test.py b/tests/imapclient_test.py index 337c1948..10ae3c10 100644 --- a/tests/imapclient_test.py +++ b/tests/imapclient_test.py @@ -1,6 +1,7 @@ -from imapclient.testable_imapclient import TestableIMAPClient as IMAPClient import unittest +from imapclient.testable_imapclient import TestableIMAPClient as IMAPClient + class IMAPClientTest(unittest.TestCase): def setUp(self): diff --git a/tests/test_auth.py b/tests/test_auth.py index 95755b28..7a46cb74 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -3,6 +3,7 @@ # Please see http://en.wikipedia.org/wiki/BSD_licenses from imapclient.exceptions import LoginError + from .imapclient_test import IMAPClientTest diff --git a/tests/test_datetime_util.py b/tests/test_datetime_util.py index 47816346..b0f124cc 100644 --- a/tests/test_datetime_util.py +++ b/tests/test_datetime_util.py @@ -2,11 +2,10 @@ # Released subject to the New BSD License # Please see http://en.wikipedia.org/wiki/BSD_licenses -from datetime import datetime, date import unittest +from datetime import date, datetime from unittest.mock import patch - from imapclient.datetime_util import ( datetime_to_INTERNALDATE, datetime_to_native, diff --git a/tests/test_enable.py b/tests/test_enable.py index 87c41a26..a1754ddd 100644 --- a/tests/test_enable.py +++ b/tests/test_enable.py @@ -5,6 +5,7 @@ from unittest.mock import Mock from imapclient.exceptions import IllegalStateError + from .imapclient_test import IMAPClientTest diff --git a/tests/test_fixed_offset.py b/tests/test_fixed_offset.py index 7e32d121..4d37dfa3 100644 --- a/tests/test_fixed_offset.py +++ b/tests/test_fixed_offset.py @@ -2,9 +2,9 @@ # Released subject to the New BSD License # Please see http://en.wikipedia.org/wiki/BSD_licenses -from datetime import timedelta import unittest -from unittest.mock import Mock, patch, DEFAULT +from datetime import timedelta +from unittest.mock import DEFAULT, Mock, patch from imapclient.fixed_offset import FixedOffset diff --git a/tests/test_imapclient.py b/tests/test_imapclient.py index 4e46b919..0819eb72 100644 --- a/tests/test_imapclient.py +++ b/tests/test_imapclient.py @@ -4,25 +4,24 @@ import io import itertools +import logging import socket import sys import warnings from datetime import datetime -import logging -from unittest.mock import patch, sentinel, Mock - from select import POLLIN +from unittest.mock import Mock, patch, sentinel from imapclient.exceptions import CapabilityError, IMAPClientError, ProtocolError +from imapclient.fixed_offset import FixedOffset from imapclient.imapclient import ( - IMAPlibLoggerAdapter, + _literal, _parse_quota, - Quota, + IMAPlibLoggerAdapter, MailboxQuotaRoots, + Quota, require_capability, - _literal, ) -from imapclient.fixed_offset import FixedOffset from imapclient.testable_imapclient import TestableIMAPClient as IMAPClient from .imapclient_test import IMAPClientTest diff --git a/tests/test_init.py b/tests/test_init.py index 8ecb5744..71dea463 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -3,7 +3,7 @@ # Please see http://en.wikipedia.org/wiki/BSD_licenses import unittest -from unittest.mock import patch, sentinel, Mock +from unittest.mock import Mock, patch, sentinel from imapclient.imapclient import IMAPClient, SocketTimeout diff --git a/tests/test_response_parser.py b/tests/test_response_parser.py index e7ce4373..cf5c72b8 100644 --- a/tests/test_response_parser.py +++ b/tests/test_response_parser.py @@ -11,14 +11,14 @@ from unittest.mock import patch from imapclient.datetime_util import datetime_to_native +from imapclient.exceptions import ProtocolError from imapclient.fixed_offset import FixedOffset from imapclient.response_parser import ( - parse_response, - parse_message_list, parse_fetch_response, + parse_message_list, + parse_response, ) -from imapclient.response_types import Envelope, Address -from imapclient.exceptions import ProtocolError +from imapclient.response_types import Address, Envelope # TODO: test invalid dates and times diff --git a/tests/test_search.py b/tests/test_search.py index 9fa5a546..07a8fa79 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -2,13 +2,13 @@ # Released subject to the New BSD License # Please see http://en.wikipedia.org/wiki/BSD_licenses +import imaplib from datetime import date, datetime from unittest.mock import Mock -import imaplib - from imapclient.exceptions import InvalidCriteriaError from imapclient.imapclient import _quoted + from .imapclient_test import IMAPClientTest diff --git a/tests/test_starttls.py b/tests/test_starttls.py index 556d380c..218baf7f 100644 --- a/tests/test_starttls.py +++ b/tests/test_starttls.py @@ -4,8 +4,8 @@ from unittest.mock import Mock, patch, sentinel -from imapclient.imapclient import IMAPClient from imapclient.exceptions import IMAPClientError +from imapclient.imapclient import IMAPClient from .imapclient_test import IMAPClientTest diff --git a/tests/test_store.py b/tests/test_store.py index 439ccdf5..faee481b 100644 --- a/tests/test_store.py +++ b/tests/test_store.py @@ -3,9 +3,10 @@ # Released subject to the New BSD License # Please see http://en.wikipedia.org/wiki/BSD_licenses -from unittest.mock import patch, sentinel, Mock +from unittest.mock import Mock, patch, sentinel + +from imapclient.imapclient import ANSWERED, DELETED, DRAFT, FLAGGED, RECENT, SEEN -from imapclient.imapclient import DELETED, SEEN, ANSWERED, FLAGGED, DRAFT, RECENT from .imapclient_test import IMAPClientTest diff --git a/tests/test_util_functions.py b/tests/test_util_functions.py index d1315ded..1049edd1 100644 --- a/tests/test_util_functions.py +++ b/tests/test_util_functions.py @@ -6,12 +6,12 @@ from imapclient.exceptions import InvalidCriteriaError, ProtocolError from imapclient.imapclient import ( - join_message_ids, _normalise_search_criteria, + _quoted, + join_message_ids, normalise_text_list, seq_to_parenstr, seq_to_parenstr_upper, - _quoted, ) from imapclient.util import assert_imap_protocol diff --git a/tox.ini b/tox.ini index b1bec50a..3fc8c9d0 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] skipsdist = True minversion = 3.0 -envlist=py37,py38,py39,py310,py311,black,flake8 +envlist=py37,py38,py39,py310,py311,black,isort,flake8 [testenv] commands=python -m unittest @@ -17,6 +17,11 @@ basepython = python3 commands = flake8 {posargs} . +[testenv:isort] +basepython = python3 +commands = + isort {posargs} . + [flake8] exclude = .git,.venv,.tox,dist,doc,*egg,build, max-line-length = 88