Skip to content

Commit 29164ad

Browse files
authored
Drop dependency on psutil (#318)
1 parent e85ebfe commit 29164ad

File tree

5 files changed

+81
-97
lines changed

5 files changed

+81
-97
lines changed

pyproject.toml

-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ dependencies = [
1111
"numpy >=2.1", # Python 3.13 support
1212
"opencv-python-headless >=4.10", # NumPy 2 support
1313
"packaging >=20.0", # py.typed
14-
"psutil >=6.0.0", # Python 3.13 support
1514
# When needed, dev builds can be found at https://download.qt.io/snapshots/ci/pyside/dev?C=M;O=D
1615
"PySide6-Essentials <6.8.1", # Has typing issue with QMessageBox.warning https://bugreports.qt.io/browse/PYSIDE-2939
1716
# "PySide6-Essentials >=6.8.2", # Fixed typing issue with QMessageBox.warning
@@ -60,7 +59,6 @@ dev = [
6059
"types-PyAutoGUI",
6160
"types-PyScreeze; sys_platform == 'linux'",
6261
"types-keyboard",
63-
"types-psutil",
6462
"types-pyinstaller",
6563
"types-python-xlib; sys_platform == 'linux'",
6664
"types-pywin32 >=306.0.0.20240130; sys_platform == 'win32'",

src/AutoSplit.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
if sys.platform == "linux":
2424
# Fixes "undefined symbol: wl_proxy_marshal_flags": https://bugreports.qt.io/browse/QTBUG-114635
2525
os.environ.setdefault("QT_QPA_PLATFORM", "xcb")
26+
# Useful for debugging missing system packages
27+
# os.environ.setdefault("QT_DEBUG_PLUGINS", "1")
2628

2729
import signal
2830
from collections.abc import Callable
@@ -33,7 +35,6 @@
3335

3436
import cv2
3537
from cv2.typing import MatLike
36-
from psutil import process_iter
3738
from PySide6 import QtCore, QtGui
3839
from PySide6.QtTest import QTest
3940
from PySide6.QtWidgets import QApplication, QFileDialog, QLabel, QMainWindow, QMessageBox
@@ -82,6 +83,7 @@
8283
flatten,
8384
imwrite,
8485
is_valid_image,
86+
list_processes,
8587
open_file,
8688
)
8789

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

10631065

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

10771073

10781074
def main():

src/capture_method/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ def get(self, key: CaptureMethodEnum, default: object = None, /):
139139
CAPTURE_METHODS[CaptureMethodEnum.XCB] = XcbCaptureMethod
140140
try:
141141
pyscreeze.screenshot()
142-
except UnidentifiedImageError:
142+
except (UnidentifiedImageError, pyscreeze.PyScreezeException):
143+
# TODO: Should we show a specific warning for, or document:
144+
# 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
143145
pass
144146
else:
145147
# TODO: Investigate solution for Slow Scrot:

src/utils.py

+16
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,22 @@ def run_tesseract(png: bytes):
301301
)
302302

303303

304+
def list_processes():
305+
if sys.platform == "win32":
306+
return [
307+
# The first row is the process name
308+
line.split()[0]
309+
for line in subprocess.check_output( # noqa: S603 # Known input
310+
"C:/Windows/System32/tasklist.exe", text=True
311+
).splitlines()[3:] # Skip the table header lines
312+
if line
313+
]
314+
315+
return subprocess.check_output( # noqa: S603 # Known input
316+
("ps", "-eo", "comm"), text=True
317+
).splitlines()[1:] # Skip the header line
318+
319+
304320
# Environment specifics
305321
WINDOWS_BUILD_NUMBER = int(version().split(".")[-1]) if sys.platform == "win32" else -1
306322
FIRST_WIN_11_BUILD = 22000

0 commit comments

Comments
 (0)