File python-pwntools.spec of Package python-pwntools

#
# spec file for package python-pwntools
#
# Copyright (c) 2025 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


Name:           python-pwntools
Version:        4.14.1
Release:        0
Summary:        A CTF framework and exploit development library
License:        MIT AND BSD-2-Clause AND GPL-2.0-or-later
URL:            https://pwntools.com
Source:         https://files.pythonhosted.org/packages/source/p/pwntools/pwntools-%{version}.tar.gz
Source1:        python-pwntools.rpmlintrc
BuildRequires:  %{python_module devel}
BuildRequires:  %{python_module pip}
BuildRequires:  %{python_module setuptools >= 44.0}
BuildRequires:  %{python_module wheel}
BuildRequires:  fdupes
BuildRequires:  python-rpm-macros
BuildRequires:  python3-capstone
Requires:       python-PySocks
Requires:       python-gunicorn >= 2.0.1
Requires:       python-intervaltree >= 3.0
Requires:       python-mako >= 1.0.0
Requires:       python-packaging
Requires:       python-paramiko >= 1.15.2
Requires:       python-pip >= 6.0.8
Requires:       python-psutil >= 3.3.0
Requires:       python-pyelftools >= 0.29
Requires:       python-pygments >= 2.0
Requires:       python-pyserial >= 2.7
Requires:       python-python-dateutil
Requires:       python-requests >= 2.0
Requires:       python-ropgadget >= 5.3
Requires:       python-rpyc
Requires:       python-six >= 1.12.0
Requires:       python-sortedcontainers
Requires:       python-unix-ar
Requires:       python3-capstone >= 3.0.5rc2
Requires:       python3-zstandard
Requires(post): update-alternatives
Requires(postun): update-alternatives
BuildArch:      noarch
%python_subpackages

%description
Pwntools is a CTF framework and exploit development library. Written
in Python, it is designed for rapid prototyping and development, and
intended to make exploit writing as simple as possible.

%prep
%autosetup -p1 -n pwntools-%{version}

%build
%pyproject_wheel

%install
%pyproject_install
%python_clone -a %{buildroot}%{_bindir}/pwn

rm %{buildroot}%{_bindir}/hex \
 %{buildroot}%{_bindir}/version \
 %{buildroot}%{_bindir}/cyclic \
 %{buildroot}%{_bindir}/scramble \
 %{buildroot}%{_bindir}/asm \
 %{buildroot}%{_bindir}/libcdb \
 %{buildroot}%{_bindir}/elfpatch \
 %{buildroot}%{_bindir}/pwnstrip \
 %{buildroot}%{_bindir}/unhex \
 %{buildroot}%{_bindir}/template \
 %{buildroot}%{_bindir}/shellcraft \
 %{buildroot}%{_bindir}/elfdiff \
 %{buildroot}%{_bindir}/disablenx \
 %{buildroot}%{_bindir}/debug \
 %{buildroot}%{_bindir}/main \
 %{buildroot}%{_bindir}/phd \
 %{buildroot}%{_bindir}/update \
 %{buildroot}%{_bindir}/checksec \
 %{buildroot}%{_bindir}/common \
 %{buildroot}%{_bindir}/disasm \
 %{buildroot}%{_bindir}/constgrep \
 %{buildroot}%{_bindir}/errno

# remove the documentation
rm -r %{buildroot}%{_prefix}/pwntools-doc/

# replace #!/usr/bin/env python with #!/usr/bin/python3
%python_expand find %{buildroot}%{$python_sitelib} -name "*.py" -type f -exec sed -i 's|#!%{_bindir}/env python|#!%{_bindir}/python3|' {} \;

%{python_expand # if a file starts with #!%{_bindir}/python3, make it executable
    files=$(find %{buildroot}%{$python_sitelib} -name "*.py" -type f)
    for file in $files; do
        if [ -f "$file" ] && [ "$(head -n 1 "$file")" = "#!%{_bindir}/python3" ]; then
            chmod +x "$file"
        fi
    done
}

# even recompiling every .py, I can't manage to make mtime the same as the original file,
# so for now, just remove the .pyc files
%python_expand find %{buildroot}%{$python_sitelib} -name "__pycache__" -type d | xargs rm -rf

%python_expand %fdupes %{buildroot}%{$python_sitelib}

%post
%python_install_alternative pwn

%postun
%python_uninstall_alternative pwn

%files %{python_files}
%doc CHANGELOG.md README.md
%license LICENSE-pwntools.txt
%python_alternative %{_bindir}/pwn
%{python_sitelib}/pwn
%{python_sitelib}/pwnlib
%{python_sitelib}/pwntools-%{version}.dist-info

%changelog
openSUSE Build Service is sponsored by