Skip to content

Conversation

Flameeyes
Copy link

I've struggled getting these utilities to work with the Zephyr SDK due to the Python version.

So here's a pull request that removes the lxml dependency in favour of Python Standard Library's ElementTree instead.

While ElementTree has some slightly more verbose APIs to find the
text within sub-elements, it allows simplifying quite a bit the
iteration logic, but most importantly it is part of the Python Standard
Library.

In particular, there is a limitation in the Zephyr SDK where only Python
3.8 can be used, but many distributions (including OpenSuSE Tumbleweed
and CentOS 9 Stream) no longer support installing lxml on this version.

By using the standard library module, the code becomes a lot more
portable.
@bnahill
Copy link
Owner

bnahill commented Aug 1, 2023

Outstanding upgrade! Can you perhaps test out another option? There's a branch incorporating cmsis-svd (which also uses elementtree) as a parser replacement here. It's worked fine in my testing but it's been a while. I'm not entirely sure which way to go forward from here, but would like to avoid having two functionally similar codebases.

@Flameeyes
Copy link
Author

I'll give it a try, but I'm afraid it might have the same problem as the lxml dependency at least in the specific case I'm looking at: it requires a pip dependency (six), and at least on OpenSUSE there's no Python 3.8 pip 🫤

I originally considered splitting the parsing and loading, so that you can use your "usual" host Python to translate from SVD to a significantly simplified format that gdb can load, but then realized just hanging lxml→elementtree fixed it — but I totally see the point of not maintaining an equivalent parser.

This import is only used to find installed SVD files as part of
cmsis-svd.

But when using this project as part of a minimal Python installation
(such as if you try to use the Zephyr SDK on openSUSE Tumbleweed) there
is no pip, nor setuptools, nor ability to install cmsis-svd.

So don't fail to load, just ignore the cmsis_svd loading if the import
fails.
There is a similar check in `_print_registers()` when given a peripheral
with no registers, but there are also registers with no fields.
@Flameeyes Flameeyes changed the title Remove dependency on lxml Allow running with just Python Standard Library Aug 3, 2023
@Flameeyes
Copy link
Author

After I prepared this, openSUSE pulled one more package for Python 3.8 so I hit a different failure today 😅

I've added one more commit for it, and another commit for a small snag I hit while debugging the devkit I have at hand.

@maksimdrachov
Copy link

Perhaps this might be helpful, my setup: SAMC21, Zephyr RTOS, Atmel debugger.

https://forum.zubax.com/t/using-pycortexmdebug-with-zephyr-rtos/2174

@Grazfather
Copy link

This wouldn't work as the invoke method also needs pkg_resources (you'd have to import it at the top of that method as well).

It can be very annoying install packages into the python that gdb uses, I generally try to avoid it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants