Skip to content

Commit

Permalink
Option to build without build number + Adaptive mask fix (#189)
Browse files Browse the repository at this point in the history
* Option to build without build number

* Fix repo url from workflow build

* Resize mask with image

* Pin more dependencies, Speed-up installs and update comments

* Add mypy config for optional support.
  • Loading branch information
Avasam authored Dec 23, 2022
1 parent bc0cde0 commit e154acc
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 70 deletions.
18 changes: 12 additions & 6 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ max-line-length=120
; Auto generated
exclude=src/gen/, typings/cv2-stubs/__init__.pyi
ignore=
W503, ; Linebreak before binary operator
E124, ; Closing bracket may not match multi-line method invocation style (enforced by add-trailing-comma)
E402, ; Allow imports at the bottom of file
Y026, ; Not using typing_extensions
SIM105, ; contextlib.suppress is roughly 3x slower than try/except
CCE001, ; False positives for attribute docstrings
; Linebreak before binary operator
W503,
; Closing bracket may not match multi-line method invocation style (enforced by add-trailing-comma)
E124,
; Allow imports at the bottom of file
E402,
; Not using typing_extensions
Y026,
; contextlib.suppress is roughly 3x slower than try/except
SIM105,
; False positives for attribute docstrings
CCE001,
per-file-ignores=
; Quotes
; Allow ... on same line as class
Expand Down
55 changes: 36 additions & 19 deletions .github/workflows/lint-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
name: Lint and build
on:
workflow_dispatch: # Allows manual builds
inputs:
excludeBuildNumber:
description: "Exclude build number"
required: true
default: false
type: boolean
push:
branches:
- main
Expand All @@ -26,23 +32,49 @@ on:

env:
GITHUB_HEAD_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name }}
GITHUB_EXCLUDE_BUILD_NUMBER: ${{ inputs.excludeBuildNumber }}

jobs:
add-trailing-comma:
isort:
runs-on: windows-latest
steps:
- name: Checkout ${{ github.repository }}/${{ github.ref }}
uses: actions/checkout@v3
- name: Set up Python 3.10
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.11"
cache: "pip"
cache-dependency-path: "scripts/requirements*.txt"
- run: scripts/install.ps1
shell: pwsh
- name: Analysing the code with isort
run: isort src/ typings/ --check-only
add-trailing-comma:
runs-on: windows-latest
steps:
- name: Checkout ${{ github.repository }}/${{ github.ref }}
uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
- run: pip install add-trailing-comma
- name: Analysing the code with add-trailing-comma
run: add-trailing-comma $(git ls-files '**.py*') --py36-plus
Bandit:
# Bandit only matters on the version deployed. Platform checks are ignored
runs-on: windows-latest
steps:
- name: Checkout ${{ github.repository }}/${{ github.ref }}
uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
- run: pip install bandit
- name: Analysing the code with Bandit
run: bandit src/ -n 1 --severity-level medium --recursive
Pyright:
runs-on: windows-latest
strategy:
Expand Down Expand Up @@ -106,22 +138,6 @@ jobs:
shell: pwsh
- name: Analysing the code with Flake8
run: flake8 src/ typings/
Bandit:
# Bandit only matters on the version deployed. Platform checks are ignored
runs-on: windows-latest
steps:
- name: Checkout ${{ github.repository }}/${{ github.ref }}
uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: "pip"
cache-dependency-path: "scripts/requirements*.txt"
- run: scripts/install.ps1
shell: pwsh
- name: Analysing the code with Bandit
run: bandit src/ -n 1 --severity-level medium --recursive
Build:
runs-on: windows-latest
strategy:
Expand All @@ -137,6 +153,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: "scripts/requirements.txt"
- run: scripts/install.ps1
shell: pwsh
- run: scripts/build.ps1
Expand Down
5 changes: 2 additions & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@
// Must disable in this workspace //
// https://github.com/microsoft/vscode/issues/40239 //
//
// We use autopep8
"ms-python.black-formatter",
// VSCode has implemented an optimized version
"coenraads.bracket-pair-colorizer",
"coenraads.bracket-pair-colorizer-2",
// Obsoleted by Pylance
"ms-pyright.pyright",
"ms-python.black-formatter",
// Not configurable per workspace, tends to conflict with other linters
"sonarsource.sonarlint-vscode",
//
// Don't recommend to autoinstall //
//
// We use autopep8
"ms-python.black-formatter",
// This is a Git project
"johnstoncode.svn-scm",
// Prefer using VSCode itself as a text editor
Expand Down
32 changes: 20 additions & 12 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@
72
]
},
"trailing-spaces.includeEmptyLines": true,
"trailing-spaces.trimOnSave": true,
"trailing-spaces.syntaxIgnore": [
"markdown"
],
"[markdown]": {
"files.trimTrailingWhitespace": false,
},
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"editor.comments.insertSpace": true,
"editor.insertSpaces": true,
"editor.detectIndentation": false,
"editor.tabSize": 2,
"editor.formatOnSave": true,
Expand All @@ -17,12 +30,6 @@
"source.fixAll.convertImportFormat": true,
"source.organizeImports": true,
},
"files.insertFinalNewline": true,
"trailing-spaces.includeEmptyLines": true,
"trailing-spaces.trimOnSave": true,
"trailing-spaces.syntaxIgnore": [
"markdown"
],
"emeraldwalk.runonsave": {
"commands": [
{
Expand All @@ -36,9 +43,7 @@
]
},
"files.associations": {
"*.json": "json",
"extensions.json": "jsonc",
"settings.json": "jsonc",
".flake8": "properties",
"*.qrc": "xml",
"*.ui": "xml"
},
Expand All @@ -50,11 +55,10 @@
"**/.DS_Store": true,
"**/Thumbs.db": true,
"build": true,
".mypy_cache": true,
"**/.mypy_cache": true,
"**/__pycache__": true,
},
"search.exclude": {
"**/bower_components": true,
"**/*.code-search": true,
"*.lock": true,
},
Expand All @@ -70,8 +74,12 @@
120, // Our hard rule
],
},
"python.formatting.provider": "autopep8",
// Important to follow the config in pyrightconfig.json
"python.analysis.useLibraryCodeForTypes": false,
"python.analysis.diagnosticMode": "workspace",
"python.formatting.provider": "autopep8",
"isort.check": true,
"isort.importStrategy": "fromEnvironment",
"python.linting.enabled": true,
// Use the new Pylint extension instead
"python.linting.pylintEnabled": false,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Refer to the [build instructions](build%20instructions.md) if you'd like to buil

#### Capture Device

Select the Video Capture Device that you wanna use if selecting the `Video Capture Device` Capture Method. Will show `[occupied]` if a device is detected but can't be started.
Select the Video Capture Device that you wanna use if selecting the `Video Capture Device` Capture Method. <!-- Will show `[occupied]` if a device is detected but can't be started. (currently disabled because poking at devices to turn turn them off freezes some like the GV-USB2)-->

#### Show Live Similarity

Expand Down
21 changes: 21 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; We don't run mypy in the CI. This is just to help anyone who would like to use it manually.
; Namely, the mypy_primer tool.
[mypy]
strict=true
; Implicit return types !
disallow_untyped_calls=false
disallow_untyped_defs=false
disallow_incomplete_defs=false

; Of course my stubs are going to be incomplete. Otherwise they'd be on typeshed!
; Mypy becomes really whack with its errors inside these stubs though
mypy_path=typings,src
; exclude doesn't work with strict=true Why?
exclude=.*(typings|gen)/.*

[mypy-gen.*,cv2.*,]
; strict=false ; Doesn't work in overrides
follow_imports=skip
implicit_reexport=true
strict_optional=false
disable_error_code=attr-defined, misc, name-defined
6 changes: 1 addition & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,11 @@ max-branches = 15
# https://github.com/PyCQA/pep8-naming/issues/164
# OR doesn't fit CaptureMethodMeta
valid-classmethod-first-arg = "self"
# https://pylint.pycqa.org/en/latest/user_guide/options.html#naming-styles
module-naming-style = "any"
disable = [
# No need to mention the fixmes
"fixme",
"missing-docstring",
# Already taken care of by Flake8 and isort
# Already taken care of by isort
"ungrouped-imports",
"unused-import",
"wrong-import-order",
Expand All @@ -122,8 +120,6 @@ disable = [
"unused-argument",
# Only reports a single instance. Pyright does a better job anyway
"cyclic-import",
# Doesn't work with local imports
"import-error",
# Similar lines in 2 files, doesn't really work
"R0801",
]
Expand Down
4 changes: 2 additions & 2 deletions scripts/compile_resources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ pyside6-rcc './res/resources.qrc' -o './src/gen/resources_rc.py'
Write-Host 'Generated code from .ui files'

$build_vars_path = "$PSScriptRoot/../src/gen/build_vars.py"
$BUILD_NUMBER = Get-Date -Format yyMMddHHmm
$BUILD_NUMBER = If ($Env:GITHUB_EXCLUDE_BUILD_NUMBER -eq $true) { '' } Else { Get-Date -Format yyMMddHHmm }
$GITHUB_REPOSITORY = $Env:GITHUB_HEAD_REPOSITORY
If (-not $GITHUB_REPOSITORY) {
$repo_url = git config --get remote.origin.url
$GITHUB_REPOSITORY = $repo_url.substring(19, $repo_url.length - 19 - 4)
$GITHUB_REPOSITORY = $repo_url.substring(19, $repo_url.length - 19) -replace '\.git', ''
}
If (-not $GITHUB_REPOSITORY) {
$GITHUB_REPOSITORY = 'Toufool/Auto-Split'
Expand Down
5 changes: 3 additions & 2 deletions scripts/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ If ($IsWindows) {
}

# Installing Python dependencies
$dev = If ($env:GITHUB_JOB -eq 'Build') { '' } Else { '-dev' }
$dev = If ($Env:GITHUB_JOB -eq 'Build') { '' } Else { '-dev' }
# Ensures installation tools are up to date. This also aliases pip to pip3 on MacOS.
python3 -m pip install wheel pip setuptools --upgrade
pip install -r "$PSScriptRoot/requirements$dev.txt" --upgrade
if (Get-Command 'npm' -ErrorAction SilentlyContinue) {
# Don't install pyright on CI. We use an action
if (-not $Env:CI -and (Get-Command 'npm' -ErrorAction SilentlyContinue)) {
npm i --global pyright@latest
}

Expand Down
2 changes: 0 additions & 2 deletions scripts/lint.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ else {

Write-Host "`nRunning Bandit..."
bandit src/ -f custom --silent --recursive
# $exitCodes += $LastExitCode # Returns 1 on low
if ($LastExitCode -gt 0) {
Write-Host "`Bandit warning ($LastExitCode)" -ForegroundColor Yellow
}
else {
Write-Host "`Bandit passed" -ForegroundColor Green
}


if ($exitCodes -gt 0) {
Write-Host "`nLinting failed ($exitCodes)" -ForegroundColor Red
}
Expand Down
15 changes: 9 additions & 6 deletions scripts/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@
#
# Linters
bandit
flake8>=5 # flake8-pyi deprecation warnings
flake8>=6 # Validates configuration
flake8-builtins
flake8-bugbear
flake8-class-attributes-order
flake8-comprehensions>=3.8 # flake8 5 support
flake8-comprehensions>=3.8 # flake8 v5 support
flake8-datetimez
flake8-isort>=4.2,<=5.0 # flake8 5 support ; Breaking issue (https://github.com/gforcada/flake8-isort/issues/128)
flake8-pyi>=22.10.0 # Fixes for negative numbers
flake8-quotes
flake8-pyi>=22.11.0 # flake8 v6 support
flake8-simplify
pep8-naming
pylint>=2.14,<3.0.0 # New checks # 3.0 still in pre-release
pylint>=2.14,<3.0.0 # New checks # 2.16 and 3.0 still in pre-release
# Formatters
add-trailing-comma>=2.3.0 # Added support for with statement
autopep8>=2.0.0 # New checks
Expand All @@ -32,6 +30,11 @@ qt6-applications
# Types
types-d3dshot
types-keyboard
types-Pillow
types-psutil
types-PyAutoGUI
types-pyinstaller
types-pywin32
types-requests
types-toml
typing-extensions
9 changes: 5 additions & 4 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
# Dependencies:
certifi
ImageHash>=4.3.1 # Contains type information + setup as package not module
git+https://github.com/Avasam/keyboard.git@fix-563#egg=keyboard # Fix install on linux-ci https://github.com/boppreh/keyboard/pull/568
git+https://github.com/boppreh/keyboard.git#egg=keyboard # Fix install on macos and linux-ci https://github.com/boppreh/keyboard/pull/568
numpy>=1.23.2 # Python 3.11 wheels
opencv-python-headless>=4.6 # Breaking changes importing cv2.cv2
packaging
Pillow>=9.2 # gnome-screeshot checks
psutil
PyAutoGUI
--extra-index-url https://www.riverbankcomputing.com/pypi/simple/ --pre
PyQt6>6.4.0 # Python 3.11 support
# 6.4.1 fixes the rare Illegal Operation issue from RTADan, but the dev wheels are currently broken :/
# 2.0.0-beta.2 contains the fixes if anyone needs it.
PyQt6>=6.4.0 # Python 3.11 support
requests
toml
#
# Build and compile resources
PyInstaller>=5.5 # Python 3.11 support
pyinstaller>=5.5 # Python 3.11 support
pyinstaller-hooks-contrib>=2022.9 # opencv-python 4.6 support. Changes for pywintypes and comtypes
PySide6>=6.4.0.1 # Python 3.11 support
#
Expand Down
Loading

0 comments on commit e154acc

Please sign in to comment.