Skip to content

Commit

Permalink
Upgrade to isort 5 (#2164)
Browse files Browse the repository at this point in the history
* Upgrade to isort 5

isort 5 now can also handle imports not at top, hence some new locations now get sorted automatically.

* Move isort config from .isort.cfg to pyproject.toml

* isort: remove exclusion of some source files

isort now only ignores auto-generated files. The other files had been excluded because old isort could not handle imports not placed on the top.

* isort: use skip_glob to ignore resources.py

This should fix issues with the `skip` parameter on Windows.
  • Loading branch information
phw authored Oct 29, 2022
1 parent a86d592 commit e46419f
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
pip install -r requirements.txt
- name: Check coding style
run: |
pip install flake8 "isort<5"
pip install flake8 "isort>=5"
flake8 picard test --count --show-source --statistics
isort --check-only --diff --recursive picard test
- name: Test with pytest
Expand Down
28 changes: 0 additions & 28 deletions .isort.cfg

This file was deleted.

11 changes: 9 additions & 2 deletions picard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,15 @@ def crash_handler():

# Display the crash information to the user as a dialog. This requires
# importing Qt5 and has some potential to fail if things are broken.
from PyQt5.QtCore import QCoreApplication, Qt, QUrl
from PyQt5.QtWidgets import QApplication, QMessageBox
from PyQt5.QtCore import (
QCoreApplication,
Qt,
QUrl,
)
from PyQt5.QtWidgets import (
QApplication,
QMessageBox,
)
app = QCoreApplication.instance()
if not app:
app = QApplication(sys.argv)
Expand Down
25 changes: 16 additions & 9 deletions picard/const/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
from collections import OrderedDict

from picard import PICARD_VERSION
from picard.const.attributes import MB_ATTRIBUTES
from picard.const import appdirs
from picard.const.attributes import MB_ATTRIBUTES


# Install gettext "noop" function in case const.py gets imported directly.
builtins.__dict__['N_'] = lambda a: a
Expand Down Expand Up @@ -112,17 +113,23 @@
elif k.startswith('DB:release_status/name:'):
RELEASE_STATUS[v] = v

# List of available charsets
from picard.const.scripts import SCRIPTS # noqa: F401,E402 # pylint: disable=unused-import

# Release countries
from picard.const.countries import RELEASE_COUNTRIES # noqa: F401,E402 # pylint: disable=unused-import

from picard.const.countries import ( # noqa: F401,E402 # pylint: disable=unused-import
RELEASE_COUNTRIES,
)
# List of available user interface languages
from picard.const.languages import UI_LANGUAGES # noqa: F401,E402 # pylint: disable=unused-import

from picard.const.languages import ( # noqa: F401,E402 # pylint: disable=unused-import
UI_LANGUAGES,
)
# List of alias locales
from picard.const.locales import ALIAS_LOCALES # noqa: F401,E402 # pylint: disable=unused-import
from picard.const.locales import ( # noqa: F401,E402 # pylint: disable=unused-import
ALIAS_LOCALES,
)
# List of available charsets
from picard.const.scripts import ( # noqa: F401,E402 # pylint: disable=unused-import
SCRIPTS,
)


# List of official musicbrainz servers - must support SSL for mblogin requests (such as collections).
MUSICBRAINZ_SERVERS = [
Expand Down
4 changes: 2 additions & 2 deletions picard/formats/mutagenext/tak.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@

try:
from mutagen.tak import (
Open,
TAK,
Open,
TAKHeaderError,
TAKInfo,
delete
delete,
)

native_tak = True
Expand Down
2 changes: 1 addition & 1 deletion picard/formats/wav.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@


try:
import mutagen.wave
from mutagen._iff import assert_valid_chunk_id
from mutagen._riff import RiffFile
from mutagen._util import loadfile
import mutagen.wave

# See https://exiftool.org/TagNames/RIFF.html
TRANSLATE_RIFF_INFO = {
Expand Down
2 changes: 1 addition & 1 deletion picard/util/filenaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
win32api = None
if IS_WIN:
try:
import win32api # isort:skip
import pywintypes
import win32api
except ImportError as e:
log.warning('pywin32 not available: %s', e)

Expand Down
1 change: 1 addition & 0 deletions picard/util/imagelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def _update_state(obj, state):
# TODO: use functools.singledispatch when py3 is supported
def _get_state(obj):
from picard.album import Album

from picard.ui.item import FileListItem

state = ImageListState()
Expand Down
4 changes: 2 additions & 2 deletions picard/util/pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@


if IS_WIN:
import win32pipe # type: ignore
import win32file # type: ignore
from pywintypes import error as WinApiError # type: ignore
import win32file # type: ignore
import win32pipe # type: ignore


class PipeError(Exception):
Expand Down
24 changes: 24 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
[build-system]
requires = ["setuptools>=62.4.0"]
build-backend = "setuptools.build_meta"

[tool.isort]
sections = [
"FUTURE", "STDLIB", "THIRDPARTY", "QT", "TEST", "PICARD", "LOCALFOLDER",
"RESOURCES", "PICARD_UI"
]
default_section = "LOCALFOLDER"
known_picard = ["picard"]
known_picard_ui = ["picard.ui"]
known_qt = ["PyQt5"]
known_resources = ["picard.resources"]
known_test = ["test.*"]
known_third_party = ["dateutil", "fasteners", "mutagen", "yaml"]
skip_glob = ["**/ui_*.py", "picard/resources.py"]
combine_as_imports = true
float_to_top = false
force_grid_wrap = 2
force_sort_within_sections = true
include_trailing_comma = true
indent = " "
lines_after_imports = 2
multi_line_output = 3
order_by_type = true
use_parentheses = true
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
autopep8
Babel>=2.6.0
flake8
isort>=4.3.10,<5
isort>=5.0
pycodestyle
pylint>=2.6.0
transifex-client

0 comments on commit e46419f

Please sign in to comment.