malat
malat

Reputation: 12504

cmake: brp-python-bytecompile and python3

I am trying to create a python3 package using cpack (cmake). For some reason it is failing with a cryptic message:

+ /usr/lib/rpm/check-buildroot
+ /usr/lib/rpm/redhat/brp-compress
+ /usr/lib/rpm/redhat/brp-strip /usr/bin/strip
+ /usr/lib/rpm/redhat/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
+ /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
+ /usr/lib/rpm/brp-python-bytecompile /usr/bin/python 1
error: Bad exit status from /var/tmp/rpm-tmp.rt2mTp (%install)
    Bad exit status from /var/tmp/rpm-tmp.rt2mTp (%install)
 ***
CPackRPM:Debug:    - /mnt/source/bin2/_CPack_Packages/Linux/RPM/rpmbuildsource-python.out
CPackRPM:Debug: *** Building target platforms: x86_64
Building for target x86_64
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.mxEjdh
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.rt2mTp
Compiling /mnt/source/bin/_CPack_Packages/Linux/RPM/project-0.0.8-Linux/python/usr/lib/python3/dist-packages/project/__init__.py ...
  File "/usr/lib/python3/dist-packages/project/__init__.py", line 27
    raise ValueError(f"Not a {obj.__class__.__name__} reference")
                                       ^
SyntaxError: invalid syntax

Is there a way to skip brp-python-bytecompile step, or else is there a way to instruct cpack that the python package only target python3.

For reference:

# head -1 source/python/__init__.py
#!/usr/bin/env python3

Upvotes: 2

Views: 2706

Answers (3)

Eliover Gonzalez
Eliover Gonzalez

Reputation: 1

I recently have the same issue and I was able to skip brp-python-bytecompile step with the following: set(CPACK_RPM_SPEC_MORE_DEFINE "%undefine __python")

Upvotes: 0

gilsanx
gilsanx

Reputation: 21

I had a similar situation some minutes ago. In my case, my dev environment uses python 3 at a specific path, while the linux env has the 2.7 python bin (which is /usr/bin/python).

So, what I did was next:

...
/usr/bin/rpmbuild -bb --define "_python_override ${PYTHON_OVERRIDE}" ...
...

That is on a sh file which first calculates the path of python 3 and stores it at

$PYTHON_OVERRIDE

Then, on the spec file

%define __python %{_python_override}/python

With this, I make sure the RPM uses the same version I use to compile my python project.

Upvotes: 2

malat
malat

Reputation: 12504

There are two solutions:

  1. Rely on the /bin hack
  2. Change the default value for __python

For solution #1, you simply need to use a bin subfolder. Any python bytecompilation which happen in a sub-directory of /bin will not be done:

For solution #2, you simply need to follow:

For cmake the syntax is:

set(CPACK_RPM_SPEC_MORE_DEFINE "%define __python python3")

See also an alternate solution:

Upvotes: 3

Related Questions