Skip to content

Commit

Permalink
Autosort imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Apr 8, 2022
1 parent 9fe5466 commit 0dfceb9
Show file tree
Hide file tree
Showing 24 changed files with 169 additions and 803 deletions.
9 changes: 4 additions & 5 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ exclude=
typings/cv2-stubs/__init__.pyi, ; External existing stub
ignore=
W503, ; Linebreak before binary operator
Y015, ; Allow default value other than "..."
E402, ; Allow imports at the bottom of file
Y026, ; Not using typing_extensions
per-file-ignores=
; allow ... on same line as def
; ???
; Docstrings in type stubs
; Function bodys contain other than just ... (eg: raise)
; Single quote docstrings
typings/cv2-stubs/__init__.pyi: Q000,N8, E704,Y021,Y010,Q002
typings/cv2-stubs/__init__.pyi: Q000,N8,E704, Y021,Y010,Q002

; Quotes
; Naming conventions can't be controlled for external libraries
__init__.pyi: Q000,N8
; allow ... on same line as def
__init__.pyi: Q000,N8,E704
QtTest.pyi: Q000,N8,E704
; PyQt methods
ignore-names=closeEvent,paintEvent,keyPressEvent,mousePressEvent,mouseMoveEvent,mouseReleaseEvent
; McCabe max-complexity is also taken care of by Pylint and doesn't fail the build there
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.fixAll.markdownlint": true,
"source.organizeImports": true,
},
"files.insertFinalNewline": true,
"trailing-spaces.includeEmptyLines": true,
Expand Down
2 changes: 1 addition & 1 deletion PyInstaller/hooks/hook-cv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
https://github.com/pyinstaller/pyinstaller-hooks-contrib/blob/master/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-cv2.py
"""

from PyInstaller.utils.hooks import collect_dynamic_libs, collect_data_files
from PyInstaller.utils.hooks import collect_data_files, collect_dynamic_libs

hiddenimports = ["numpy"]

Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,7 @@ disable = [

[tool.pylint.TYPECHECK]
generated-members = "cv2"

[tool.isort]
line_length = 120
combine_as_imports = true
4 changes: 3 additions & 1 deletion scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ PySide6
pyautogui
pywin32
requests
# Linting and Types
# Linting, formatters and Types
bandit
isort
flake8
flake8-pyi
flake8-quotes
flake8-isort
pylint>=2.13
git+https://github.com/Avasam/pywin32-stubs.git#egg=pywin32-stubs # https://github.com/kaluluosi/pywin32-stubs/pull/4
simplejson
Expand Down
7 changes: 5 additions & 2 deletions src/AutoControlledWorker.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from __future__ import annotations

from typing import TYPE_CHECKING
if TYPE_CHECKING:
from AutoSplit import AutoSplit

from PyQt6 import QtCore

import error_messages
import settings_file as settings

if TYPE_CHECKING:
from AutoSplit import AutoSplit


class AutoControlledWorker(QtCore.QObject):
def __init__(self, autosplit: AutoSplit):
Expand Down
20 changes: 10 additions & 10 deletions src/AutoSplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@
# - Externals
# - Internals
from __future__ import annotations
from collections.abc import Callable
from types import FunctionType, TracebackType
from typing import Optional, Union

import sys
import os
import ctypes
import os
import signal
import sys
import traceback
from collections.abc import Callable
from time import time
from types import FunctionType, TracebackType
from typing import Optional, Union

import certifi
import cv2
from PyQt6 import QtCore, QtGui
from PyQt6.QtTest import QTest
from PyQt6.QtWidgets import QApplication, QFileDialog, QMainWindow, QMessageBox, QWidget
from win32 import win32gui
from AutoSplitImage import COMPARISON_RESIZE, AutoSplitImage, ImageType

import error_messages
import settings_file as settings
from AutoControlledWorker import AutoControlledWorker
from AutoSplitImage import COMPARISON_RESIZE, AutoSplitImage, ImageType
from capture_windows import capture_region, set_ui_image
from gen import about, design, settings as settings_ui, update_checker
from hotkeys import send_command, after_setting_hotkey
from menu_bar import get_default_settings_from_ui, open_about, VERSION, open_settings, view_help, check_for_updates, \
open_update_checker
from screen_region import select_region, select_window, align_region, validate_before_parsing
from hotkeys import after_setting_hotkey, send_command
from menu_bar import (VERSION, check_for_updates, get_default_settings_from_ui, open_about, open_settings,
open_update_checker, view_help)
from screen_region import align_region, select_region, select_window, validate_before_parsing
from settings_file import FROZEN
from split_parser import BELOW_FLAG, DUMMY_FLAG, PAUSE_FLAG, parse_and_validate_images

Expand Down
15 changes: 7 additions & 8 deletions src/AutoSplitImage.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from __future__ import annotations

from enum import Enum
import os
from typing import Optional, Union, TYPE_CHECKING
if TYPE_CHECKING:
from AutoSplit import AutoSplit
from enum import Enum
from typing import TYPE_CHECKING, Optional, Union

import cv2
import numpy as np
from win32con import MAXBYTE

import error_messages
from compare import check_if_image_has_transparency, compare_histograms, compare_l2_norm, compare_phash
from split_parser import (delay_from_filename, flags_from_filename, loop_from_filename, pause_from_filename,
threshold_from_filename)

if TYPE_CHECKING:
from AutoSplit import AutoSplit

# Resize to these width and height so that FPS performance increases
COMPARISON_RESIZE_WIDTH = 320
Expand Down Expand Up @@ -120,7 +123,3 @@ def compare_with_capture(
if comparison_method == 2:
return compare_phash(self.bytes, capture, self.mask)
return 0.0


from split_parser import delay_from_filename, flags_from_filename, loop_from_filename, pause_from_filename, \
threshold_from_filename
8 changes: 4 additions & 4 deletions src/capture_windows.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from __future__ import annotations
from typing import Optional, cast

import ctypes
import ctypes.wintypes
from dataclasses import dataclass
from PyQt6 import QtCore, QtGui
from PyQt6.QtWidgets import QLabel
from typing import Optional, cast

import cv2
import numpy as np
import pywintypes
import win32con
import win32ui
import pywintypes
from PyQt6 import QtCore, QtGui
from PyQt6.QtWidgets import QLabel
from win32 import win32gui

# This is an undocumented nFlag value for PrintWindow
Expand Down
6 changes: 4 additions & 2 deletions src/compare.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import annotations

from typing import Optional
from PIL import Image
from win32con import MAXBYTE

import cv2
import imagehash # https://github.com/JohannesBuchner/imagehash/issues/151
import numpy as np
from PIL import Image
from win32con import MAXBYTE

MAXRANGE = MAXBYTE + 1
channels = [0, 1, 2]
Expand Down
2 changes: 1 addition & 1 deletion src/error_messages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Error messages
import traceback

from PyQt6 import QtCore, QtWidgets


Expand Down
11 changes: 6 additions & 5 deletions src/hotkeys.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from __future__ import annotations
from typing import Literal, Optional, TYPE_CHECKING, Union
from collections.abc import Callable

if TYPE_CHECKING:
from AutoSplit import AutoSplit

import threading
from collections.abc import Callable
from typing import TYPE_CHECKING, Literal, Optional, Union

import keyboard # https://github.com/boppreh/keyboard/issues/505
import pyautogui # https://github.com/asweigart/pyautogui/issues/645

if TYPE_CHECKING:
from AutoSplit import AutoSplit

# While not usually recommended, we don't manipulate the mouse, and we don't want the extra delay
pyautogui.FAILSAFE = False

Expand Down
12 changes: 6 additions & 6 deletions src/menu_bar.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
from __future__ import annotations
from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
from AutoSplit import AutoSplit

import webbrowser
from typing import TYPE_CHECKING, Any

import requests
from simplejson.errors import JSONDecodeError
from packaging import version
from PyQt6 import QtWidgets
from PyQt6.QtCore import QThread
from requests.exceptions import RequestException
from simplejson.errors import JSONDecodeError

import error_messages
import settings_file as settings
from capture_windows import Region
from gen import about, design, resources_rc, settings as settings_ui, update_checker # noqa: F401
from hotkeys import set_split_hotkey, set_reset_hotkey, set_skip_split_hotkey, set_undo_split_hotkey, set_pause_hotkey
from hotkeys import set_pause_hotkey, set_reset_hotkey, set_skip_split_hotkey, set_split_hotkey, set_undo_split_hotkey

if TYPE_CHECKING:
from AutoSplit import AutoSplit

# AutoSplit Version number
VERSION = "1.6.1"
Expand Down
12 changes: 6 additions & 6 deletions src/screen_region.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from __future__ import annotations
from typing import cast, TYPE_CHECKING
if TYPE_CHECKING:
from AutoSplit import AutoSplit

import os
import ctypes
import ctypes.wintypes
import cv2
import os
from typing import TYPE_CHECKING, cast

import cv2
import numpy as np
from PyQt6 import QtCore, QtGui, QtWidgets
from PyQt6.QtTest import QTest
from win32 import win32gui
from win32con import GA_ROOT, MAXBYTE, SM_XVIRTUALSCREEN, SM_YVIRTUALSCREEN, SM_CXVIRTUALSCREEN, SM_CYVIRTUALSCREEN
from win32con import GA_ROOT, MAXBYTE, SM_CXVIRTUALSCREEN, SM_CYVIRTUALSCREEN, SM_XVIRTUALSCREEN, SM_YVIRTUALSCREEN

import capture_windows
import error_messages

if TYPE_CHECKING:
from AutoSplit import AutoSplit

WINDOWS_SHADOW_SIZE = 8
WINDOWS_TOPBAR_SIZE = 24
Expand Down
12 changes: 6 additions & 6 deletions src/settings_file.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from __future__ import annotations
from typing import TYPE_CHECKING, Any, TypedDict

if TYPE_CHECKING:
from AutoSplit import AutoSplit

import os
import sys
import pickle
import sys
from typing import TYPE_CHECKING, Any, TypedDict

import keyboard # https://github.com/boppreh/keyboard/issues/505
from win32 import win32gui
from PyQt6 import QtCore, QtWidgets
from win32 import win32gui

import error_messages
from capture_windows import Region
from gen import design
from hotkeys import set_pause_hotkey, set_reset_hotkey, set_skip_split_hotkey, set_split_hotkey, set_undo_split_hotkey

if TYPE_CHECKING:
from AutoSplit import AutoSplit

# Keyword "frozen" is for setting basedir while in onefile mode in pyinstaller
FROZEN = hasattr(sys, "frozen")
# Get the directory of either AutoSplit.exe or AutoSplit.py
Expand Down
6 changes: 3 additions & 3 deletions src/split_parser.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from AutoSplit import AutoSplit

import os
from typing import TYPE_CHECKING

import error_messages
from AutoSplitImage import AutoSplitImage, ImageType

if TYPE_CHECKING:
from AutoSplit import AutoSplit

[DUMMY_FLAG,
BELOW_FLAG,
Expand Down
2 changes: 1 addition & 1 deletion typings/PyInstaller/utils/hooks/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" # noqa: Y021
This type stub file was generated by pyright.
"""
from typing import Any, Literal, Optional, Union, Callable
from typing import Any, Callable, Literal, Optional, Union

logger = ...
PY_IGNORE_EXTENSIONS: set
Expand Down
4 changes: 3 additions & 1 deletion typings/PyQt6/QtTest.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import typing

import PyQt6.sip

# Email sent to [email protected]


class QTest(PyQt6.sip.simplewrapper):
# Email sent to [email protected]
@typing.overload
@staticmethod
def qWait(ms: int) -> None: ...
Expand Down
Loading

0 comments on commit 0dfceb9

Please sign in to comment.