Skip to content

Commit 0dfceb9

Browse files
committed
Autosort imports
1 parent 9fe5466 commit 0dfceb9

24 files changed

+169
-803
lines changed

.flake8

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ exclude=
66
typings/cv2-stubs/__init__.pyi, ; External existing stub
77
ignore=
88
W503, ; Linebreak before binary operator
9-
Y015, ; Allow default value other than "..."
109
E402, ; Allow imports at the bottom of file
1110
Y026, ; Not using typing_extensions
1211
per-file-ignores=
13-
; allow ... on same line as def
14-
; ???
1512
; Docstrings in type stubs
1613
; Function bodys contain other than just ... (eg: raise)
1714
; Single quote docstrings
18-
typings/cv2-stubs/__init__.pyi: Q000,N8, E704,Y021,Y010,Q002
15+
typings/cv2-stubs/__init__.pyi: Q000,N8,E704, Y021,Y010,Q002
1916

2017
; Quotes
2118
; Naming conventions can't be controlled for external libraries
22-
__init__.pyi: Q000,N8
19+
; allow ... on same line as def
20+
__init__.pyi: Q000,N8,E704
21+
QtTest.pyi: Q000,N8,E704
2322
; PyQt methods
2423
ignore-names=closeEvent,paintEvent,keyPressEvent,mousePressEvent,mouseMoveEvent,mouseReleaseEvent
2524
; McCabe max-complexity is also taken care of by Pylint and doesn't fail the build there

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"editor.codeActionsOnSave": {
1515
"source.fixAll": true,
1616
"source.fixAll.markdownlint": true,
17+
"source.organizeImports": true,
1718
},
1819
"files.insertFinalNewline": true,
1920
"trailing-spaces.includeEmptyLines": true,

