Encountered the problem of python setup.py build error when packaging Python project as rpm

problem description

use rpmbuild to package python projects, and execute
rpmbuild-bb autoinstall.spec

hrwxr-xr-x XXX/XXX     0 2018-12-19 13:38 autoinstall-1.0/autoinstall/.gitignore link to autoinstall-1.0/autoinstall/.gitignore
+ STATUS=0
+ [ 0 -ne 0 ]
+ cd autoinstall-1.0
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.witEBA
+ umask 022
+ cd /home/XXX/rpmbuild/BUILD
+ cd autoinstall-1.0
+ python setup.py build
ERROR:root:Error parsing
Traceback (most recent call last):
  File "/home/XXX/.local/lib/python2.7/site-packages/pbr/core.py", line 96, in pbr
    attrs = util.cfg_to_args(path, dist.script_args)
  File "/home/XXX/.local/lib/python2.7/site-packages/pbr/util.py", line 256, in cfg_to_args
    pbr.hooks.setup_hook(config)
  File "/home/XXX/.local/lib/python2.7/site-packages/pbr/hooks/__init__.py", line 25, in setup_hook
    metadata_config.run()
  File "/home/XXX/.local/lib/python2.7/site-packages/pbr/hooks/base.py", line 27, in run
    self.hook()
  File "/home/XXX/.local/lib/python2.7/site-packages/pbr/hooks/metadata.py", line 26, in hook
    self.config["name"], self.config.get("version", None))
KeyError: "name"
error in setup command: Error parsing /home/XXX/rpmbuild/BUILD/autoinstall-1.0/setup.cfg: KeyError: "name"
error: Bad exit status from /var/tmp/rpm-tmp.witEBA (%build)

the environmental background of the problems and what methods you have tried

Python 2.7.0
pbr5.1.1
setuptools 40.6.3

1. Directly use python setup.py build normal
2. You can also package normally by directly using python setup.py bdist_rpm . But executing the command under centos also reported an error.

related codes

setup.py

-sharp THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT
import setuptools

-sharp In python < 2.7.4, a lazy loading of package `pbr` will break
-sharp setuptools if some other modules registered functions in `atexit`.
-sharp solution from: http://bugs.python.org/issue15881-sharpmsg170215
try:
    import multiprocessing  -sharp noqa
except ImportError:
    pass

setuptools.setup(
    setup_requires=["pbr"],
    pbr=True)

setup.cfg

[metadata]
name = autoinstall
version = 1.0
summary = autoinstall
author = Yannis
author-email = openstack-dev@lists.openstack.org
home-page = http://www.openstack.org/
classifier =
    Environment :: TusCloud
    Intended Audience :: Information Technology
    Intended Audience :: System Administrators
    License :: OSI Approved :: Apache Software License
    Operating System :: POSIX :: Linux
    Programming Language :: Python
    Programming Language :: Python :: 2
    Programming Language :: Python :: 2.7

[files]
packages =
    autoinstall

[pbr]
autodoc_index_modules = True

[build_sphinx]
all_files = 1
build-dir = doc/build
source-dir = doc/source

[egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0

[wheel]
universal = 1

autoinstall.spec

%if 0%{?rhel} && 0%{?rhel} <= 6
%{!?__python2: %global __python2 /usr/bin/python2}
%{!?python2_sitelib: %global python2_sitelib %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")}
%{!?python2_sitearch: %global python2_sitearch %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")}
%else
%global __python2 /usr/bin/python
%endif

%define name autoinstall
%define version 1.0
%define unmangled_version 1.0
%define unmangled_version 1.0
%define release 1
Summary: auto install scripts for tusCloud
Name: %{name}
Version: %{version}
Release: %{release}
Source0: %{name}-%{unmangled_version}.tar.gz
License: UNKNOWN
Group: Development/Libraries
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
Prefix: %{_prefix}
BuildArch: noarch
Vendor: UNKNOWN <UNKNOWN>
Provides: provide-files

%description
UNKNOWN

%prep
%setup -n %{name}-%{unmangled_version} -n %{name}-%{unmangled_version}

%build
python setup.py build

%install
python setup.py install -O1 --skip-build --root=$RPM_BUILD_ROOT
mkdir -p %{buildroot}%{_sysconfdir}/%{name}/
mkdir -p %{buildroot}%{_bindir}/
mkdir -p %{buildroot}/var/lib/autoinstall
mkdir -p %{buildroot}/var/log/autoinstall
touch -c %{buildroot}/var/log/autoinstall/auto_install.log

install -p -D -m 755 %{_builddir}/%{name}-%{version}/bin/* %{buildroot}/%{_bindir}/

%clean
rm -rf $RPM_BUILD_ROOT

%files
%{python_sitelib}/autoinstall*
%defattr(-,root,root)
%config(noreplace) %attr(-,root,root) %{_sysconfdir}/%{name}/
%{_bindir}/*
-sharp{_sysconfdir}/logrotate.d/autoinstall
/var/log/autoinstall
/var/lib/autoinstall
Feb.25,2022
Menu