Skip to content

Commit

Permalink
First linting pass
Browse files Browse the repository at this point in the history
Configured VSCode and Markdownlint settings
Added and configured the following linters as strict as I could: pylint, flake8, mypy, bandit, pyright
Partially filled in some type stubs: cv2, imagehash, keyboard, pyautogui, pythonwin, win32helper
[Breaking change] Using interpolation=cv2.INTER_NEAREST everywhere as it is the fastest interlpolation method
Hide generated/compiled files
SelectRegionWidget width and height as functions
Added validate_images_before_parsing() to validate images both before maxFPS and starting autosplitter
  • Loading branch information
Avasam committed Nov 29, 2021
1 parent 3cb2aa6 commit 3f23c55
Show file tree
Hide file tree
Showing 48 changed files with 120,602 additions and 4,007 deletions.
14 changes: 14 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[flake8]
color=always
max-line-length=120
; TODO: Bring WAY down
max-complexity=55
; Auto generated
exclude=src/gen/
; TODO: We want to configure this
ignore=W503,N801,N802,N803,N806,N815,N816
per-file-ignores =
; imported but unused
; line too long
; mixed case
__init__.pyi:F401,E501,N816
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ __pycache__/
env/
build/
dist/
# Generated
**/gen/*.py
!**/gen/*.pyi

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
5 changes: 5 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"default": true,
"MD025": false,
"MD013": false
}
33 changes: 33 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
; https://mypy.readthedocs.io/en/stable/command_line.html#disallow-dynamic-typing
[mypy]
show_column_numbers=True
show_error_codes=True
no_color_output=False
color_output=True

ignore_missing_imports=True
follow_imports=silent

; Note: exclude is ignored when linting file by file so VSCode will still show errors in typings
; typings are incomplete as we only add types for what we need, cannot disable specific rules per file
; Auto generated
exclude=(typings/|src/gen/)

; Redundant
disallow_untyped_defs=False
; Doesn't see our cv2 type stubs
warn_return_any=False
; False positives when it's needed for other linting libraries
warn_unused_ignores=False
; Doesn't see imports from src/gen/
disallow_any_unimported=False
disallow_subclassing_any=False
; False positives with ndarray
disable_error_code=no-untyped-def

strict=True
; Doesn't see types from some imports
disallow_any_expr=False
disallow_any_decorated=True
disallow_any_explicit=True
warn_unreachable=True
23 changes: 23 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; http://pylint-messages.wikidot.com/all-codes
[MASTER]
max-line-length=120
ignore-paths=
; Haven't looked into disabling specific rules per file
^typings/.*$,
; Auto generated
^src/gen/.*$
disable=
missing-docstring,
; TODO: We want to configure this
; https://pylint.pycqa.org/en/latest/user_guide/options.html#naming-styles
invalid-name,
; We group imports
wrong-import-position,
; Already taken care of and grayed out. Also conflicts with Pylance reportIncompatibleMethodOverride
unused-argument,
; Already taken care of by Flake8
unused-import,
extension-pkg-allow-list=PyQt6,win32ui

[TYPECHECK]
generated-members=cv2
62 changes: 32 additions & 30 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,29 @@
120,
]
},
// Keeping autoformat to false for now to keep minimal changes
"editor.formatOnSave": false,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": false,
},
"python.linting.enabled": true,
"python.analysis.typeCheckingMode": "basic",
"python.analysis.diagnosticSeverityOverrides": {
// Too many false positives with pywin32 (all functions have 0 arguments in type stub)
"reportGeneralTypeIssues":"none"
"source.fixAll": true,
"source.fixAll.markdownlint": true,
},
// Set to trace when sending error reports to Pylance
// "python.analysis.logLevel": "Trace",
// https://code.visualstudio.com/docs/python/linting#_specific-linters
// Maybe consider PyLint once all Flake8 linting is fixed
"python.linting.pylintEnabled": false,
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.linting.pylintCategorySeverity.convention": "Warning",
"python.linting.pylintCategorySeverity.refactor": "Warning",
"python.linting.flake8Enabled": true,
"python.linting.flake8CategorySeverity.E": "Warning",
"python.linting.mypyEnabled": true,
// Flake8 is already a pycodestyle wrapper
// Is already wrapped by Flake8, prospector and pylama
"python.linting.pycodestyleEnabled": false,
"python.linting.pylintArgs": [
"--disable=no-member",
"--max-line-length=120"
],
"python.linting.flake8CategorySeverity.E": "Warning",
"python.linting.flake8Args": [
"--max-line-length=120"
],
"python.linting.mypyArgs": [
"--max-line-length=120"
],
"python.formatting.autopep8Args": [
"--max-line-length=120"
],
// Just another wrapper, use Flake8 OR this
"python.linting.prospectorEnabled": false,
// Just another wrapper, use Flake8 OR this
"python.linting.pylamaEnabled": false,
"python.linting.banditEnabled": true,
"files.insertFinalNewline": true,
"trailing-spaces.deleteModifiedLinesOnly": true,
"trailing-spaces.includeEmptyLines": true,
"trailing-spaces.trimOnSave": true,
"trailing-spaces.syntaxIgnore": [
Expand All @@ -61,8 +50,21 @@
"*.qrc": "xml",
"*.ui": "xml"
},
"markdownlint.config": {
"default": true,
"MD025": false,
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"build": true,
".mypy_cache": true,
"**/__pycache__": true,
},
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/*.code-search": true,
"typings": true,
}
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ This program can be used to automatically start, split, and reset your preferred

(This is not required for normal use)

- Microsoft Visual C++ 14.0 or greater may be required. Get it with [Microsoft C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/)
- Microsoft Visual C++ 14.0 or greater may be required to build the executable. Get it with [Microsoft C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/)
- Node is optional, but required for complete linting (using Pyright).
- Read [requirements.txt](/scripts/requirements.txt) for information on how to install, run and build the python code
- Run `.\scripts\install.bat` to install all dependencies
- Run the app directly with `py .\src\AutoSplit.py [--auto-controlled]`
Expand Down Expand Up @@ -195,6 +196,7 @@ The AutoSplit LiveSplit Component will directly connect AutoSplit with LiveSplit
## Resources

Still need help?

- [Open an issue](../../issues)
- Join the [AutoSplit Discord](https://discord.gg/Qcbxv9y)

Expand Down
19 changes: 19 additions & 0 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"typeCheckingMode": "strict",
// Auto generated
"ignore": [
// "src/gen/",
"typings/",
],
"reportMissingTypeStubs": "information",
// False positives with TYPE_CHECKING
"reportImportCycles": "information",
// PyQt .connect
"reportFunctionMemberAccess": "information",
// Extra runtime safety
"reportUnnecessaryComparison": "warning",
// Flake8 does a better job
"reportUnusedImport": "none",
// numpy has way too many complex types that triggers this
"reportUnknownMemberType": "none",
}
10 changes: 8 additions & 2 deletions res/about.ui
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ consider donating. Thank you!</string>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;amp;business=BYRHQG69YRHBA&amp;amp;item_name=AutoSplit+development&amp;amp;currency_code=USD&amp;amp;source=url&quot;&gt;&lt;img src=&quot;:/resources/btn_donateCC_LG.png&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string/>
</property>
<property name="pixmap">
<pixmap resource="resources.qrc">:/resources/btn_donateCC_LG.png</pixmap>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
Expand All @@ -116,7 +119,10 @@ consider donating. Thank you!</string>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;img src=&quot;:/resources/icon.ico&quot;/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string/>
</property>
<property name="pixmap">
<pixmap resource="resources.qrc">:/resources/icon.ico</pixmap>
</property>
</widget>
</widget>
Expand Down
8 changes: 7 additions & 1 deletion res/update_checker.ui
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
<property name="windowTitle">
<string>Update Checker</string>
</property>
<property name="windowIcon">
<iconset resource="resources.qrc">
<normaloff>:/resources/icon.ico</normaloff>:/resources/icon.ico</iconset>
</property>
<widget class="QLabel" name="labelUpdateStatus">
<property name="geometry">
<rect>
Expand Down Expand Up @@ -169,7 +173,9 @@
</property>
</widget>
</widget>
<resources/>
<resources>
<include location="resources.qrc"/>
</resources>
<connections>
<connection>
<sender>pushButtonRight</sender>
Expand Down
1 change: 1 addition & 0 deletions scripts/build.bat
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
CALL "%~p0compile_resources.bat"
pyinstaller -w -F --icon=res\icon.ico "%~p0..\src\AutoSplit.py"
8 changes: 4 additions & 4 deletions scripts/compile_resources.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cd "%~dp0.."
pyuic6 ".\res\about.ui" -o ".\src\about.py"
pyuic6 ".\res\design.ui" -o ".\src\design.py"
pyuic6 ".\res\update_checker.ui" -o ".\src\update_checker.py"
pyside6-rcc ".\res\resources.qrc" -o ".\src\resources_rc.py"
pyuic6 ".\res\about.ui" -o ".\src\gen\about.py"
pyuic6 ".\res\design.ui" -o ".\src\gen\design.py"
pyuic6 ".\res\update_checker.ui" -o ".\src\gen\update_checker.py"
pyside6-rcc ".\res\resources.qrc" -o ".\src\gen\resources_rc.py"
4 changes: 4 additions & 0 deletions scripts/install.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
py -3.9 -m pip install wheel
py -3.9 -m pip install -r "%~p0requirements.txt"
@REM https://github.com/python/mypy/issues/10600 --non-interactive may still have issues
mypy --install-types --non-interactive
npm install -g pyright
CALL "%~p0compile_resources.bat"
8 changes: 8 additions & 0 deletions scripts/lint.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pylint --score=n --output-format=text,colorized $(git ls-files '**/*.py*')
# pylint --reports=y --output-format=text,colorized $(git ls-files '**/*.py*')
mypy .
# mypy --pretty src
pyright
bandit -f custom --silent --severity-level medium -r .
# bandit -n 1 --severity-level medium -r src
flake8
7 changes: 5 additions & 2 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@
# Usage: .\scripts\install.bat
#
# If you're having issues with the libraries, you might want to first run:
# pip3.9 uninstall -r requirements.txt
# pip3.9 uninstall -r .\scripts\requirements.txt
#
# Creating AutoSplit.exe with PyInstaller: .\scripts\build.bat
#
# Dependencies:
PyQt6
numpy>=1.22.0rc1
opencv-python<=4.5.3.56 # https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/110
PyQt6
Pillow
ImageHash
pywin32
pywin32-stubs
keyboard
packaging
pyautogui
PySide6
flake8
mypy
pylint
requests
#
# Comment this out if you don't want to build AutoSplit.exe:
Expand Down
2 changes: 2 additions & 0 deletions scripts/start.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CALL "%~p0compile_resources.bat"
py -3.9 "%~p0..\src\AutoSplit.py"
42 changes: 42 additions & 0 deletions src/AutoControlledWorker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from AutoSplit import AutoSplit
from PyQt6 import QtCore

import error_messages


class AutoControlledWorker(QtCore.QObject):
def __init__(self, autosplit: AutoSplit):
self.autosplit = autosplit
super().__init__()

def run(self):
while True:
try:
line = input()
except RuntimeError:
self.autosplit.showErrorSignal.emit(error_messages.stdinLostError)
break
# TODO: "AutoSplit Integration" needs to call this and wait instead of outright killing the app.
# TODO: See if we can also get LiveSplit to wait on Exit in "AutoSplit Integration"
# For now this can only used in a Development environment
if line == 'kill':
self.autosplit.closeEvent()
break
elif line == 'start':
self.autosplit.startAutoSplitter()
elif line == 'split' or line == 'skip':
self.autosplit.startSkipSplit()
elif line == 'undo':
self.autosplit.startUndoSplit()
elif line == 'reset':
self.autosplit.startReset()
elif line.startswith('settings'):
# Allow for any split character between "settings" and the path
self.autosplit.load_settings_file_path = line[9:]
self.autosplit.loadSettings(load_settings_from_livesplit=True)
# TODO: Not yet implemented in AutoSplit Integration
# elif line == 'pause':
# self.startPause()
Loading

0 comments on commit 3f23c55

Please sign in to comment.