Skip to content

Commit

Permalink
Drop dependency on psutil (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored Feb 14, 2025
1 parent e85ebfe commit 29164ad
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 97 deletions.
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies = [
"numpy >=2.1", # Python 3.13 support
"opencv-python-headless >=4.10", # NumPy 2 support
"packaging >=20.0", # py.typed
"psutil >=6.0.0", # Python 3.13 support
# When needed, dev builds can be found at https://download.qt.io/snapshots/ci/pyside/dev?C=M;O=D
"PySide6-Essentials <6.8.1", # Has typing issue with QMessageBox.warning https://bugreports.qt.io/browse/PYSIDE-2939
# "PySide6-Essentials >=6.8.2", # Fixed typing issue with QMessageBox.warning
Expand Down Expand Up @@ -60,7 +59,6 @@ dev = [
"types-PyAutoGUI",
"types-PyScreeze; sys_platform == 'linux'",
"types-keyboard",
"types-psutil",
"types-pyinstaller",
"types-python-xlib; sys_platform == 'linux'",
"types-pywin32 >=306.0.0.20240130; sys_platform == 'win32'",
Expand Down
14 changes: 5 additions & 9 deletions src/AutoSplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
if sys.platform == "linux":
# Fixes "undefined symbol: wl_proxy_marshal_flags": https://bugreports.qt.io/browse/QTBUG-114635
os.environ.setdefault("QT_QPA_PLATFORM", "xcb")
# Useful for debugging missing system packages
# os.environ.setdefault("QT_DEBUG_PLUGINS", "1")

import signal
from collections.abc import Callable
Expand All @@ -33,7 +35,6 @@

import cv2
from cv2.typing import MatLike
from psutil import process_iter
from PySide6 import QtCore, QtGui
from PySide6.QtTest import QTest
from PySide6.QtWidgets import QApplication, QFileDialog, QLabel, QMainWindow, QMessageBox
Expand Down Expand Up @@ -82,6 +83,7 @@
flatten,
imwrite,
is_valid_image,
list_processes,
open_file,
)

Expand Down Expand Up @@ -1061,18 +1063,12 @@ def seconds_remaining_text(seconds: float):
return f"{seconds:.1f} second{'' if 0 < seconds <= 1 else 's'} remaining"


# TODO: Add Linux support
def is_already_open():
# When running directly in Python, any AutoSplit process means it's already open
# When bundled, we must ignore itself and the splash screen
max_processes = 3 if FROZEN else 1
process_count = 0
for process in process_iter():
if process.name() == "AutoSplit.exe":
process_count += 1
if process_count >= max_processes:
return True
return False
process_name = "AutoSplit.exe" if sys.platform == "win32" else "AutoSplit.elf"
return list_processes().count(process_name) >= max_processes


def main():
Expand Down
4 changes: 3 additions & 1 deletion src/capture_method/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ def get(self, key: CaptureMethodEnum, default: object = None, /):
CAPTURE_METHODS[CaptureMethodEnum.XCB] = XcbCaptureMethod
try:
pyscreeze.screenshot()
except UnidentifiedImageError:
except (UnidentifiedImageError, pyscreeze.PyScreezeException):
# TODO: Should we show a specific warning for, or document:
# pyscreeze.PyScreezeException: Your computer uses the Wayland window system. Scrot works on the X11 window system but not Wayland. You must install gnome-screenshot by running `sudo apt install gnome-screenshot` # noqa: E501
pass
else:
# TODO: Investigate solution for Slow Scrot:
Expand Down
16 changes: 16 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,22 @@ def run_tesseract(png: bytes):
)


def list_processes():
if sys.platform == "win32":
return [
# The first row is the process name
line.split()[0]
for line in subprocess.check_output( # noqa: S603 # Known input
"C:/Windows/System32/tasklist.exe", text=True
).splitlines()[3:] # Skip the table header lines
if line
]

return subprocess.check_output( # noqa: S603 # Known input
("ps", "-eo", "comm"), text=True
).splitlines()[1:] # Skip the header line


# Environment specifics
WINDOWS_BUILD_NUMBER = int(version().split(".")[-1]) if sys.platform == "win32" else -1
FIRST_WIN_11_BUILD = 22000
Expand Down
Loading

0 comments on commit 29164ad

Please sign in to comment.