Skip to content

[cmake] Produce python .dist-info metadata#22688

Open
jase231 wants to merge 1 commit into
root-project:masterfrom
jase231:jserwe_provide_python_metadata
Open

[cmake] Produce python .dist-info metadata#22688
jase231 wants to merge 1 commit into
root-project:masterfrom
jase231:jserwe_provide_python_metadata

Conversation

@jase231

@jase231 jase231 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

This Pull request:

Makes the ROOT Python import package compatible with importlib.metadata's metadata system.

Changes or fixes:

Adds a cmake module that places a METADATA and INSTALLER files inside a root-<version>.dist-info folder on the PYTHONPATH, which importlib.metadata can access to query e.g. distribution package version.

This metadata is already present in the wheel distribution courtesy of the build backend, but is absent in all other ROOT distributions. importlib.metadata.version() will throw an exception if called on a ROOT source build, but works just fine for wheels. This PR's change standardizes this behavior.

See https://packaging.python.org/en/latest/specifications/recording-installed-packages/ for python's official spec.

Checklist:

  • tested changes locally
  • updated the docs (if necessary)

@jase231 jase231 requested review from bellenot and dpiparo as code owners June 23, 2026 15:37
@vepadulano vepadulano added the build-python-wheels Run the workflow to build Python wheels label Jun 23, 2026

@siliataider siliataider left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Very nice work! I have a couple of comments:

  • We would require a follow-up PR as the try / except block we added for the PackageNotFoundError should in principle no longer be needed here thanks to your addition in this PR
    # importlib.metadata.version reads distribution metadata from the package's
  • I have a small doubt about how to handle the synchronization between the metadata in this METADATA.in template and the pyproject.toml since it's hard coded here, say for example Requires-Dist evolves to not only include numpy, there is no mechanism that enforces applying changes in both files, thus metadata could quietly diverge, do we want to document that changes should be always applied to both files? Do we want to think of a way to generate the template by parsing pyproject.toml? ...

Comment thread cmake/modules/InstallPythonMetadata.cmake Outdated
Comment thread cmake/modules/InstallPythonMetadata.cmake Outdated
Comment thread config/METADATA.in Outdated
@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown

Test Results

    23 files      23 suites   3d 14h 3m 2s ⏱️
 3 877 tests  3 868 ✅   0 💤 9 ❌
78 846 runs  78 726 ✅ 111 💤 9 ❌

For more details on these failures, see this check.

Results for commit 5b50b2f.

♻️ This comment has been updated with latest results.

@jase231 jase231 force-pushed the jserwe_provide_python_metadata branch 4 times, most recently from 8eebeba to a05a820 Compare June 25, 2026 23:17
@jase231 jase231 requested a review from guitargeek as a code owner June 25, 2026 23:17
@jase231 jase231 force-pushed the jserwe_provide_python_metadata branch from a05a820 to 6a5c4cc Compare June 26, 2026 08:40

@vepadulano vepadulano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you! A couple of suggestions for improvement before running the CI

Comment thread bindings/pyroot/pythonizations/test/CMakeLists.txt Outdated
Comment thread config/METADATA.in Outdated
Comment thread cmake/modules/InstallPythonMetadata.cmake Outdated
@jase231 jase231 force-pushed the jserwe_provide_python_metadata branch from 6a5c4cc to 5b50b2f Compare June 29, 2026 13:22
@jase231

jase231 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

@vepadulano Suggestions should be applied now, along with a fix for failing windows builds

@siliataider

Copy link
Copy Markdown
Contributor

Workflow running, let's see what the CI says

@siliataider siliataider left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the changes!

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

Labels

build-python-wheels Run the workflow to build Python wheels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants