Skip to content

Commit

Permalink
chore: add use of the isort linter
Browse files Browse the repository at this point in the history
  * Add the `isort` linter https://pycqa.github.io/isort/
  * Add a `tox` environment to run `isort`
  * Enable it in the GitHub CI
  * Run it on all the code.
  • Loading branch information
JohnVillalovos committed Aug 18, 2023
1 parent 2768fc3 commit 1e0af9e
Show file tree
Hide file tree
Showing 23 changed files with 59 additions and 47 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions imapclient/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion imapclient/fixed_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
18 changes: 8 additions & 10 deletions imapclient/imapclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion imapclient/interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions imapclient/response_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
3 changes: 2 additions & 1 deletion imapclient/testable_imapclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions livetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[tool.isort]
profile = "black"
multi_line_output = 3
order_by_type = false
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sphinx
black==22.3.0
flake8==4.0.1
isort==5.12.0
3 changes: 2 additions & 1 deletion tests/imapclient_test.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
1 change: 1 addition & 0 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Please see http://en.wikipedia.org/wiki/BSD_licenses

from imapclient.exceptions import LoginError

from .imapclient_test import IMAPClientTest


Expand Down
3 changes: 1 addition & 2 deletions tests/test_datetime_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions tests/test_enable.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from unittest.mock import Mock

from imapclient.exceptions import IllegalStateError

from .imapclient_test import IMAPClientTest


Expand Down
4 changes: 2 additions & 2 deletions tests/test_fixed_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 6 additions & 7 deletions tests/test_imapclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions tests/test_response_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion tests/test_starttls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions tests/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions tests/test_util_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down

0 comments on commit 1e0af9e

Please sign in to comment.