From 9d8c75289d94c141ab14f4e9dee840ac342c938f Mon Sep 17 00:00:00 2001 From: Jan Pazdziora Date: Fri, 16 Feb 2024 14:22:57 +0100 Subject: [PATCH] Desperate attempt to figure out how rpm should be built in 2024 given deprecation of bdist_rpm in https://github.com/pypa/setuptools/issues/1988 does not provide any solid guidance about replacements. We just use a .spec file template in the end. But it does not seem to 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/ --- .circleci/config.yml | 4 +- .cirrus.yml | 2 - .github/workflows/build-test.yaml | 4 +- Makefile | 38 ++++++++--- bdist_rpm/install_script | 20 ------ pyproject.toml | 39 ++++++++++++ rpm2swidtag.spec.in | 101 ++++++++++++++++++++++++++++++ setup.cfg | 9 ++- setup.py | 40 ------------ tests/Dockerfile | 1 - tests/build.sh | 3 +- 11 files changed, 177 insertions(+), 84 deletions(-) delete mode 100644 bdist_rpm/install_script create mode 100644 pyproject.toml create mode 100644 rpm2swidtag.spec.in delete mode 100644 setup.py diff --git a/.circleci/config.yml b/.circleci/config.yml index 38adfd5..7b4f6db 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 @@ -26,4 +26,4 @@ workflows: - arm-container: matrix: parameters: - os: [ fedora-latest, centos-stream-9, centos-stream-8 ] + os: [ fedora-latest ] diff --git a/.cirrus.yml b/.cirrus.yml index c20bec8..f71c1aa 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -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 diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index a1a6d4d..3d167e8 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -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 diff --git a/Makefile b/Makefile index 928d7f6..7195fb5 100644 --- a/Makefile +++ b/Makefile @@ -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 + diff --git a/bdist_rpm/install_script b/bdist_rpm/install_script deleted file mode 100644 index b1c9826..0000000 --- a/bdist_rpm/install_script +++ /dev/null @@ -1,20 +0,0 @@ -python3 setup.py install --single-version-externally-managed -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES -# workaround https://bugs.python.org/issue20337 -sed -i 's#^/etc#%config(noreplace) /etc#' INSTALLED_FILES - -%check -make test-pylint test - -%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 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..3e06e79 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,39 @@ + +[project] +name = "rpm2swidtag" +version = "0.8.20" +authors = [{name = "Jan Pazdziora", email = "jpazdziora@redhat.com"}] +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", +] + diff --git a/rpm2swidtag.spec.in b/rpm2swidtag.spec.in new file mode 100644 index 0000000..3742279 --- /dev/null +++ b/rpm2swidtag.spec.in @@ -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 diff --git a/setup.cfg b/setup.cfg index f301ab9..72e0590 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 + diff --git a/setup.py b/setup.py deleted file mode 100644 index 7eb85e2..0000000 --- a/setup.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python - -from setuptools import setup - -setup( - name = 'rpm2swidtag', - version = '0.8.20', - description = 'Tools for producing SWID tags from rpm package headers and inspecting the SWID tags', - author = 'Jan Pazdziora', - author_email = 'jpazdziora@redhat.com', - license = 'ASL 2.0', - 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', - ], - package_dir = {'': 'lib'}, - packages = ['rpm2swidtag', 'swidq'], - py_modules = ['dnf-plugins.swidtags'], - scripts = ['bin/rpm2swidtag', 'bin/dnf-plugin-swidtags-update-from-0.7', 'bin/swidq'], - data_files = [ - ('/etc/rpm2swidtag', ['rpm2swidtag.conf', 'swidtag-template.xml', 'swidtag.xslt', 'rpm2swidtag.xslt', 'rpm2swidtag-tagid.xslt']), - ('/etc/rpm2swidtag/rpm2swidtag.conf.d', ['rpm2swidtag.conf.d/fedora-rawhide.conf', 'rpm2swidtag.conf.d/fedora-40.conf', 'rpm2swidtag.conf.d/fedora-39.conf', 'rpm2swidtag.conf.d/fedora-38.conf', 'rpm2swidtag.conf.d/fedora-37.conf']), - ('/etc/swid', ['swidq.conf']), - ('/etc/swid/swidtags.d', []), - ('/usr/share/swidq/stylesheets', ['swidq-info.xslt', 'swidq-dump.xslt', 'swidq-files.xslt', 'swidq-xml.xslt']), - ('/etc/dnf/plugins', ['dnf/plugins/swidtags.conf']), - ], - install_requires = ['rpm', 'lxml'], -) diff --git a/tests/Dockerfile b/tests/Dockerfile index 9c58f87..e3a3d4e 100644 --- a/tests/Dockerfile +++ b/tests/Dockerfile @@ -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 diff --git a/tests/build.sh b/tests/build.sh index 6240a9c..20dc8af 100755 --- a/tests/build.sh +++ b/tests/build.sh @@ -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