Skip to content

Commit

Permalink
Desperate attempt to figure out how rpm should be built in 2024
Browse files Browse the repository at this point in the history
to get rid of

    $ make spec
    python3 setup.py bdist_rpm --spec-only --install-script=bdist_rpm/install_script
    running bdist_rpm
    /usr/lib/python3.12/site-packages/setuptools/_distutils/dist.py:988: SetuptoolsDeprecationWarning: Deprecated command
    !!

            ********************************************************************************
            bdist_rpm is deprecated and will be removed in a future version.
            Use bdist_wheel (wheel packages) instead.

            This deprecation is overdue, please update your project and remove deprecated
            calls to avoid build errors in the future.

            See pypa/setuptools#1988 for details.
            ********************************************************************************

    !!

Given pypa/setuptools#1988 deprecates bdist_rpm
but does not provide any solid guidance about replacements, we just use
a .spec file template in the end. But the necessary dependencies do not
seem to be present / work on CentOS Stream 8 and 9, so we have to stop
testing on those.

We wanted to use pyproject.toml for everything.
But tool.setuptools.data-files does not respect absolute path
(unlike setup.py's data_files) so that has to be done with installs
in the .spec; and py-modules fails with
    configuration error: `tool.setuptools.py-modules[0]` must be python-module-name
    GIVEN VALUE:
        "dnf-plugins.swidtags"

    OFFENDING RULE: 'format'

    DEFINITION:
        {
            "type": "string",
            "format": "python-module-name"
        }
so we have to put those in setup.cfg.

https://gregoryszorc.com/blog/2023/10/30/my-user-experience-porting-off-setup.py/
  • Loading branch information
adelton committed Feb 17, 2024
1 parent 6e28c9c commit c4cda55
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 84 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
resource_class: arm.medium
steps:
- checkout
- run: sed -i "s#^FROM.*#FROM $( echo << parameters.os >> | sed 's#^fedora-#registry.fedoraproject.org/fedora:#; s#^centos-stream-#quay.io/centos/centos:stream#;' )#" tests/Dockerfile
- run: sed -i "s#^FROM.*#FROM $( echo << parameters.os >> | sed 's#^fedora-#registry.fedoraproject.org/fedora:#' )#" tests/Dockerfile
- run: docker build -t rpm2swidtag-source -f tests/Dockerfile .
- run: docker run --name rpm2swidtag-build -d rpm2swidtag-source sleep 600
- run: docker exec rpm2swidtag-build tests/build.sh
Expand All @@ -26,4 +26,4 @@ workflows:
- arm-container:
matrix:
parameters:
os: [ fedora-latest, centos-stream-9, centos-stream-8 ]
os: [ fedora-latest ]
2 changes: 0 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@ test_task:
matrix:
image: registry.fedoraproject.org/fedora:rawhide
image: registry.fedoraproject.org/fedora:latest
image: quay.io/centos/centos:stream9
image: quay.io/centos/centos:stream8
build_script: tests/build.sh
test_script: make test
4 changes: 2 additions & 2 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ fedora-rawhide, fedora-40, fedora-39, fedora-38, centos-stream-8, centos-stream-9 ]
os: [ fedora-rawhide, fedora-40, fedora-39, fedora-38 ]
steps:
- uses: actions/checkout@v4
- name: Set the right OS in the Dockerfile
run: sed -i "s#^FROM.*#FROM $( echo ${{ matrix.os }} | sed 's#^fedora-#registry.fedoraproject.org/fedora:#; s#^centos-stream-#quay.io/centos/centos:stream#;' )#" tests/Dockerfile
run: sed -i "s#^FROM.*#FROM $( echo ${{ matrix.os }} | sed 's#^fedora-#registry.fedoraproject.org/fedora:#' )#" tests/Dockerfile
- name: Create image with the source
run: podman build -t rpm2swidtag-source -f tests/Dockerfile .
- name: Run a container to build the rpm
Expand Down
38 changes: 28 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@

