Skip to content

PR: Monkey patch pyside2uic UIParser.readResources for Python 3.9 compatibility#325

Merged
dalthviz merged 2 commits intospyder-ide:masterfrom
n-elie:python39
Mar 1, 2022
Merged

PR: Monkey patch pyside2uic UIParser.readResources for Python 3.9 compatibility#325
dalthviz merged 2 commits intospyder-ide:masterfrom
n-elie:python39

Conversation

@n-elie
Copy link
Copy Markdown
Contributor

@n-elie n-elie commented Mar 1, 2022

Monkey patch UIParser.readResources to make it works with Python 3.9. Without this patch, we get this error:

Traceback (most recent call last):
File "simple.py", line 12, in
MainWindowUI, MainWindowBase = uic.loadUiType(UI_FILE)
File "\Miniconda3\envs\pysideads\lib\site-packages\qtpy\uic.py", line 271, in loadUiType
compileUi(fd, code_stream, indent=0, from_imports=from_imports)
File "\Miniconda3\envs\pysideads\lib\site-packages\pyside2uic_init_.py", line 144, in compileUi
winfo = ui_comp.compileUi(uifile, pyfile, from_imports)
File "\Miniconda3\envs\pysideads\lib\site-packages\pyside2uic\Compiler\compiler.py", line 91, in compileUi
w = self.parse(input_stream)
File "\Miniconda3\envs\pysideads\lib\site-packages\pyside2uic\uiparser.py", line 882, in parse
actor(elem)
File "\Miniconda3\envs\pysideads\lib\site-packages\qtpy\uic.py", line 253, in readResources
elem.getiterator = elem.iter
AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'getiterator'

Methods getchildren() and getiterator() of classes ElementTree and Element in the ElementTree module have been removed. They were deprecated in Python 3.2. Use iter(x) or list(x) instead of x.getchildren() and x.iter() or list(x.iter()) instead of x.getiterator(). (Contributed by Serhiy Storchaka in bpo-36543.)

https://docs.python.org/3.9/whatsnew/3.9.html#removed

@dalthviz dalthviz added this to the v2.1.0 milestone Mar 1, 2022
@dalthviz dalthviz changed the title Monkey patch UIParser for Python 3.9 compatibility PR: Monkey patch UIParser for Python 3.9 compatibility Mar 1, 2022
Copy link
Copy Markdown
Member

@dalthviz dalthviz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @n-elie for your help with this! I left a comment otherwise this LGTM 👍

Also, not totally sure but, maybe could be worthy to create an issue over PySide regarding this?

@n-elie
Copy link
Copy Markdown
Contributor Author

n-elie commented Mar 1, 2022

Also, not totally sure but, maybe could be worthy to create an issue over PySide regarding this?

I think you are right but I was not able to find where I should create the issue for PySide2

@dalthviz
Copy link
Copy Markdown
Member

dalthviz commented Mar 1, 2022

I think you are right but I was not able to find where I should create the issue for PySide2

For info regarding that you can check here: https://wiki.qt.io/Qt_for_Python/Reporting_Bugs

Edit:

Maybe @cmaureir could guide us into if is worthy to open an issue or not

Copy link
Copy Markdown
Member

@dalthviz dalthviz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @n-elie !

@dalthviz dalthviz merged commit cb16812 into spyder-ide:master Mar 1, 2022
@dalthviz dalthviz changed the title PR: Monkey patch UIParser for Python 3.9 compatibility PR: Monkey patch pyside2uic UIParser.readResources for Python 3.9 compatibility Mar 1, 2022
@CAM-Gerlach
Copy link
Copy Markdown
Member

If I were to guess, it seems possible they would decline to fix it in PySide2, unfortunately, due to TQC dropping LTS support for open source (without a paid commercial subscription). In fact, at least as I understand it, PySide2 won't work at all with Python 3.10 for want of a one-line patch that they only applied to Qt6 (see #269).

However, we could consider applying the patches ourselves on the Conda feedstock, assuming it is unblocked by progress on getting Qt >5.12 packaged. See discussion on #296 and e.g. conda-forge/pyside2-feedstock#91.

