Skip to content

Commit

Permalink
Drop support for Python 3.9 (#261)
Browse files Browse the repository at this point in the history
* Doc & config update
* Drop `from __future__ import annotations` & type reference fixes
* Improved control flow (match-case)
* Couple other manual updates
* Fix pyright issue with versions
* Re-lint
  • Loading branch information
Avasam authored Oct 20, 2023
1 parent 04e3f7d commit c144016
Show file tree
Hide file tree
Showing 27 changed files with 2,443 additions and 2,477 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/lint-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
fail-fast: false
# Ruff is version and platform sensible
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.10", "3.11"]
steps:
- name: Checkout ${{ github.repository }}/${{ github.ref }}
uses: actions/checkout@v3
Expand All @@ -64,7 +64,7 @@ jobs:
fail-fast: false
# Pyright is version and platform sensible
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.10", "3.11"]
steps:
- name: Checkout ${{ github.repository }}/${{ github.ref }}
uses: actions/checkout@v3
Expand All @@ -80,6 +80,7 @@ jobs:
uses: jakebailey/pyright-action@v1
with:
working-directory: src/
python-version: ${{ matrix.python-version }}
Build:
runs-on: windows-latest
strategy:
Expand Down
2 changes: 1 addition & 1 deletion .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sonar.python.version=3.9, 3.10, 3.11
sonar.python.version=3.10, 3.11
2 changes: 0 additions & 2 deletions PyInstaller/hooks/hook-requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

from PyInstaller.utils.hooks import collect_data_files

# Get the cacert.pem
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This program can be used to automatically start, split, and reset your preferred
### Compatibility

- Windows 10 and 11.
- Python 3.9+ (Not required for normal use. Refer to the [build instructions](/docs/build%20instructions.md) if you'd like run the application directly in Python).
- Python 3.10+ (Not required for normal use. Refer to the [build instructions](/docs/build%20instructions.md) if you'd like run the application directly in Python).

## OPTIONS

Expand Down
2 changes: 1 addition & 1 deletion docs/build instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

### All platforms

- [Python](https://www.python.org/downloads/) 3.9+.
- [Python](https://www.python.org/downloads/) 3.10+.
- [Node](https://nodejs.org) is optional, but required for complete linting.
- Alternatively you can install the [pyright python wrapper](https://pypi.org/project/pyright/) which has a bit of an overhead delay.
- [PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell)
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://docs.astral.sh/ruff/configuration/
[tool.ruff]
target-version = "py39"
target-version = "py310"
line-length = 120
select = ["ALL"]
preview = true
Expand All @@ -21,6 +21,8 @@ ignore = [
"ERA001", # eradicate: commented-out-code
# contextlib.suppress is roughly 3x slower than try/except
"SIM105", # flake8-simplify: use-contextlib-suppress
# Negative performance impact
"UP038", # non-pep604-isinstance
# Checked by type-checker (pyright)
"ANN", # flake-annotations
"PGH003", # blanket-type-ignore
Expand Down Expand Up @@ -85,7 +87,6 @@ allow-multiline = false
[tool.ruff.isort]
combine-as-imports = true
split-on-trailing-comma = false
required-imports = ["from __future__ import annotations"]
# Unlike isort, Ruff only counts relative imports as local-folder by default for know.
# https://github.com/astral-sh/ruff/issues/3115
known-local-folder = [
Expand Down Expand Up @@ -141,6 +142,7 @@ ignore = [
# https://github.com/microsoft/pyright/blob/main/docs/configuration.md#sample-pyprojecttoml-file
[tool.pyright]
typeCheckingMode = "strict"
pythonVersion = "3.10"
# Prefer `pyright: ignore`
enableTypeIgnoreComments = false
# Extra strict
Expand Down
92 changes: 46 additions & 46 deletions src/AutoControlledThread.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from PySide6 import QtCore

import error_messages
import user_profile

if TYPE_CHECKING:
from AutoSplit import AutoSplit


class AutoControlledThread(QtCore.QThread):
def __init__(self, autosplit: AutoSplit):
self.autosplit = autosplit
super().__init__()

@QtCore.Slot()
def run(self):
while True:
try:
line = input()
except RuntimeError:
self.autosplit.show_error_signal.emit(error_messages.stdin_lost)
break
except EOFError:
continue
# This is for use in a Development environment
if line == "kill":
self.autosplit.closeEvent()
break
if line == "start":
self.autosplit.start_auto_splitter()
elif line in {"split", "skip"}:
self.autosplit.skip_split_signal.emit()
elif line == "undo":
self.autosplit.undo_split_signal.emit()
elif line == "reset":
self.autosplit.reset_signal.emit()
elif line.startswith("settings"):
# Allow for any split character between "settings" and the path
user_profile.load_settings(self.autosplit, line[9:])
# TODO: Not yet implemented in AutoSplit Integration
# elif line == 'pause':
# self.pause_signal.emit()
from typing import TYPE_CHECKING

from PySide6 import QtCore

import error_messages
import user_profile

if TYPE_CHECKING:
from AutoSplit import AutoSplit


class AutoControlledThread(QtCore.QThread):
def __init__(self, autosplit: "AutoSplit"):
self.autosplit = autosplit
super().__init__()

@QtCore.Slot()
def run(self):
while True:
try:
line = input()
except RuntimeError:
self.autosplit.show_error_signal.emit(error_messages.stdin_lost)
break
except EOFError:
continue
match line:
# This is for use in a Development environment
case "kill":
self.autosplit.closeEvent()
break
case "start":
self.autosplit.start_auto_splitter()
case "split" | "skip":
self.autosplit.skip_split_signal.emit()
case "undo":
self.autosplit.undo_split_signal.emit()
case "reset":
self.autosplit.reset_signal.emit()
# TODO: Not yet implemented in AutoSplit Integration
# case 'pause':
# self.pause_signal.emit()
case line:
if line.startswith("settings"):
# Allow for any split character between "settings" and the path
user_profile.load_settings(self.autosplit, line[9:])
60 changes: 27 additions & 33 deletions src/AutoSplit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/python3
from __future__ import annotations

import ctypes
import os
import signal
Expand Down Expand Up @@ -878,40 +876,36 @@ def exit_program() -> NoReturn:
os.kill(os.getpid(), signal.SIGINT)
sys.exit()

# Simulates LiveSplit quitting without asking. See "TODO" at update_auto_control Worker
# `event is None` simulates LiveSplit quitting without asking.
# This also more gracefully exits LiveSplit
# Users can still manually save their settings
if event is None:
if event is None or not user_profile.have_settings_changed(self):
exit_program()

if user_profile.have_settings_changed(self):
# Give a different warning if there was never a settings file that was loaded successfully,
# and "save as" instead of "save".
settings_file_name = (
"Untitled"
if not self.last_successfully_loaded_settings_file_path
else os.path.basename(self.last_successfully_loaded_settings_file_path)
)

warning = QMessageBox.warning(
self,
"AutoSplit",
f"Do you want to save changes made to settings file {settings_file_name}?",
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No | QMessageBox.StandardButton.Cancel,
)
# Give a different warning if there was never a settings file that was loaded successfully,
# and "save as" instead of "save".
settings_file_name = (
"Untitled"
if not self.last_successfully_loaded_settings_file_path
else os.path.basename(self.last_successfully_loaded_settings_file_path)
)

if warning is QMessageBox.StandardButton.Yes:
if user_profile.save_settings(self):
exit_program()
else:
event.ignore()
if warning is QMessageBox.StandardButton.No:
exit_program()
if warning is QMessageBox.StandardButton.Cancel:
event.ignore()
else:
warning = QMessageBox.warning(
self,
"AutoSplit",
f"Do you want to save changes made to settings file {settings_file_name}?",
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No | QMessageBox.StandardButton.Cancel,
)

if (
(warning is QMessageBox.StandardButton.Yes and user_profile.save_settings(self))
or warning is QMessageBox.StandardButton.No
):
exit_program()

# Fallthrough case: Prevent program from closing.
event.ignore()


def set_preview_image(qlabel: QLabel, image: MatLike | None):
if not is_valid_image(image):
Expand All @@ -930,10 +924,10 @@ def set_preview_image(qlabel: QLabel, image: MatLike | None):

qimage = QtGui.QImage(
capture.data, # pyright: ignore[reportGeneralTypeIssues] # https://bugreports.qt.io/browse/PYSIDE-2476
width,
height,
width * channels,
image_format,
width,
height,
width * channels,
image_format,
)
qlabel.setPixmap(
QtGui.QPixmap(qimage).scaled(
Expand Down
Loading

0 comments on commit c144016

Please sign in to comment.