Skip to content

Commit

Permalink
Minor refactor support for PyQt5/6 & PySide2/6
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis-van-Gils committed Oct 26, 2022
1 parent 801c942 commit 6b8a9b9
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 37 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

1.1.2 (2022-10-26)
------------------
* Minor refactor of mechanism to support PyQt5, PyQt6, PySide2 and PySide6

1.1.1 (2022-09-14)
------------------
* Forgot to bump requirement ``dvg-debug-functions~=2.2`` to ensure support for
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = "Dennis van Gils"

# The full version, including alpha/beta/rc tags
release = "1.1.1"
release = "1.1.2"

# -- General configuration ---------------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions run_test.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@echo off
rem REMEMBER TO HAVE THIS PACKAGE INSTALLED LOCALLY USING: pip install -e .
rem IF YOU WANT TO RUN PYTEST LOCALLY
rem pytest --cov-report term-missing --cov=src --cov-append -vv
pytest --cov-report term-missing --cov=src -vv
rem coverage combine
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def read(*names, **kwargs):

setup(
name="dvg-qdeviceio",
version="1.1.1",
version="1.1.2",
license="MIT",
description="Hassle-free PyQt/PySide interface for multithreaded data acquisition and communication with an I/O device.",
long_description="%s\n%s"
Expand Down
37 changes: 18 additions & 19 deletions src/dvg_qdeviceio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
__author__ = "Dennis van Gils"
__authoremail__ = "vangils.dennis@gmail.com"
__url__ = "https://github.com/Dennis-van-Gils/python-dvg-qdeviceio"
__date__ = "14-09-2022"
__version__ = "1.1.1"
__date__ = "26-10-2022"
__version__ = "1.1.2"
# pylint: disable=protected-access

from enum import IntEnum, unique
import os
import sys
import queue
import time
from enum import IntEnum, unique

# Code coverage tools 'coverage' and 'pytest-cov' don't seem to correctly trace
# code which is inside methods called from within QThreads, see
Expand All @@ -27,28 +29,23 @@

# Mechanism to support both PyQt and PySide
# -----------------------------------------
import os
import sys

QT_LIB = os.getenv("PYQTGRAPH_QT_LIB")
PYSIDE = "PySide"
PYSIDE2 = "PySide2"
PYSIDE6 = "PySide6"
PYQT4 = "PyQt4"
PYQT5 = "PyQt5"
PYQT6 = "PyQt6"
PYSIDE2 = "PySide2"
PYSIDE6 = "PySide6"
QT_LIB_ORDER = [PYQT5, PYSIDE2, PYSIDE6, PYQT6]
QT_LIB = os.getenv("PYQTGRAPH_QT_LIB")

# pylint: disable=import-error, no-name-in-module
# fmt: off
# pylint: disable=import-error, no-name-in-module, c-extension-no-member
if QT_LIB is None:
libOrder = [PYQT5, PYSIDE2, PYSIDE6, PYQT6]
for lib in libOrder:
for lib in QT_LIB_ORDER:
if lib in sys.modules:
QT_LIB = lib
break

if QT_LIB is None:
for lib in libOrder:
for lib in QT_LIB_ORDER:
try:
__import__(lib)
QT_LIB = lib
Expand All @@ -57,11 +54,13 @@
pass

if QT_LIB is None:
this_file = __file__.split(os.sep)[-1]
raise Exception(
"DvG_QDeviceIO requires PyQt5, PyQt6, PySide2 or PySide6; none of "
"these packages could be imported."
f"{this_file} requires PyQt5, PyQt6, PySide2 or PySide6; "
"none of these packages could be imported."
)

# fmt: off
if QT_LIB == PYQT5:
from PyQt5 import QtCore # type: ignore
from PyQt5.QtCore import pyqtSlot as Slot # type: ignore
Expand All @@ -78,9 +77,9 @@
from PySide6 import QtCore # type: ignore
from PySide6.QtCore import Slot # type: ignore
from PySide6.QtCore import Signal # type: ignore

# fmt: on
# pylint: enable=import-error, no-name-in-module

# pylint: enable=import-error, no-name-in-module, c-extension-no-member
# \end[Mechanism to support both PyQt and PySide]
# -----------------------------------------------

Expand Down
32 changes: 16 additions & 16 deletions tests/test_dvg_qdeviceio.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
import sys
import time

# Mechanism to support both PyQt and PySide
# -----------------------------------------
import os
import sys

QT_LIB = os.getenv("PYQTGRAPH_QT_LIB")
PYSIDE = "PySide"
PYSIDE2 = "PySide2"
PYSIDE6 = "PySide6"
PYQT4 = "PyQt4"
PYQT5 = "PyQt5"
PYQT6 = "PyQt6"
PYSIDE2 = "PySide2"
PYSIDE6 = "PySide6"
QT_LIB_ORDER = [PYQT5, PYSIDE2, PYSIDE6, PYQT6]
QT_LIB = os.getenv("PYQTGRAPH_QT_LIB")

# pylint: disable=import-error, no-name-in-module
# fmt: off
# pylint: disable=import-error, no-name-in-module, c-extension-no-member
if QT_LIB is None:
libOrder = [PYQT5, PYSIDE2, PYSIDE6, PYQT6]
for lib in libOrder:
for lib in QT_LIB_ORDER:
if lib in sys.modules:
QT_LIB = lib
break

if QT_LIB is None:
for lib in libOrder:
for lib in QT_LIB_ORDER:
try:
__import__(lib)
QT_LIB = lib
Expand All @@ -34,11 +32,13 @@
pass

if QT_LIB is None:
this_file = __file__.split(os.sep)[-1]
raise Exception(
"DvG_QDeviceIO requires PyQt5, PyQt6, PySide2 or PySide6; none of "
"these packages could be imported."
f"{this_file} requires PyQt5, PyQt6, PySide2 or PySide6; "
"none of these packages could be imported."
)

# fmt: off
if QT_LIB == PYQT5:
from PyQt5 import QtCore # type: ignore
from PyQt5.QtCore import pyqtSlot as Slot # type: ignore
Expand All @@ -55,9 +55,9 @@
from PySide6 import QtCore # type: ignore
from PySide6.QtCore import Slot # type: ignore
from PySide6.QtCore import Signal # type: ignore

# fmt: on
# pylint: enable=import-error, no-name-in-module

# pylint: enable=import-error, no-name-in-module, c-extension-no-member
# \end[Mechanism to support both PyQt and PySide]
# -----------------------------------------------

Expand Down

0 comments on commit 6b8a9b9

Please sign in to comment.