Andrei Rînea
Andrei Rînea

Reputation: 20780

Python RPM package generation fails with 'rpm: -ba: unknown option' - rpmbuild is available

My issue is very similar to this one. But it differs in a few key points and the solution over there does not work.

I have a simple Python 3 project with a package containing a few simple classes. I need to package this project as an RPM and publish it on a private repo.

Environment:

Mac OS X 10.15.3 (Catalina)
Python 3.7.3
rpm 4.15.1

Package           Version
----------------- -------
astroid           2.3.3  
coverage          5.0.4  
isort             4.3.21 
lazy-object-proxy 1.4.3  
mccabe            0.6.1  
pip               20.0.2 
pylint            2.4.4  
setuptools        46.1.3 
six               1.12.0 
typed-ast         1.4.1  
wheel             0.34.2 
wrapt             1.11.2

I have a setup.py file in the project root:

import setuptools

with open("README.md", "r") as fh:  # README.md exists alongside, is readable and has few ASCII text
    long_description = fh.read()

setuptools.setup(
    name="my_util",
    version="0.2.0",
    author="Andrei Rinea",
    author_email="[email protected]",
    description="Utils",
    long_description=long_description,
    long_description_content_type="text/markdown",
    url="https://example.com/",
    packages=setuptools.find_packages(),
    classifiers=[
        "Programming Language :: Python :: 3.7",
        "Operating System :: OS Independent",
        "License :: Other/Proprietary License"
    ],
    python_requires='>=3.7',
    license='(C) ACME Example 2020',
    platforms='any'
)

When I run

python setup.py bdist_rpm

I end up having an error:

... (successfully making directories, copying files etc.)
...
copying dist/my_util-0.2.0.tar.gz -> build/bdist.macosx-10.15-x86_64/rpm/SOURCES
building RPMs
rpm -ba --define _topdir /Users/andrei/Work/my-util/build/bdist.macosx-10.15-x86_64/rpm --clean build/bdist.macosx-10.15-x86_64/rpm/SPECS/my_util.spec
rpm: -ba: unknown option
error: command 'rpm' failed with exit status 1

rpmbuild is available in path:

% rpmbuild --version

RPM version 4.15.1

I searched all over Google but there aren't many results, the closest being the Stackoverflow question linked at the beginning. That one is on Linux, and it seems that installing rpm-build (which seems to be included with rpm on OS X) for that guy worked.

LATER EDIT: Distutils version:

% python3
Python 3.7.3 (default, Nov 15 2019, 04:04:52) 
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import distutils
>>> print (distutils.__version__)
3.7.3

Upvotes: 0

Views: 1210

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295242

The problem is that distutils 3.7.3 only uses rpmbuild if it's found in /bin or /usr/bin, as you can see in its source code:

rpm_cmd = ['rpm']
if os.path.exists('/usr/bin/rpmbuild') or \
   os.path.exists('/bin/rpmbuild'):
    rpm_cmd = ['rpmbuild']

If you can symlink it into that position, that's probably your easiest answer. Otherwise, you may need to patch your copy of bdist_rpm.py.

Upvotes: 3

Related Questions