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? ...

@@ -0,0 +1,12 @@
# Installs Python METADATA and INSTALLER files for compatability with importlib.metadata

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.

Suggested change
# Installs Python METADATA and INSTALLER files for compatability with importlib.metadata
# Installs Python METADATA and INSTALLER files for compatibility with importlib.metadata

# 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 SKBUILD)

@siliataider siliataider Jun 24, 2026

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.

Suggested change
IF(NOT SKBUILD)
if(NOT SKBUILD)

since you're ending the block with endif() lower case

Comment thread config/METADATA.in Outdated
Name: root
Version: @ROOT_VERSION@
Summary: Analyzing petabytes of data, scientifically.
Maintainer-Email: Vincenzo Eduardo Padulano <vincenzo.eduardo.padulano@cern.ch>

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.

Suggested change
Maintainer-Email: Vincenzo Eduardo Padulano <vincenzo.eduardo.padulano@cern.ch>
Maintainer-email: Vincenzo Eduardo Padulano <vincenzo.eduardo.padulano@cern.ch>

see spec https://packaging.python.org/en/latest/specifications/core-metadata/#maintainer-email

@github-actions

Copy link
Copy Markdown

Test Results

    21 files      21 suites   3d 8h 21m 25s ⏱️
 3 873 tests  3 873 ✅ 0 💤 0 ❌
73 880 runs  73 880 ✅ 0 💤 0 ❌

Results for commit 017eba2.

@jase231 jase231 force-pushed the jserwe_provide_python_metadata branch 2 times, most recently from 9764475 to e1ae3cc Compare June 24, 2026 15:18
@jase231 jase231 force-pushed the jserwe_provide_python_metadata branch from e1ae3cc to 8eebeba Compare June 24, 2026 15:20
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