Skip to content

Commit

Permalink
Switch to pyside6
Browse files Browse the repository at this point in the history
  • Loading branch information
Nodd committed Sep 10, 2023
1 parent c88c054 commit ef17e44
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 51 deletions.
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "README.rst"
license = { text = "MIT" }
dynamic = ["version"]
requires-python = ">=3.8"
dependencies = ["line-profiler", "qtpy"]
dependencies = ["line-profiler", "pyside6"]
authors = [
{ name = "Joseph Martinot-Lagarde", email = "[email protected]" },
]
Expand Down Expand Up @@ -39,8 +39,6 @@ Tracker = "https://github.com/Nodd/lineprofilergui/issues"
Source = "https://github.com/Nodd/lineprofilergui"

[project.optional-dependencies]
pyqt5 = ["pyqt5"]
pyside2 = ["pyside2"]
test = ["pytest", "pytest-qt", "pytest-cov"]
dev = ["ruff>=0.0.273", "black>=23"]

Expand All @@ -61,7 +59,7 @@ pythonpath = "src" # Pytest >= 7.0, otherwise use PYTHONPATH=src
testpaths = ["tests"]
addopts = "--cov lineprofilergui"
# TODO: test with pyside too (use PYTEST_QT_API=pyside2 environment variable ?)
qt_api = "pyqt5"
qt_api = "pyside6"

[tool.ruff]
src = ["src", "tests"]
Expand Down
2 changes: 1 addition & 1 deletion run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from lineprofilergui.main import main
from src.lineprofilergui.main import main

if __name__ == "__main__":
main()
15 changes: 7 additions & 8 deletions src/lineprofilergui/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
from functools import cached_property
from pathlib import Path

import qtpy.compat as qtcompat
from qtpy import QtCore, QtGui, QtWidgets
from qtpy.QtCore import Qt
from PySide6 import QtCore, QtGui, QtWidgets
from PySide6.QtCore import Qt

from .utils import ICONS, MONOSPACE_FONT, PIXMAPS
from .utils import translate as _
Expand Down Expand Up @@ -391,7 +390,7 @@ def update_profileButton_enabled(self):