srpm:
python3 setup.py bdist_rpm --source-only --install-script=bdist_rpm/install_script
ls -l dist/*.src.rpm

rpm:
python3 setup.py bdist_rpm --binary-only --install-script=bdist_rpm/install_script
ls -l dist/*.noarch.rpm
NAME = $(shell eval echo $$( awk '/^name/ { print $$NF }' pyproject.toml))
VERSION = $(shell eval echo $$( awk '/^version/ { print $$NF }' pyproject.toml))
DIST = dist
SPECFILE = dist/$(NAME).spec

spec:
python3 setup.py bdist_rpm --spec-only --install-script=bdist_rpm/install_script
ls -l dist/*.spec
mkdir -p $(DIST)
rpm -D "version $(VERSION)" --eval "$$( cat rpm2swidtag.spec.in )" > $(SPECFILE)
ls -l $(DIST)/*.spec

tar-gz:
rm -rf $(DIST)/$(NAME)-$(VERSION)
mkdir -p $(DIST)/$(NAME)-$(VERSION)
cp -rp -t dist/$(NAME)-$(VERSION) $(shell ls | grep -v dist)
for i in $(shell cat .gitignore) ; do rm -rf $(DIST)/$$i ; done
tar -C $(DIST) -cvzf $(DIST)/$(NAME)-$(VERSION).tar.gz $(NAME)-$(VERSION)
rm -rf $(DIST)/$(NAME)-$(VERSION)
ls -l $(DIST)/*.tar.gz

srpm: spec tar-gz
rpmbuild -D '_srcrpmdir $(DIST)' -D '_sourcedir $(DIST)' -bs $(SPECFILE)
ls -l $(DIST)/*.src.rpm

rpm: spec tar-gz
rpmbuild -D '_rpmdir $(DIST)' -D '_sourcedir $(PWD)/$(DIST)' -bb $(SPECFILE)
mv $(DIST)/noarch/*.noarch.rpm $(DIST)
ls -l $(DIST)/*.noarch.rpm

test:
./test.sh

test-pylint:
pylint-3 --disable=R --disable=C --indent-string="\t" --extension-pkg-whitelist=rpm,lxml lib/*/*.py setup.py
pylint-3 --disable=R --disable=C --indent-string="\t" --extension-pkg-whitelist=rpm,lxml lib/*/*.py

clean:
rm -rf $(shell cat .gitignore)

.PHONY: spec tar-gz srpm rpm test test-pylint clean

20 changes: 0 additions & 20 deletions bdist_rpm/install_script

This file was deleted.

39 changes: 39 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

[project]
name = "rpm2swidtag"
version = "0.8.20"
authors = [{name = "Jan Pazdziora", email = "[email protected]"}]
license = {text = "ASL 2.0"}
description = "Tools for producing SWID tags from rpm package headers and inspecting the SWID tags"
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Console",
"Environment :: Plugins",
"Intended Audience :: System Administrators",
"Intended Audience :: Developers",
"Intended Audience :: Information Technology",
"License :: OSI Approved :: Apache Software License",
"Operating System :: POSIX",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3",
"Topic :: Security",
"Topic :: Software Development :: Build Tools",
"Topic :: System :: Systems Administration",
]

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
package-dir = {"" = "lib"}
# Workaround configuration error: `tool.setuptools.py-modules[0]` must be python-module-name
# by keeping this in setup.cfg file:
# py-modules = ["dnf-plugins.swidtags"]
packages = ["rpm2swidtag", "swidq"]
script-files = [
"bin/rpm2swidtag",
"bin/dnf-plugin-swidtags-update-from-0.7",
"bin/swidq",
]

101 changes: 101 additions & 0 deletions rpm2swidtag.spec.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
Name: rpm2swidtag
Version: %{version}
Release: 1%%{?dist}

Summary: Tools for producing SWID tags from rpm package headers and inspecting the SWID tags
License: ASL 2.0
URL: https://github.com/swidtags/rpm2swidtag
Source: %%{name}-%%{version}.tar.gz

Requires: python3-rpm
Requires: python3-lxml
Requires: python3-zstandard
Requires: dnf-plugins-core
Requires: xmlsec1-openssl
Obsoletes: dnf-plugin-swidtags
Obsoletes: swid-tools

BuildArch: noarch
BuildRequires: make
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-wheel
BuildRequires: python3-rpm
BuildRequires: python3-lxml
BuildRequires: python3-zstandard
BuildRequires: openssl
BuildRequires: xmlsec1-openssl
BuildRequires: createrepo_c
BuildRequires: fakechroot
BuildRequires: fakeroot
BuildRequires: dnf
BuildRequires: dnf-plugins-core
BuildRequires: gzip
BuildRequires: gnupg2
BuildRequires: python3-pylint


%%description
Tools for producing SWID tags from rpm package headers and inspecting the SWID tags.

%%prep
%%autosetup -p1

%%generate_buildrequires
%%pyproject_buildrequires

%%build
%%pyproject_wheel

%%install
%%pyproject_install
%%pyproject_save_files '*' +auto
install -D -t %%{buildroot}%%{_sysconfdir}/%%{name} \
rpm2swidtag.conf \
swidtag-template.xml \
swidtag.xslt \
rpm2swidtag.xslt \
rpm2swidtag-tagid.xslt
install -D -t %%{buildroot}%%{_sysconfdir}/%%{name}/rpm2swidtag.conf.d \
rpm2swidtag.conf.d/fedora-37.conf \
rpm2swidtag.conf.d/fedora-38.conf \
rpm2swidtag.conf.d/fedora-39.conf \
rpm2swidtag.conf.d/fedora-40.conf \
rpm2swidtag.conf.d/fedora-rawhide.conf
install -D -t %%{buildroot}%%{_sysconfdir}/swid swidq.conf
install -d %%{buildroot}%%{_sysconfdir}/swid/swidtags.d
install -D -t %%{buildroot}%%{_datarootdir}/swidq/stylesheets \
swidq-info.xslt \
swidq-dump.xslt \
swidq-files.xslt \
swidq-xml.xslt
install -D -t %%{buildroot}%%{_sysconfdir}/dnf/plugins dnf/plugins/swidtags.conf

%%check
%%pyproject_check_import
make test-pylint test

%%files -f %%{pyproject_files}

%%{_sysconfdir}/%%{name}
%%{_sysconfdir}/swid/swidq.conf
%%{_sysconfdir}/swid/swidtags.d
%%{_datarootdir}/swidq
%%{_sysconfdir}/dnf/plugins/swidtags.conf

%%post

if rpm -q rpm2swidtag dnf-plugin-swidtags 2> /dev/null | grep -E -q '(rpm2swidtag|dnf-plugin-swidtags)-0\.[1-7]\.[0-9]-' ; then
echo
echo "Please run dnf-plugin-swidtags-update-from-0.7 to update the filename format."

if echo "88d7506a4769d9402548cd9f0d242913cd46616f4fa755c52013094af33f5c1b /etc/dnf/plugins/swidtags.conf" | sha256sum -c > /dev/null 2>&1 ; then
sed -i 's/^# rpm2swidtag_command = /rpm2swidtag_command = /' /etc/dnf/plugins/swidtags.conf
echo
echo "The rpm2swidtag_command in /etc/dnf/plugins/swidtags.conf enabled"
echo "to keep the pre-0.8 behaviour."
fi
fi

%%changelog
%%autochangelog
9 changes: 4 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[bdist_rpm]
requires = python3-rpm python3-lxml python3-zstandard dnf-plugins-core xmlsec1-openssl
build_requires = python3 make python3-setuptools python3-rpm python3-lxml python3-zstandard openssl xmlsec1-openssl createrepo_c fakechroot fakeroot dnf dnf-plugins-core gzip gnupg2 python3-pylint
release = 1%%{dist}
obsoletes = dnf-plugin-swidtags swid-tools

[options]
py_modules = dnf-plugins.swidtags

40 changes: 0 additions & 40 deletions setup.py

This file was deleted.

1 change: 0 additions & 1 deletion tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
FROM registry.fedoraproject.org/fedora
COPY . /src/
WORKDIR /src
RUN if test -f /etc/centos-release ; then dnf install -y epel-release ; fi
3 changes: 1 addition & 2 deletions tests/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ set -x
export LC_ALL=C.utf8

DNF=dnf
test -f /etc/centos-release && $DNF install -y python3 epel-release
$DNF install -y rpm-build make "$DNF-command(builddep)" python3-setuptools
$DNF install -y rpm-build make "$DNF-command(builddep)"

make spec
$DNF builddep -y dist/rpm2swidtag.spec
Expand Down

0 comments on commit c4cda55

Please sign in to comment.