From c190994eb348eaf97ffd4d9e5c38911d0d7f874b Mon Sep 17 00:00:00 2001 From: Jan Pazdziora Date: Sat, 9 Nov 2024 15:42:09 +0100 Subject: [PATCH] With setuptools changes, it is increasingly hard to build using bdist_rpm or test using setuptools. The setuptools 69.3.0 started to change dashes to underscores, leading to + /usr/lib/rpm/rpmuncompress -x -v /src/build/bdist.linux-x86_64/rpm/SOURCES/python-libssh-0.0.1.tar.gz error: File /src/build/bdist.linux-x86_64/rpm/SOURCES/python-libssh-0.0.1.tar.gz: No such file or directory error: Bad exit status from /var/tmp/rpm-tmp.deAYuh (%prep) https://github.com/pypa/setuptools/issues/3593 The setuptools 72.0.2 removed setup.py test command, leading to /usr/lib/python3.13/site-packages/setuptools/_distutils/dist.py:261: UserWarning: Unknown distribution option: 'test_suite' warnings.warn(msg) usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: setup.py --help [cmd1 cmd2 ...] or: setup.py --help-commands or: setup.py cmd --help error: invalid command 'test' https://github.com/pypa/setuptools/issues/4519 --- .github/workflows/build-test.yaml | 8 +++---- Makefile | 36 +++++++++++++++++++++++++++++++ README.md | 11 +++++++++- pyproject.toml | 21 ++++++++++++++++++ python-libssh.spec | 33 ++++++++++++++++++++++++++++ setup.py | 5 ----- tests/Dockerfile | 9 +++++--- 7 files changed, 109 insertions(+), 14 deletions(-) create mode 100644 pyproject.toml create mode 100644 python-libssh.spec diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index f4f981a..e12071b 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -17,8 +17,6 @@ jobs: os: - registry.fedoraproject.org/fedora:latest - registry.fedoraproject.org/fedora:rawhide - - docker.io/almalinux:8 - - quay.io/centos/centos:stream9 steps: - uses: actions/checkout@v4 - name: Set the right OS in the Dockerfile @@ -27,7 +25,7 @@ jobs: run: docker build -t python-libssh -f tests/Dockerfile . - name: Run container run: docker run --name python-libssh --rm -d python-libssh - - name: Run tests in the container - run: docker exec python-libssh python3 setup.py test - - name: Run tests with installed rpm + - name: Run tests with unittest discover + run: docker exec python-libssh python3 -m unittest discover -v -s tests -p 't*_*.py' + - name: Run tests manually run: docker exec python-libssh bash -c 'cp -rp tests /tmp/tests && cd /tmp/tests && for i in *.py ; do python3 -Werror $i ; done' diff --git a/Makefile b/Makefile index d8c52ad..ea44a1c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,40 @@ +NAME = python-$(shell eval echo $$( awk '/^name/ { print $$NF }' pyproject.toml)) +VERSION = $(shell eval echo $$( awk '/^version/ { print $$NF }' pyproject.toml)) +DIST = dist +SPECFILE = $(NAME).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: tar-gz + rpmbuild -D '_srcrpmdir $(DIST)' -D '_sourcedir $(DIST)' -bs $(SPECFILE) + ls -l $(DIST)/*.src.rpm + +dynamic-build-requires: tar-gz + rpmbuild -D '_srcrpmdir $(DIST)' -D '_sourcedir $(PWD)/$(DIST)' -br $(SPECFILE) + +rpm: tar-gz + rpmbuild -D '_rpmdir $(DIST)' -D '_sourcedir $(PWD)/$(DIST)' -bb $(SPECFILE) + mv $(DIST)/$$(uname -m)/*.$$(uname -m).rpm $(DIST) + ls -l $(DIST)/*.$$(uname -m).rpm + # rpm -qlp $(DIST)/*.$$(uname -m).rpm + # rpm -q --requires -p $(DIST)/*.$$(uname -m).rpm + +test: + ./test.sh + +test-pylint: + pylint-3 --disable=R --disable=C --indent-string="\t" --extension-pkg-whitelist=rpm,lxml libssh.pyx + clean: rm -rf $(shell cat .gitignore) +.PHONY: tar-gz srpm rpm test test-pylint clean + diff --git a/README.md b/README.md index a684a63..1724107 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,11 @@ Build the extension with ``` +make rpm +rpm -Uvh dist/python-libssh*.rpm +``` +or +``` python3 setup.py build_ext --inplace ``` @@ -16,12 +21,16 @@ In other words, `ssh localhost true` needs to work. Test it with ``` +python3 -m unittest discover -v -s tests -p 't*_*.py' +``` +or +``` python3 setup.py test ``` ## Author -Written by Jan Pazdziora, 2019 +Written by Jan Pazdziora, 2019--2024 ## License diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..db44083 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,21 @@ + +[project] +name = "libssh" +version = "0.0.1" +authors = [{name = "Jan Pazdziora"}] +license = {text = "GNU Lesser General Public License v2 (LGPLv2)"} +description = "Python bindings to client functionality of libssh" +classifiers = [ + "Development Status :: 2 - Pre-Alpha", + "License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)", + "Topic :: Security", +] + +[build-system] +requires = ["setuptools", "Cython"] +build-backend = "setuptools.build_meta" + +[tool.setuptools] +packages = ["libssh"] +package-dir = {"libssh" = "."} + diff --git a/python-libssh.spec b/python-libssh.spec new file mode 100644 index 0000000..5d32ad6 --- /dev/null +++ b/python-libssh.spec @@ -0,0 +1,33 @@ + +Name: python-libssh +Version: 0.0.1 +Release: 1%{?dist} + +Summary: Python bindings to client functionality of libssh +License: LGPLv2 +URL: https://github.com/adelton/python-libssh +Source0: %{name}-%{version}.tar.gz + +BuildRequires: libssh-devel +BuildRequires: python3-devel +BuildRequires: python3-wheel + +%description +Python bindings to client functionality of libssh. + +%prep +%autosetup + +%generate_buildrequires +%pyproject_buildrequires -p + +%build +%pyproject_wheel + +%install +%pyproject_install + +%pyproject_save_files -l libssh + +%files -f %{pyproject_files} + diff --git a/setup.py b/setup.py index 490f498..ed9baf0 100644 --- a/setup.py +++ b/setup.py @@ -8,10 +8,6 @@ from setuptools.extension import Extension from Cython.Build import cythonize -import unittest -def get_tests(): - return unittest.TestLoader().discover("tests", pattern="*.py") - setup( name = "python-libssh", version = "0.0.1", @@ -24,6 +20,5 @@ def get_tests(): "License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)", "Topic :: Security", ], - test_suite = "setup.get_tests", ) diff --git a/tests/Dockerfile b/tests/Dockerfile index 619d78a..c66b34a 100644 --- a/tests/Dockerfile +++ b/tests/Dockerfile @@ -4,7 +4,7 @@ RUN if test -f /etc/almalinux-release && grep 'AlmaLinux release 8' /etc/almalin dnf config-manager --set-enabled powertools ; fi RUN if test -f /etc/centos-release && grep 'CentOS Stream release 9' /etc/centos-release ; then \ dnf config-manager --set-enabled crb ; fi -RUN dnf install -y --setopt=install_weak_deps=False python3-devel python3-setuptools python3-Cython make gcc libssh-devel openssh-server openssh-clients rpm-build +RUN dnf install -y --setopt=install_weak_deps=False openssh-server openssh-clients make rpm-build gcc RUN if test -f /etc/nsswitch.conf ; then grep hosts: /etc/nsswitch.conf && sed -i 's/^hosts:.*/hosts: files dns myhostname/' /etc/nsswitch.conf ; fi RUN echo 'set enable-bracketed-paste off' >> ~root/.inputrc RUN for i in rsa ecdsa ed25519 ; do /usr/libexec/openssh/sshd-keygen $i ; done @@ -16,7 +16,10 @@ RUN yes | ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa RUN cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys && chmod 400 ~/.ssh/authorized_keys COPY . /src/ WORKDIR /src -RUN python3 setup.py build_ext --inplace -RUN python3 setup.py bdist_rpm +RUN if ! dnf --version | grep '^dnf5' ; then dnf install -y 'dnf-command(builddep)' ; fi +RUN dnf builddep -y python-libssh.spec +RUN make dynamic-build-requires || dnf builddep -y dist/*.buildreqs.nosrc.rpm +RUN make rpm +# RUN dnf install -y dist/python-libssh*.rpm RUN rpm -Uvh dist/python-libssh*.rpm ENTRYPOINT [ "/usr/sbin/sshd", "-D" ]