@QtCore.Slot()
def on_wdirButton_clicked(self):
if filename := qtcompat.getexistingdirectory(
if filename := QtWidgets.QFileDialog.getExistingDirectory(
self, _("Select Python script"), self.wdirWidget.text()
):
self.wdirWidget.setText(filename)
Expand Down Expand Up @@ -432,7 +431,7 @@ def on_envWidget_textChanged(self, text):

@QtCore.Slot()
def on_scriptButton_clicked(self):
filename, _selfilter = qtcompat.getopenfilename(
filename, _selfilter = QtWidgets.QFileDialog.getOpenFileName(
self,
_("Select Python script"),
self.scriptWidget.text(),
Expand All @@ -443,7 +442,7 @@ def on_scriptButton_clicked(self):

@QtCore.Slot()
def on_warmupButton_clicked(self):
filename, _selfilter = qtcompat.getopenfilename(
filename, _selfilter = QtWidgets.QFileDialog.getOpenFileName(
self,
_("Select Python warmup script"),
self.warmupWidget.text(),
Expand All @@ -454,7 +453,7 @@ def on_warmupButton_clicked(self):

@QtCore.Slot()
def on_statsButton_clicked(self):
filename, _selfilter = qtcompat.getsavefilename(
filename, _selfilter = QtWidgets.QFileDialog.getSaveFileName(
self,
_("Select stats filename"),
self.statsWidget.text(),
Expand All @@ -465,7 +464,7 @@ def on_statsButton_clicked(self):

@QtCore.Slot()
def on_kernprofButton_clicked(self):
filename, _selfilter = qtcompat.getopenfilename(
filename, _selfilter = QtWidgets.QFileDialog.getOpenFileName(
self,
_("Select kernprof executable"),
self.kernprofWidget.text() or self.config.default_kernprof,
Expand Down
44 changes: 22 additions & 22 deletions src/lineprofilergui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import urllib
from pathlib import Path

import qtpy
import qtpy.compat as qtcompat
from qtpy import QtCore, QtGui, QtWidgets
from qtpy.QtCore import Qt
import PySide6
from PySide6 import QtCore, QtGui, QtWidgets
from PySide6.QtCore import Qt

from . import __version__
from .config import Config, UiConfigDialog
Expand All @@ -33,7 +32,7 @@ def __init__(self):
super().__init__()
self.setup_ui()
self.kernprof_run = KernprofRun(self.config)
self.connect()
self.connect_signals()

self.profile_start_time = None

Expand All @@ -54,31 +53,31 @@ def setup_ui(self): # noqa: PLR0915
self.addDockWidget(Qt.BottomDockWidgetArea, self.dockOutputWidget)

# Actions
self.actionCollapse_all = QtWidgets.QAction(self)
self.actionCollapse_all = QtGui.QAction(self)
self.actionCollapse_all.setIcon(ICONS["COLLAPSE"])
self.actionExpand_all = QtWidgets.QAction(self)
self.actionExpand_all = QtGui.QAction(self)
self.actionExpand_all.setIcon(ICONS["EXPAND"])
self.actionRun = QtWidgets.QAction(self)
self.actionRun = QtGui.QAction(self)
self.actionRun.setIcon(ICONS["START"])
self.actionAbort = QtWidgets.QAction(self)
self.actionAbort = QtGui.QAction(self)
self.actionAbort.setIcon(ICONS["STOP"])
self.actionShowOutput = self.dockOutputWidget.toggleViewAction()
self.actionShowOutput.setIcon(ICONS["INFO"])
self.actionLoadLprof = QtWidgets.QAction(self)
self.actionLoadLprof = QtGui.QAction(self)
self.actionLoadLprof.setIcon(ICONS["READFILE"])
self.actionQuit = QtWidgets.QAction(self)
self.actionQuit = QtGui.QAction(self)
self.actionQuit.setIcon(ICONS["ABORT"])
self.actionConfigure = QtWidgets.QAction(self)
self.actionConfigure = QtGui.QAction(self)
self.actionConfigure.setIcon(ICONS["CONFIG"])
self.actionSettings = QtWidgets.QAction(self)
self.actionSettings = QtGui.QAction(self)
self.actionSettings.setIcon(ICONS["SETTINGS"])
self.actionLine_profiler_documentation = QtWidgets.QAction(self)
self.actionLine_profiler_documentation = QtGui.QAction(self)
self.actionLine_profiler_documentation.setIcon(ICONS["HELP"])
self.actionGithubLink = QtWidgets.QAction(self)
self.actionGithubLink = QtGui.QAction(self)
self.actionGithubLink.setIcon(ICONS["INFO"])
self.actionReportBug = QtWidgets.QAction(self)
self.actionReportBug = QtGui.QAction(self)
self.actionReportBug.setIcon(ICONS["ERROR"])
self.actionAbout_Qt = QtWidgets.QAction(self)
self.actionAbout_Qt = QtGui.QAction(self)
self.actionAbout_Qt.setIcon(ICONS["QT"])

# Menu bar
Expand Down Expand Up @@ -153,10 +152,10 @@ def setup_ui(self): # noqa: PLR0915
# Finalization
self.retranslate_ui()
self.read_settings()
self.set_running_state(False)
self.set_running_state(QtCore.QProcess.NotRunning)
update_theme()

def connect(self):
def connect_signals(self):
self.actionCollapse_all.triggered.connect(self.resultsTreeWidget.collapseAll)
self.actionExpand_all.triggered.connect(self.resultsTreeWidget.expandAll)
self.actionConfigure.triggered.connect(self.configure)
Expand Down Expand Up @@ -241,7 +240,7 @@ def read_settings(self):

@QtCore.Slot()
def selectLprof(self):
filename, _selfilter = qtcompat.getopenfilename(
filename, _selfilter = QtWidgets.QFileDialog.getOpenFileName(
self,
_("Select line profiler data"),
"",
Expand Down Expand Up @@ -274,6 +273,7 @@ def profile(self):

@QtCore.Slot(QtCore.QProcess.ProcessState)
def set_running_state(self, running):
running = running != QtCore.QProcess.NotRunning
self.actionRun.setEnabled(not running)
self.actionAbort.setEnabled(running)
self.actionConfigure.setEnabled(not running)
Expand Down Expand Up @@ -370,8 +370,8 @@ def report_bug(self):
* **python**: *{sys.version}*
* **OS**: *{sys.platform}*
* **line_profiler**: *{line_profiler_version}*
* **QtPy API**: *{qtpy.API} {qtpy.PYQT_VERSION if qtpy.API.startswith("pyqt") else qtpy.PYSIDE_VERSION}*
* **Qt**: *{qtpy.QT_VERSION}*
* **QtPy API**: *{PySide6.API} {PySide6.PYQT_VERSION if PySide6.API.startswith("pyqt") else PySide6.PYSIDE_VERSION}*
* **Qt**: *{PySide6.QT_VERSION}*
"""
).strip()
url = f"{LINE_PROFILER_GUI_GITHUB_URL}/issues/new?body={urllib.parse.quote_plus(body)}"
Expand Down
2 changes: 1 addition & 1 deletion src/lineprofilergui/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
import sys

from qtpy import QtCore, QtWidgets
from PySide6 import QtCore, QtWidgets

from . import __version__
from .gui import UIMainWindow
Expand Down
11 changes: 5 additions & 6 deletions src/lineprofilergui/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
import os
import shlex

from qtpy import QtCore
from PySide6 import QtCore

from .utils import translate as _

LOCALE_CODEC = QtCore.QTextCodec.codecForLocale()


class KernprofRun(QtCore.QObject):
output_text = QtCore.Signal(str)
Expand All @@ -27,7 +25,8 @@ def prepare(self):

# Manage environment
qenv = QtCore.QProcessEnvironment.systemEnvironment()
qenv.insert(self.config.env)
for name, value in self.config.env.items():
qenv.insert(name, value)
self.process.setProcessEnvironment(qenv)

self.process.setWorkingDirectory(self.config.wdir)
Expand Down Expand Up @@ -64,12 +63,12 @@ def start(self):
@QtCore.Slot()
def read_output(self):
qbytearray = self.process.readAllStandardOutput()
self.output_text.emit(LOCALE_CODEC.toUnicode(qbytearray))
self.output_text.emit(str(qbytearray, "utf-8"))

@QtCore.Slot()
def read_error(self):
qbytearray = self.process.readAllStandardError()
self.output_error.emit(LOCALE_CODEC.toUnicode(qbytearray))
self.output_error.emit(str(qbytearray, "utf-8"))

@QtCore.Slot()
def kill(self):
Expand Down
2 changes: 1 addition & 1 deletion src/lineprofilergui/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from qtpy import QtCore, QtWidgets
from PySide6 import QtCore, QtWidgets

from .utils import translate as _

Expand Down
4 changes: 2 additions & 2 deletions src/lineprofilergui/theme.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from qtpy import QtCore, QtGui, QtWidgets
from qtpy.QtCore import Qt
from PySide6 import QtCore, QtGui, QtWidgets
from PySide6.QtCore import Qt


def apply_dark_theme():
Expand Down
6 changes: 3 additions & 3 deletions src/lineprofilergui/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import subprocess
import zlib

from qtpy import QtCore, QtGui, QtWidgets
from qtpy.QtCore import Qt
from PySide6 import QtCore, QtGui, QtWidgets
from PySide6.QtCore import Qt

from .utils import MONOSPACE_FONT
from .utils import translate as _
Expand Down Expand Up @@ -88,7 +88,7 @@ def parse_stats(self, stats):
def color(self):
"""Choose deteministic unique color for the function."""
key = (self.filename + self.name).encode("utf8")
hue = float(zlib.crc32(key) & 0xFFFFFFFF) / 2**32 * 360
hue = float(zlib.crc32(key) & 0xFFFFFFFF) / 2**32
color = QtGui.QColor.fromHsvF(hue, 1.0, 1.0)

# Normalize luminance to get visually uniform colors
Expand Down
2 changes: 1 addition & 1 deletion src/lineprofilergui/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from functools import partial

from qtpy import QtCore, QtGui, QtWidgets
from PySide6 import QtCore, QtGui, QtWidgets

translate = partial(QtCore.QCoreApplication.translate, "self")

Expand Down
2 changes: 1 addition & 1 deletion tests/test_mainwindow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import textwrap
from pathlib import Path

from qtpy.QtCore import Qt
from PySide6.QtCore import Qt

from lineprofilergui import main

Expand Down
2 changes: 1 addition & 1 deletion tests/test_tree.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import subprocess

from qtpy import QtCore
from PySide6 import QtCore

from .utils import run_code

Expand Down

0 comments on commit ef17e44

Please sign in to comment.