Skip to content

Commit

Permalink
With setuptools changes, it is increasingly hard to build using bdist…
Browse files Browse the repository at this point in the history
…_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)

pypa/setuptools#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'

pypa/setuptools#4519
  • Loading branch information
adelton committed Nov 9, 2024
1 parent a43e344 commit c190994
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 14 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

Build the extension with
```
make rpm
rpm -Uvh dist/python-libssh*.rpm
```
or
```
python3 setup.py build_ext --inplace
```

Expand All @@ -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

Expand Down
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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" = "."}

33 changes: 33 additions & 0 deletions python-libssh.spec
Original file line number Diff line number Diff line change
@@ -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}

5 changes: 0 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -24,6 +20,5 @@ def get_tests():
"License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)",
"Topic :: Security",
],
test_suite = "setup.get_tests",
)

9 changes: 6 additions & 3 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" ]

0 comments on commit c190994

Please sign in to comment.