Skip to content

Commit

Permalink
Include dist-info for python3-dnf
Browse files Browse the repository at this point in the history
This is the DNF 4 cousin to this patch [0] for DNF 5.

Per [1], Python packages should include some minimal distribution
metadata, e.g. to make the package appear in `pip list`.

Perhaps the "proper way" to generate this dist-info metadata would be to
write a pyproject.toml and use a conventional Python build system like
Poetry to build `python3-dnf` rather than doing it with CMake, but this
is a way to do it with minimal changes to the build process.

Closes RhBug:2239323 [2]

[0] rpm-software-management/dnf5#447
[1] https://packaging.python.org/en/latest/specifications/core-metadata/#core-metadata,
[2] https://bugzilla.redhat.com/show_bug.cgi?id=2239323

= changelog =
msg: Add metadata for `dnf` Python package
type: bugfix
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2239323
  • Loading branch information
Your Name authored and jan-kolarik committed Oct 9, 2023
1 parent 552e61e commit 43e9249
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions dnf.spec
Expand Up @@ -363,6 +363,7 @@ popd
%{_bindir}/%{name}-3
%{_bindir}/%{name}4
%exclude %{python3_sitelib}/%{name}/automatic
%{python3_sitelib}/%{name}-*.dist-info
%{python3_sitelib}/%{name}/
%dir %{py3pluginpath}
%dir %{py3pluginpath}/__pycache__
Expand Down
9 changes: 9 additions & 0 deletions dnf/CMakeLists.txt
Expand Up @@ -3,6 +3,15 @@ INSTALL (FILES ${dnf_SRCS} DESTINATION ${PYTHON_INSTALL_DIR}/dnf)
# const.py is generated so the glob alone won't see it:
INSTALL (FILES const.py DESTINATION ${PYTHON_INSTALL_DIR}/dnf)

# Generate dist-info metadata
SET(DISTINFO_PATH "${CMAKE_CURRENT_BINARY_DIR}/dnf-${DNF_VERSION}.dist-info")
SET(METADATA_FILE "${DISTINFO_PATH}/METADATA")
FILE(MAKE_DIRECTORY ${DISTINFO_PATH})
FILE(WRITE ${METADATA_FILE} "Metadata-Version: 2.1\n")
FILE(APPEND ${METADATA_FILE} "Name: dnf\n")
FILE(APPEND ${METADATA_FILE} "Version: ${DNF_VERSION}\n")
INSTALL(DIRECTORY ${DISTINFO_PATH} DESTINATION ${PYTHON_INSTALL_DIR})

ADD_SUBDIRECTORY (automatic)
ADD_SUBDIRECTORY (cli)
ADD_SUBDIRECTORY (conf)
Expand Down

0 comments on commit 43e9249

Please sign in to comment.