打包Python项目为rpm时遇到python setup.py build报错的问题

发布于 2022-09-11 16:23:26 字数 4587 浏览 22 评论 0

问题描述

使用rpmbuild打包python项目,执行报错
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)

问题出现的环境背景及自己尝试过哪些方法

Python版本 2.7.0
pbr版本5.1.1
setuptools版本 40.6.3

1.直接使用 python setup.py build正常
2.直接使用 python setup.py bdist_rpm 也可以正常打包.但在centos下执行该命令也报错.

相关代码

setup.py

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

# In python < 2.7.4, a lazy loading of package `pbr` will break
# setuptools if some other modules registered functions in `atexit`.
# solution from: http://bugs.python.org/issue15881#msg170215
try:
    import multiprocessing  # 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}/*
#{_sysconfdir}/logrotate.d/autoinstall
/var/log/autoinstall
/var/lib/autoinstall

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文