PyInstaller/hooks/hook-cv2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
https://github.com/pyinstaller/pyinstaller-hooks-contrib/blob/master/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-cv2.py
1313
"""
1414

15-
from PyInstaller.utils.hooks import collect_dynamic_libs, collect_data_files
15+
from PyInstaller.utils.hooks import collect_data_files, collect_dynamic_libs
1616

1717
hiddenimports = ["numpy"]
1818

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,7 @@ disable = [
125125

126126
[tool.pylint.TYPECHECK]
127127
generated-members = "cv2"
128+
129+
[tool.isort]
130+
line_length = 120
131+
combine_as_imports = true

scripts/requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ PySide6
2222
pyautogui
2323
pywin32
2424
requests
25-
# Linting and Types
25+
# Linting, formatters and Types
2626
bandit
27+
isort
2728
flake8
2829
flake8-pyi
2930
flake8-quotes
31+
flake8-isort
3032
pylint>=2.13
3133
git+https://github.com/Avasam/pywin32-stubs.git#egg=pywin32-stubs # https://github.com/kaluluosi/pywin32-stubs/pull/4
3234
simplejson

src/AutoControlledWorker.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
from __future__ import annotations
2+
23
from typing import TYPE_CHECKING
3-
if TYPE_CHECKING:
4-
from AutoSplit import AutoSplit
4+
55
from PyQt6 import QtCore
66

77
import error_messages
88
import settings_file as settings
99

10+
if TYPE_CHECKING:
11+
from AutoSplit import AutoSplit
12+
1013

1114
class AutoControlledWorker(QtCore.QObject):
1215
def __init__(self, autosplit: AutoSplit):

src/AutoSplit.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,34 @@
77
# - Externals
88
# - Internals
99
from __future__ import annotations
10-
from collections.abc import Callable
11-
from types import FunctionType, TracebackType
12-
from typing import Optional, Union
1310

14-
import sys
15-
import os
1611
import ctypes
12+
import os
1713
import signal
14+
import sys
1815
import traceback
16+
from collections.abc import Callable
1917
from time import time
18+
from types import FunctionType, TracebackType
19+
from typing import Optional, Union
2020

2121
import certifi
2222
import cv2
2323
from PyQt6 import QtCore, QtGui
2424
from PyQt6.QtTest import QTest
2525
from PyQt6.QtWidgets import QApplication, QFileDialog, QMainWindow, QMessageBox, QWidget
2626
from win32 import win32gui
27-
from AutoSplitImage import COMPARISON_RESIZE, AutoSplitImage, ImageType
2827

2928
import error_messages
3029
import settings_file as settings
3130
from AutoControlledWorker import AutoControlledWorker
31+
from AutoSplitImage import COMPARISON_RESIZE, AutoSplitImage, ImageType
3232
from capture_windows import capture_region, set_ui_image
3333
from gen import about, design, settings as settings_ui, update_checker
34-
from hotkeys import send_command, after_setting_hotkey
35-
from menu_bar import get_default_settings_from_ui, open_about, VERSION, open_settings, view_help, check_for_updates, \
36-
open_update_checker
37-
from screen_region import select_region, select_window, align_region, validate_before_parsing
34+
from hotkeys import after_setting_hotkey, send_command
35+
from menu_bar import (VERSION, check_for_updates, get_default_settings_from_ui, open_about, open_settings,
36+
open_update_checker, view_help)
37+
from screen_region import align_region, select_region, select_window, validate_before_parsing
3838
from settings_file import FROZEN
3939
from split_parser import BELOW_FLAG, DUMMY_FLAG, PAUSE_FLAG, parse_and_validate_images
4040

src/AutoSplitImage.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
from __future__ import annotations
22

3-
from enum import Enum
43
import os
5-
from typing import Optional, Union, TYPE_CHECKING
6-
if TYPE_CHECKING:
7-
from AutoSplit import AutoSplit
4+
from enum import Enum
5+
from typing import TYPE_CHECKING, Optional, Union
86

97
import cv2
108
import numpy as np
119
from win32con import MAXBYTE
10+
1211
import error_messages
1312
from compare import check_if_image_has_transparency, compare_histograms, compare_l2_norm, compare_phash
13+
from split_parser import (delay_from_filename, flags_from_filename, loop_from_filename, pause_from_filename,
14+
threshold_from_filename)
1415

16+
if TYPE_CHECKING:
17+
from AutoSplit import AutoSplit
1518

1619
# Resize to these width and height so that FPS performance increases
1720
COMPARISON_RESIZE_WIDTH = 320
@@ -120,7 +123,3 @@ def compare_with_capture(
120123
if comparison_method == 2:
121124
return compare_phash(self.bytes, capture, self.mask)
122125
return 0.0
123-
124-
125-
from split_parser import delay_from_filename, flags_from_filename, loop_from_filename, pause_from_filename, \
126-
threshold_from_filename

src/capture_windows.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
from __future__ import annotations
2-
from typing import Optional, cast
32

43
import ctypes
54
import ctypes.wintypes
65
from dataclasses import dataclass
7-
from PyQt6 import QtCore, QtGui
8-
from PyQt6.QtWidgets import QLabel
6+
from typing import Optional, cast
97

108
import cv2
119
import numpy as np
10+
import pywintypes
1211
import win32con
1312
import win32ui
14-
import pywintypes
13+
from PyQt6 import QtCore, QtGui
14+
from PyQt6.QtWidgets import QLabel
1515
from win32 import win32gui
1616

1717
# This is an undocumented nFlag value for PrintWindow

src/compare.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from __future__ import annotations
2+
23
from typing import Optional
3-
from PIL import Image
4-
from win32con import MAXBYTE
4+
55
import cv2
66
import imagehash # https://github.com/JohannesBuchner/imagehash/issues/151
77
import numpy as np
8+
from PIL import Image
9+
from win32con import MAXBYTE
810

911
MAXRANGE = MAXBYTE + 1
1012
channels = [0, 1, 2]

src/error_messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Error messages
21
import traceback
2+
33
from PyQt6 import QtCore, QtWidgets
44

55

src/hotkeys.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from __future__ import annotations
2-
from typing import Literal, Optional, TYPE_CHECKING, Union
3-
from collections.abc import Callable
4-
5-
if TYPE_CHECKING:
6-
from AutoSplit import AutoSplit
72

83
import threading
4+
from collections.abc import Callable
5+
from typing import TYPE_CHECKING, Literal, Optional, Union
96

107
import keyboard # https://github.com/boppreh/keyboard/issues/505
118
import pyautogui # https://github.com/asweigart/pyautogui/issues/645
9+
10+
if TYPE_CHECKING:
11+
from AutoSplit import AutoSplit
12+
1213
# While not usually recommended, we don't manipulate the mouse, and we don't want the extra delay
1314
pyautogui.FAILSAFE = False
1415

src/menu_bar.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
from __future__ import annotations
2-
from typing import TYPE_CHECKING, Any
3-
4-
if TYPE_CHECKING:
5-
from AutoSplit import AutoSplit
62

73
import webbrowser
4+
from typing import TYPE_CHECKING, Any
85

96
import requests
10-
from simplejson.errors import JSONDecodeError
117
from packaging import version
128
from PyQt6 import QtWidgets
139
from PyQt6.QtCore import QThread
1410
from requests.exceptions import RequestException
11+
from simplejson.errors import JSONDecodeError
1512

1613
import error_messages
1714
import settings_file as settings
1815
from capture_windows import Region
1916
from gen import about, design, resources_rc, settings as settings_ui, update_checker # noqa: F401
20-
from hotkeys import set_split_hotkey, set_reset_hotkey, set_skip_split_hotkey, set_undo_split_hotkey, set_pause_hotkey
17+
from hotkeys import set_pause_hotkey, set_reset_hotkey, set_skip_split_hotkey, set_split_hotkey, set_undo_split_hotkey
18+
19+
if TYPE_CHECKING:
20+
from AutoSplit import AutoSplit
2121

2222
# AutoSplit Version number
2323
VERSION = "1.6.1"

src/screen_region.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
from __future__ import annotations
2-
from typing import cast, TYPE_CHECKING
3-
if TYPE_CHECKING:
4-
from AutoSplit import AutoSplit
52

6-
import os
73
import ctypes
84
import ctypes.wintypes
9-
import cv2
5+
import os
6+
from typing import TYPE_CHECKING, cast
107

8+
import cv2
119
import numpy as np
1210
from PyQt6 import QtCore, QtGui, QtWidgets
1311
from PyQt6.QtTest import QTest
1412
from win32 import win32gui
15-
from win32con import GA_ROOT, MAXBYTE, SM_XVIRTUALSCREEN, SM_YVIRTUALSCREEN, SM_CXVIRTUALSCREEN, SM_CYVIRTUALSCREEN
13+
from win32con import GA_ROOT, MAXBYTE, SM_CXVIRTUALSCREEN, SM_CYVIRTUALSCREEN, SM_XVIRTUALSCREEN, SM_YVIRTUALSCREEN
1614

1715
import capture_windows
1816
import error_messages
1917

18+
if TYPE_CHECKING:
19+
from AutoSplit import AutoSplit
2020

2121
WINDOWS_SHADOW_SIZE = 8
2222
WINDOWS_TOPBAR_SIZE = 24

src/settings_file.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
from __future__ import annotations
2-
from typing import TYPE_CHECKING, Any, TypedDict
3-
4-
if TYPE_CHECKING:
5-
from AutoSplit import AutoSplit
62

73
import os
8-
import sys
94
import pickle
5+
import sys
6+
from typing import TYPE_CHECKING, Any, TypedDict
107

118
import keyboard # https://github.com/boppreh/keyboard/issues/505
12-
from win32 import win32gui
139
from PyQt6 import QtCore, QtWidgets
10+
from win32 import win32gui
1411

1512
import error_messages
1613
from capture_windows import Region
1714
from gen import design
1815
from hotkeys import set_pause_hotkey, set_reset_hotkey, set_skip_split_hotkey, set_split_hotkey, set_undo_split_hotkey
1916

17+
if TYPE_CHECKING:
18+
from AutoSplit import AutoSplit
19+
2020
# Keyword "frozen" is for setting basedir while in onefile mode in pyinstaller
2121
FROZEN = hasattr(sys, "frozen")
2222
# Get the directory of either AutoSplit.exe or AutoSplit.py

src/split_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from __future__ import annotations
2-
from typing import TYPE_CHECKING
3-
if TYPE_CHECKING:
4-
from AutoSplit import AutoSplit
52

63
import os
4+
from typing import TYPE_CHECKING
75

86
import error_messages
97
from AutoSplitImage import AutoSplitImage, ImageType
108

9+
if TYPE_CHECKING:
10+
from AutoSplit import AutoSplit
1111

1212
[DUMMY_FLAG,
1313
BELOW_FLAG,

typings/PyInstaller/utils/hooks/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" # noqa: Y021
22
This type stub file was generated by pyright.
33
"""
4-
from typing import Any, Literal, Optional, Union, Callable
4+
from typing import Any, Callable, Literal, Optional, Union
55

66
logger = ...
77
PY_IGNORE_EXTENSIONS: set

typings/PyQt6/QtTest.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import typing
2+
23
import PyQt6.sip
34

5+
# Email sent to [email protected]
6+
47

58
class QTest(PyQt6.sip.simplewrapper):
6-
# Email sent to [email protected]
79
@typing.overload
810
@staticmethod
911
def qWait(ms: int) -> None: ...

0 commit comments

Comments
 (0)