From 410d1f8966a2c30a1de314dfedf6b50a9e3212dd Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sun, 18 Sep 2016 12:57:24 +0200 Subject: [PATCH 01/12] Add pyside2-uic (executable) and pyside2uic (module) --- Dockerfile-py2.7 | 7 +++++++ Dockerfile-py3.5 | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/Dockerfile-py2.7 b/Dockerfile-py2.7 index e3bc2c20..b937c3f9 100644 --- a/Dockerfile-py2.7 +++ b/Dockerfile-py2.7 @@ -1,5 +1,8 @@ FROM ubuntu:16.04 +# Needed to install pyside2-tools without issues +ENV DEBIAN_FRONTEND noninteractive + RUN apt-get update && \ apt-get install -y \ software-properties-common && \ @@ -12,8 +15,12 @@ RUN apt-get update && \ python-pyqt5 \ python-pyside \ python-pyside2 \ + pyside2-tools \ xvfb +# Make pyside2uic availble for Python 2.x +RUN cp -avr /usr/lib/python3/dist-packages/pyside2uic /usr/local/lib/python2.7/dist-packages + # Nose is the Python test-runner RUN pip install nose nosepipe diff --git a/Dockerfile-py3.5 b/Dockerfile-py3.5 index f4646d55..37f38b0e 100644 --- a/Dockerfile-py3.5 +++ b/Dockerfile-py3.5 @@ -1,5 +1,8 @@ FROM ubuntu:16.04 +# Needed to install pyside2-tools without issues +ENV DEBIAN_FRONTEND noninteractive + RUN apt-get update && \ apt-get install -y \ software-properties-common && \ @@ -12,6 +15,7 @@ RUN apt-get update && \ python3-pyqt5 \ python3-pyside \ python3-pyside2 \ + pyside2-tools \ xvfb # Nose is the Python test-runner From 366bfdab05e14687c44128cc72a9fd61aaa47ff8 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sun, 18 Sep 2016 14:49:19 +0200 Subject: [PATCH 02/12] Fix whitespace --- tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests.py b/tests.py index a7872996..4ae6838a 100644 --- a/tests.py +++ b/tests.py @@ -263,6 +263,7 @@ def test_meta_add(): assert "MyAttr" not in Qt.__remapped__ assert "MyAttr" not in Qt.__modified__ + def test_meta_remap(): """Qt.remap() appends to __modified__""" import types @@ -277,7 +278,6 @@ def test_meta_remap(): assert "MyAttr" not in Qt.__modified__ - def test_meta_add_existing(): """Qt.add() appends to __added__""" import types From 76ecd497462b03c6bc64fe4805648cfb6fef2983 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sun, 18 Sep 2016 15:24:45 +0200 Subject: [PATCH 03/12] Initial test --- tests.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests.py b/tests.py index 4ae6838a..2c8368a7 100644 --- a/tests.py +++ b/tests.py @@ -311,6 +311,21 @@ def test_import_from_qtwidgets(): assert QPushButton.__name__ == "QPushButton", QPushButton +def test_pyside2uic_py2(): + """pyside2-uic, Python 2""" + + import pyside2uic + from cStringIO import StringIO + + with open(self.ui_qwidget, 'r') as ui_file: + py_filename = 'output.py' + with open(py_filename, 'w') as py_file: + pyside2uic.compileUi(ui_file, py_file, indent=0) + import output + ui_form = output.Ui_Form() # Create object + os.remove(py_filename) + + if binding("PyQt4"): def test_preferred_pyqt4(): """QT_PREFERRED_BINDING = PyQt4 properly forces the binding""" From 031e08faf3608e315d2d99ee992121be27083007 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sun, 18 Sep 2016 15:32:20 +0200 Subject: [PATCH 04/12] Remove junk --- tests.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests.py b/tests.py index 2c8368a7..daaf9ade 100644 --- a/tests.py +++ b/tests.py @@ -311,11 +311,10 @@ def test_import_from_qtwidgets(): assert QPushButton.__name__ == "QPushButton", QPushButton -def test_pyside2uic_py2(): - """pyside2-uic, Python 2""" +def test_pyside2uic(): + """pyside2-uic""" import pyside2uic - from cStringIO import StringIO with open(self.ui_qwidget, 'r') as ui_file: py_filename = 'output.py' From 9c2580bc7341235d2831a506a97387bbe86bfceb Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sun, 18 Sep 2016 15:36:59 +0200 Subject: [PATCH 05/12] Read compiled ui into string, write compiled ui into file --- tests.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests.py b/tests.py index daaf9ade..33391f78 100644 --- a/tests.py +++ b/tests.py @@ -315,8 +315,16 @@ def test_pyside2uic(): """pyside2-uic""" import pyside2uic + from cStringIO import StringIO with open(self.ui_qwidget, 'r') as ui_file: + # Read compiled UI into string + pyfile_output = StringIO() + pyside2uic.compileUi(ui_file, pyfile_output, indent=0) + print(pyfile_output.getvalue()) + exec pyfile_output.getvalue() + + # Write compiled ui into Python file py_filename = 'output.py' with open(py_filename, 'w') as py_file: pyside2uic.compileUi(ui_file, py_file, indent=0) From fd9eb0b021f663d831105640b324de09bdd888b1 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sun, 18 Sep 2016 15:42:30 +0200 Subject: [PATCH 06/12] Commented out problematic parts (which works locally) --- tests.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests.py b/tests.py index 33391f78..071c7f5f 100644 --- a/tests.py +++ b/tests.py @@ -321,15 +321,15 @@ def test_pyside2uic(): # Read compiled UI into string pyfile_output = StringIO() pyside2uic.compileUi(ui_file, pyfile_output, indent=0) - print(pyfile_output.getvalue()) - exec pyfile_output.getvalue() + # print(pyfile_output.getvalue()) + # exec pyfile_output.getvalue() # Execute Python code # Write compiled ui into Python file py_filename = 'output.py' with open(py_filename, 'w') as py_file: pyside2uic.compileUi(ui_file, py_file, indent=0) import output - ui_form = output.Ui_Form() # Create object + # ui_form = output.Ui_Form() # Create object os.remove(py_filename) From 5baf0e23b261fb66515de1f191c878de93fd8a2f Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sun, 18 Sep 2016 15:48:09 +0200 Subject: [PATCH 07/12] Remove compiling ui into string --- tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests.py b/tests.py index 071c7f5f..cf852a84 100644 --- a/tests.py +++ b/tests.py @@ -319,8 +319,8 @@ def test_pyside2uic(): with open(self.ui_qwidget, 'r') as ui_file: # Read compiled UI into string - pyfile_output = StringIO() - pyside2uic.compileUi(ui_file, pyfile_output, indent=0) + # pyfile_output = StringIO() + # pyside2uic.compileUi(ui_file, pyfile_output, indent=0) # print(pyfile_output.getvalue()) # exec pyfile_output.getvalue() # Execute Python code From 4f413d31b46fbf00f1b8400bb353ac21ed6d44a5 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sun, 18 Sep 2016 15:52:49 +0200 Subject: [PATCH 08/12] Remove cStringIO --- tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests.py b/tests.py index cf852a84..ce444d7a 100644 --- a/tests.py +++ b/tests.py @@ -315,9 +315,9 @@ def test_pyside2uic(): """pyside2-uic""" import pyside2uic - from cStringIO import StringIO with open(self.ui_qwidget, 'r') as ui_file: + # from cStringIO import StringIO # Read compiled UI into string # pyfile_output = StringIO() # pyside2uic.compileUi(ui_file, pyfile_output, indent=0) From 8703dd8db764e1d84c83bca73f3519e3c122002e Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sun, 18 Sep 2016 16:02:51 +0200 Subject: [PATCH 09/12] Use space indentation --- tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests.py b/tests.py index ce444d7a..8edb5f08 100644 --- a/tests.py +++ b/tests.py @@ -327,7 +327,7 @@ def test_pyside2uic(): # Write compiled ui into Python file py_filename = 'output.py' with open(py_filename, 'w') as py_file: - pyside2uic.compileUi(ui_file, py_file, indent=0) + pyside2uic.compileUi(ui_file, py_file) import output # ui_form = output.Ui_Form() # Create object os.remove(py_filename) From 7ebadcc33f9c17678c2454c227ba75c00ada262b Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sun, 18 Sep 2016 16:07:52 +0200 Subject: [PATCH 10/12] Add expected output --- tests.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/tests.py b/tests.py index 8edb5f08..c4ba8211 100644 --- a/tests.py +++ b/tests.py @@ -316,6 +316,36 @@ def test_pyside2uic(): import pyside2uic + expected_output = """\ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'diggi.ui' +# +# Created: Sun Sep 18 13:57:29 2016 +# by: pyside2-uic running on PySide2 2.0.0~alpha0 +# +# WARNING! All changes made in this file will be lost! + +from PySide2 import QtCore, QtGui, QtWidgets + +class Ui_Form(object): + def setupUi(self, Form): + Form.setObjectName("Form") + Form.resize(235, 149) + self.gridLayout = QtWidgets.QGridLayout(Form) + self.gridLayout.setObjectName("gridLayout") + self.lineEdit = QtWidgets.QLineEdit(Form) + self.lineEdit.setObjectName("lineEdit") + self.gridLayout.addWidget(self.lineEdit, 0, 0, 1, 1) + + self.retranslateUi(Form) + QtCore.QMetaObject.connectSlotsByName(Form) + + def retranslateUi(self, Form): + Form.setWindowTitle(QtWidgets.QApplication.translate("Form", "Form", None, -1)) + +""" + with open(self.ui_qwidget, 'r') as ui_file: # from cStringIO import StringIO # Read compiled UI into string @@ -328,8 +358,9 @@ def test_pyside2uic(): py_filename = 'output.py' with open(py_filename, 'w') as py_file: pyside2uic.compileUi(ui_file, py_file) - import output + # import output # ui_form = output.Ui_Form() # Create object + assert expected_output == py_file.read() os.remove(py_filename) From 4ad77e6d5e284b348a5c8e6ffaef2734c0803d38 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sun, 18 Sep 2016 16:22:59 +0200 Subject: [PATCH 11/12] Fix IOError --- tests.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests.py b/tests.py index c4ba8211..876faf68 100644 --- a/tests.py +++ b/tests.py @@ -312,16 +312,15 @@ def test_import_from_qtwidgets(): def test_pyside2uic(): - """pyside2-uic""" + """Test pyside2uic (copied from Python 3.x dist-packages)""" import pyside2uic - expected_output = """\ -# -*- coding: utf-8 -*- + expected_output = """# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'diggi.ui' # -# Created: Sun Sep 18 13:57:29 2016 +# Created: Sun Sep 18 14:21:02 2016 # by: pyside2-uic running on PySide2 2.0.0~alpha0 # # WARNING! All changes made in this file will be lost! @@ -354,13 +353,14 @@ def retranslateUi(self, Form): # print(pyfile_output.getvalue()) # exec pyfile_output.getvalue() # Execute Python code - # Write compiled ui into Python file py_filename = 'output.py' - with open(py_filename, 'w') as py_file: - pyside2uic.compileUi(ui_file, py_file) - # import output - # ui_form = output.Ui_Form() # Create object + with open(ui_file, 'r') as ui_file: + with open(py_filename, 'w') as py_file: + pyside2uic.compileUi(ui_file, py_file) + + with open(py_filename, 'r') as py_file: assert expected_output == py_file.read() + os.remove(py_filename) From 6e44338778d797c6d6b48b426e5febd2392b4c17 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sun, 18 Sep 2016 16:24:40 +0200 Subject: [PATCH 12/12] Remove test --- tests.py | 55 +------------------------------------------------------ 1 file changed, 1 insertion(+), 54 deletions(-) diff --git a/tests.py b/tests.py index 876faf68..a7872996 100644 --- a/tests.py +++ b/tests.py @@ -263,7 +263,6 @@ def test_meta_add(): assert "MyAttr" not in Qt.__remapped__ assert "MyAttr" not in Qt.__modified__ - def test_meta_remap(): """Qt.remap() appends to __modified__""" import types @@ -278,6 +277,7 @@ def test_meta_remap(): assert "MyAttr" not in Qt.__modified__ + def test_meta_add_existing(): """Qt.add() appends to __added__""" import types @@ -311,59 +311,6 @@ def test_import_from_qtwidgets(): assert QPushButton.__name__ == "QPushButton", QPushButton -def test_pyside2uic(): - """Test pyside2uic (copied from Python 3.x dist-packages)""" - - import pyside2uic - - expected_output = """# -*- coding: utf-8 -*- - -# Form implementation generated from reading ui file 'diggi.ui' -# -# Created: Sun Sep 18 14:21:02 2016 -# by: pyside2-uic running on PySide2 2.0.0~alpha0 -# -# WARNING! All changes made in this file will be lost! - -from PySide2 import QtCore, QtGui, QtWidgets - -class Ui_Form(object): - def setupUi(self, Form): - Form.setObjectName("Form") - Form.resize(235, 149) - self.gridLayout = QtWidgets.QGridLayout(Form) - self.gridLayout.setObjectName("gridLayout") - self.lineEdit = QtWidgets.QLineEdit(Form) - self.lineEdit.setObjectName("lineEdit") - self.gridLayout.addWidget(self.lineEdit, 0, 0, 1, 1) - - self.retranslateUi(Form) - QtCore.QMetaObject.connectSlotsByName(Form) - - def retranslateUi(self, Form): - Form.setWindowTitle(QtWidgets.QApplication.translate("Form", "Form", None, -1)) - -""" - - with open(self.ui_qwidget, 'r') as ui_file: - # from cStringIO import StringIO - # Read compiled UI into string - # pyfile_output = StringIO() - # pyside2uic.compileUi(ui_file, pyfile_output, indent=0) - # print(pyfile_output.getvalue()) - # exec pyfile_output.getvalue() # Execute Python code - - py_filename = 'output.py' - with open(ui_file, 'r') as ui_file: - with open(py_filename, 'w') as py_file: - pyside2uic.compileUi(ui_file, py_file) - - with open(py_filename, 'r') as py_file: - assert expected_output == py_file.read() - - os.remove(py_filename) - - if binding("PyQt4"): def test_preferred_pyqt4(): """QT_PREFERRED_BINDING = PyQt4 properly forces the binding"""