@cmaureir
Copy link
Copy Markdown

cmaureir commented Mar 1, 2022

If I were to guess, it seems possible they would decline to fix it in PySide2, unfortunately, due to TQC dropping LTS support for open source (without a paid commercial subscription).

That's right, as Qt/C++, we followed the new changes that 5.15.2 was the last OSS release.

In fact, at least as I understand it, PySide2 won't work at all with Python 3.10 for want of a one-line patch that they only applied to Qt6 (see #269).

We decided that supporting 3.10 was necessary, and we did a special release 5.15.2.1 that only included 3.10 support. You can check the wheel tags here https://pypi.org/project/PySide2/#files

However, we could consider applying the patches ourselves on the Conda feedstock, assuming it is unblocked by progress on getting Qt >5.12 packaged. See discussion on #296 and e.g. conda-forge/pyside2-feedstock#91.

As many linux distributions, it's common to include patches on top of the latest source: https://download.qt.io/official_releases/QtForPython/pyside2/PySide2-5.15.2.1-src/ but hopefully the migration to Qt6 can be done soon, I know this is not in your plate but the responsibility of each software maintainer :(

Complementary to the changes in pyside2uic, the origin of that piece of software was an early fork from PyQt's uic implementation, but it was really hard to keep it up-to-date so we decided to drop support for that code, and we deprecated it.
We went on a different direction, and we include Python support within the official uic tool, mainly to try to make Python a first-class citizen within the common Qt ecosystem.

The story of the dynamical loader, was motivated for our discussion with the people from pyqtgraph, that they required something to load .ui files, and not only convert them, so we did a loadUiType function, which might be equivalent in this code to achieve something similar. The CPython code can be found in https://code.qt.io/cgit/pyside/pyside-setup.git/tree/sources/pyside6/PySide6/glue/qtuitools.cpp#n115 but overall it's calling 'uic' as a process, and eval the converted code.

@n-elie n-elie deleted the python39 branch March 1, 2022 21:00
@CAM-Gerlach
Copy link
Copy Markdown
Member

CAM-Gerlach commented Mar 1, 2022

We decided that supporting 3.10 was necessary, and we did a special release 5.15.2.1 that only included 3.10 support. You can check the wheel tags here https://pypi.org/project/PySide2/#files

Ah, gotcha, thanks—I'm glad for that. Looks like that happened after I last checked on the status of it.

As many linux distributions, it's common to include patches on top of the latest source: https://download.qt.io/official_releases/QtForPython/pyside2/PySide2-5.15.2.1-src/ but hopefully the migration to Qt6 can be done soon, I know this is not in your plate but the responsibility of each software maintainer :(

Realistically, we're probably going to have to support Qt5 for many years yet, considering QtPy's purpose is a compatibility layer and Qt6 was released fairly recently and is still working to reach feature parity with Qt5, and Qt6 isn't out yet on CF or AD. Pragmatically, getting a new Qt minor/LTS version building and working on Conda-Forge (much less a major version) is a pretty large undertaking; builds there are still stuck on Qt 5.12.x (though I believe @dalthviz @andfoy is currently working on updating that, IIRC), and the official AD defaults builds are even further behind, on Qt 5.9 (which we don't have any control over).

@dalthviz
Copy link
Copy Markdown
Member

dalthviz commented Mar 3, 2022

Thank you for the feedback @CAM-Gerlach and @cmaureir ! Also, just in case @andfoy is the one working on getting a new Qt minor/LTS version on conda-forge. Some links to the work he has been doing: conda-forge/qt-feedstock#206 https://github.com/conda-forge/qt-main-feedstock)

@CAM-Gerlach
Copy link
Copy Markdown
Member

Ah, sorry—somehow got it confused. Thanks for the links!

@n-elie
Copy link
Copy Markdown
Contributor Author

n-elie commented Mar 11, 2022

I opened a PR on pyside2-feedstock with a patch for this: [conda-forge/pyside2-feedstock#105]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants