Feature Request: find Python3 package

In a project I’m involved with, we need to check if certain Python packages are available to the interpreter. To do this, I have written a basic macro find_Python3_package.

This is used in a CMake block like this:

find_package(Python3 COMPONENTS Interpreter)
if(Python3_FOUND)
  find_Python3_package("pyyaml" HAS_PYYAML)
  find_Python3_package("ruamel.yaml" HAS_RUAMEL_YAML)
endif()

with a possible CMake configure output:

...
-- Found Python3: /usr/bin/python3.10 (found version "3.10.12") found components: Interpreter 
-- Looking for pyyaml
-- Looking for pyyaml - not found
-- Looking for ruamel.yaml
-- Looking for ruamel.yaml - found version "0.17.16"
...

I think this type of functionality could be potentially useful for others, and I don’t believe it exists anywhere else. Is it within scope to refine and contribute to the CMake source? I can push this effort, but I might need some guidance.

VTK has this module as well, but it doesn’t extract version information.

Cc: @marc.chevrier

I don’t think a such module is acceptable to be part of CMake distribution for the following reasons:

  1. The rule is to not accept any new module because the maintenance cost is, by far, too high and regularly raise problems because CMake releases are not in sync with artifacts release managed by the module, so regularly the modules become obsolete and cannot be fixed until the next CMake delivery.
  2. What you suggest implies a lot of developments (nearly infinite because python supports numerous packages) and a high cost of maintenance. So, a such module will be nearly always obsolete related to some python package…