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

    22 files      22 suites   3d 11h 23m 51s ⏱️
 3 876 tests  3 860 ✅   2 💤 14 ❌
75 313 runs  75 184 ✅ 115 💤 14 ❌

For more details on these failures, see this check.

Results for commit 6a5c4cc.

♻️ 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


ROOT_ADD_PYUNITTEST(regression_18441 regression_18441.py)

ROOT_ADD_PYUNITTEST(package_metadata package_metadata.py PYTHON_DEPS importlib)

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.

Suggested change
ROOT_ADD_PYUNITTEST(package_metadata package_metadata.py PYTHON_DEPS importlib)
ROOT_ADD_PYUNITTEST(package_metadata package_metadata.py)

importlib is part of the standard Python libraries, so we don't need to signal the dependency explicitly since it will always be present with a Python installation

Comment thread config/METADATA.in
@@ -0,0 +1,3 @@
Metadata-Version: 2.2
Name: root
Version: @ROOT_VERSION@ No newline at end of file

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.

Add newline at end of file

# See: https://packaging.python.org/en/latest/specifications/recording-installed-packages/

# scikit-build-core handles metadata so only do this for non-wheel builds to avoid conflict
if(NOT _wheel_build)

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.

Here we are missing more checks: pyroot option must be on, as well as Python3_FOUND which signals that there was actually a Python installation found for this build

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