Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- jrl_release: add `ConanFileVersionExtractor` by @arntanguy
- jrl_release: add `--check-version --check-tag vX.Y.Z` by @arntanguy
- jrl_release: add `DebianChangelogVersionExtractor` by @arntanguy
- jrl_check_python_module: fall back to `importlib.metadata` when the module has no `__version__` by @ahoarau
- jrl: change jrl_configure_default_install_dirs() to macro to make GNUInstallDirs in caller's scope by @ahoarau

## [2.1.0] - 2026-07-03
Expand Down
3 changes: 2 additions & 1 deletion v2/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,8 @@ jrl_check_python_module(

### Description
Find if a python module is available, fills <module_name>_FOUND variable.
Also fills <module_name>_VERSION variable if the module has a __version__ attribute.
Also fills <module_name>_VERSION variable if the module has a __version__ attribute,
falling back to importlib.metadata.version(<module_name>) otherwise.
Displays messages based on REQUIRED and QUIET options.


Expand Down
21 changes: 20 additions & 1 deletion v2/modules/jrl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3691,7 +3691,8 @@ jrl_check_python_module(

### Description
Find if a python module is available, fills <module_name>_FOUND variable.
Also fills <module_name>_VERSION variable if the module has a __version__ attribute.
Also fills <module_name>_VERSION variable if the module has a __version__ attribute,
falling back to importlib.metadata.version(<module_name>) otherwise.
Displays messages based on REQUIRED and QUIET options.


Expand Down Expand Up @@ -3725,6 +3726,24 @@ function(jrl_check_python_module module_name)
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Fallback: some modules do not expose a __version__ attribute, ask the
# package metadata instead (works only if the distribution name matches
# the module name).
if(module_found STREQUAL 0 AND NOT module_version)
execute_process(
COMMAND
${python} -c
"import importlib.metadata; print(importlib.metadata.version('${module_name}'), end='')"
RESULT_VARIABLE metadata_found
OUTPUT_VARIABLE metadata_version
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(metadata_found STREQUAL 0)
set(module_version "${metadata_version}")
endif()
endif()

if(module_found STREQUAL 0)
set(${module_name}_FOUND true PARENT_SCOPE)
if(module_version)
Expand Down
Loading