I’m working on packaging one of my projects into an RPM for Fedora. The project uses python hatch for building and I’ve looked at some existing examples in the Fedora tree that use the PEP517 build process. Here is the spec file I came up with:
Name: mediahug
Version: 0.4.dev4+g155a7b0
Release: 1%{?dist}
Summary: Video and Media Browser
License: AGPLv3
URL: https://battlepenguin.com
Source0: https://nexus.sumit.im/repository/bp-python-snapshots/packages/%{name}/%{version}/%{name}-%{version}.tar.gz
BuildArch: noarch
BuildRequires: python3-devel
BuildRequires: python3-pytest
# Runtime dependencies
# It appears these are just ignored as the builder pulls them from the
# pyproject.toml file, so I've commented them out
# Requires: python3dist(rich)
# Requires: python3dist(pyqt6)
# Requires: python3dist(rich)
# Requires: python3dist(opencv)
%description
MediaHug is media and video browser
%prep
%autosetup -p1
%generate_buildrequires
%pyproject_buildrequires
%build
%pyproject_wheel
%install
%pyproject_install
%pyproject_save_files -L %{name}
%check
%pytest
%files -f %{pyproject_files}
%license LICENSE.txt
%doc README.md
%changelog
* Mon Jun 02 2025 Sumit Khanna <sumit@battlepenguin.com> - 0.4.dev4+g155a7b0
- Initial package creation
..and my build Dockerfile
is pretty simple:
FROM fedora:42
RUN dnf install rpmdevtools python3-pytest python3-hatch-vcs python3-hatchling python3-devel \
python3-rich python3-click python3-pyqt6 python3-opencv
Some of the version numbers were a bit too specific, so I recreated the tar with more generic versions (e.g. click>=8
instead of click>=8.1.1
) just for testing. (Just in case you pull the tar URL and notice the versions are different).
I get the following when I run rpmbuild -ba mediahug.spec
+ TMPDIR=/root/rpmbuild/BUILD/mediahug-0.4.dev4+g155a7b0-build/mediahug-0.4.dev4+g155a7b0/.pyproject-builddir
+ RPM_TOXENV=py313
+ FEDORA=42
+ HOSTNAME=rpmbuild
+ /usr/bin/python3 -Bs /usr/lib/rpm/redhat/pyproject_buildrequires.py --generate-extras --python3_pkgversion 3 --wheeldir /root/rpmbuild/BUILD/mediahug-0.4.dev4+g155a7b0-build/mediahug-0.4.dev4+g155a7b0/pyproject-wheeldir --output /root/rpmbuild/BUILD/mediahug-0.4.dev4+g155a7b0-build/mediahug-0.4.dev4+g155a7b0-1.fc42.noarch-pyproject-buildrequires
Handling hatchling from build-system.requires
Requirement satisfied: hatchling
(installed: hatchling 1.27.0)
Handling hatch-vcs from build-system.requires
Requirement satisfied: hatch-vcs
(installed: hatch-vcs 0.4.0)
Handling click>=8 from hook generated metadata: Requires-Dist (mediahug)
Requirement satisfied: click>=8
(installed: click 8.1.7)
Handling opencv-python>=4 from hook generated metadata: Requires-Dist (mediahug)
Requirement not satisfied: opencv-python>=4
Handling pyqt6>=6.0.0 from hook generated metadata: Requires-Dist (mediahug)
Requirement satisfied: pyqt6>=6.0.0
(installed: pyqt6 6.9.0)
Handling python-mpv>=1.0.0 from hook generated metadata: Requires-Dist (mediahug)
Requirement not satisfied: python-mpv>=1.0.0
Handling rich>=13 from hook generated metadata: Requires-Dist (mediahug)
Requirement satisfied: rich>=13
(installed: rich 13.9.4)
Handling sqlite-connector>=0.1.0 from hook generated metadata: Requires-Dist (mediahug)
Requirement not satisfied: sqlite-connector>=0.1.0
Handling yoyo-migrations>=9.0.0 from hook generated metadata: Requires-Dist (mediahug)
Requirement not satisfied: yoyo-migrations>=9.0.0
+ cat /root/rpmbuild/BUILD/mediahug-0.4.dev4+g155a7b0-build/mediahug-0.4.dev4+g155a7b0-1.fc42.noarch-pyproject-buildrequires
+ rm -rfv mediahug-0.4.dev4+g155a7b0.dist-info/
removed 'mediahug-0.4.dev4+g155a7b0.dist-info/METADATA'
removed directory 'mediahug-0.4.dev4+g155a7b0.dist-info/'
+ RPM_EC=0
++ jobs -p
+ exit 0
error: Failed build dependencies:
python3dist(opencv-python) >= 4 is needed by mediahug-0.4.dev4+g155a7b0-1.fc42.noarch
python3dist(python-mpv) >= 1 is needed by mediahug-0.4.dev4+g155a7b0-1.fc42.noarch
python3dist(sqlite-connector) >= 0.1 is needed by mediahug-0.4.dev4+g155a7b0-1.fc42.noarch
python3dist(yoyo-migrations) >= 9 is needed by mediahug-0.4.dev4+g155a7b0-1.fc42.noarch
Wrote: /root/rpmbuild/SRPMS/mediahug-0.4.dev4+g155a7b0-1.fc42.buildreqs.nosrc.rpm
I realize python3-mpv
python3-sqlite-connector
and python3-yoyo-migrations
don’t exist in the Fedora repository, so I’ll have to make spec files for those and build them. But I’m wondering about opencv-python
. It seems like this package is called python3-opencv
on Fedora, but I need to keep opencv-python
in the pyproject.toml
since that’s the pypi
repository package name. Is there a way in the spec file to state that to satisfy opencv-python
it can use just python3dist(opencv)
instead?