Skip to content

Find python package version via pkg_resources instead of pip-internal method

The pyversion.py script is called from DunePythonFindPackage.cmake and tries to find a package by its name, returning the extracted version number. Currently, it does so by checking the content of pip.get_installed_distributions().

However, in recent pip versions, pip.get_installed_distributions method was moved to pip._internal, leading to an AttributeError in the call to pyversion with packages that did not supply the __version__ variable.
Consequently, for those packages, DunePythonFindPackage will always evaluate to false.

What does this MR do?

This MR restores the behaviour of the pyversion.py script to look for the version of a package in other places then only the version variable.

It does so via pkg_resources.working_set, which offers access to the same information on installed distributions and is the recommended way. (Note, that it is strongly suggested to not use the pip._internal interface.)

Also, it removes the defunct implementation via the pip interface.

Open questions

Can it be assumed that pkg_resources is installed?
The get-pip.py docs suggest that it is installed unless explicitly suppressed by passing a flag, but I am not too familiar with the exact setup of the virtual environment...

Merge request reports