Home Backend Development Python Tutorial Packaging python RPMs

Packaging python RPMs

Jan 05, 2025 am 04:16 AM

Packaging python RPMs

Recently I was working on a very specific task in the current project that I'm
working for Red Hat, the RHEL Lightspeed
ShellAI, this project is
relatively new but we wanted to start shipping development RPMs for our QE
friends to start playing around the tool and testing it in their pipeline.

I know my way around packaging and general python stuff, but man, I have to
tell you, this packaging task took me two entire days to get through. Let me
guide your through the details of the task very quickly.

TLDR; everything worked out at the end and this is the resulting PR:
https://github.com/rhel-lightspeed/shellai/pull/4

Details of the task

The project, ShellAI, is intended ot be shipped under RHEL 9 and the upcoming
RHEL 10. As a bonus target, we would like to get it running also on RHEL 8.

By the statement above, if you already worked with RHEL before, you already
guessed that the challenge will be the version of the dependencies that lives
in RHEL.

  • RHEL 8 has Python 3.6
  • RHEL 9 has Python 3.9
  • and lastly, RHEL 10 has Python 3.12

We also would like to get development builds relatively frequently in order to
getting new features to be tested as we develop the tool.

For the development part, we would like to use
pdm to manage our dependencies and
builds. As we went through the taks we noticed that the pdm backend is not
shipped in the RHEL repositories, thus we went with default setuptools build
backend.

Since our system targets are "relatively new", we would like to modernize the
project and make sure that we are using new tools/structure and formats. For
that, we chose to do with a pyproject.toml, as it is generated via pdm init
when we bootstraped the proejct.

Problems with building the RPM

Initially, our idea was to use the most recent python features and project
structure, such as the pyproject.toml file instead of the legacy setup.py.
When you start a new project, everything is cool and new you get very excited
to use that stuff, the only problem is:

  • They are very good for development process, but not for packaging.

Initially, when I began the task, I thought that we could use the new RPM
macros for build the project, since we are using pyproject.toml and pdm for
managing dependencies.

For that, the Fedora Documentation has a nice article called Python Packaging
Guidelines
where they go in details. While the guide covers almost every topic and case
you may need, even with a example
specfile.

With our main target being RHEL, we could imagine that following everything
from the guide would work as-is, right? No. The reason for that lies in the
versions shipped in the RHEL repositories. Even though that the new macros
pointed in the guide may work during the build, you won't be able to generate
the final RPM in the following targets:

  • RHEL 8 will throw to you an error during the %generate_buildrequires, as the python3-setuptools version shipped in that release is super old and do not really recognize the new pyproject.toml format.
  • RHEL 9 will be able to progress through most of the steps, but will fail %pyproject_wheel as it will build a package with the name UNKNOWN. This is happens because (again) the python3-setuptools shipped under RHEL 9 is old. It doesn't recognize most of the metadata that is generated by the pyproject.toml specf.

The solution

We had to create a legacy
setup.py
file in order to progress with the Python wheel builds, and to avoid data
duplication between the pyproject.toml and our legacy setup.py file, we
used tomllib, because of the
following reasons:

  • The tomllib is available (through pypi and rpm packaging) in RHEL 8
  • After Python 3.11, tomllib got bundled natively into the standard library

As you have seen above, we used tomllib to load the pyproject.toml file and
read the necessary fields and simply update our legacy setup.py. This way, we
are able to modify pyproject.toml and whenever we push a new build, we will
be able to keep consistency in our legacy setup.py as well.

Regarding the specfile, we had to go back and use what the documentation calls
“201x-era” Python packaging
guidelines.
Essentially, we are using the good old python setup.py build ... command
(through macros, obviously) to build the project.

That solution enabled us to keep consistency across the RHEL versions we want
to support, and, at the same time, keep using pdm and the shiny new features
we would like for development.

The above is the detailed content of Packaging python RPMs. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the permissions problem encountered when viewing Python version in Linux terminal? How to solve the permissions problem encountered when viewing Python version in Linux terminal? Apr 01, 2025 pm 05:09 PM

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? Apr 01, 2025 pm 11:15 PM

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to dynamically create an object through a string and call its methods in Python? How to dynamically create an object through a string and call its methods in Python? Apr 01, 2025 pm 11:18 PM

In Python, how to dynamically create an object through a string and call its methods? This is a common programming requirement, especially if it needs to be configured or run...

How does Uvicorn continuously listen for HTTP requests without serving_forever()? How does Uvicorn continuously listen for HTTP requests without serving_forever()? Apr 01, 2025 pm 10:51 PM

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

How to teach computer novice programming basics in project and problem-driven methods within 10 hours? How to teach computer novice programming basics in project and problem-driven methods within 10 hours? Apr 02, 2025 am 07:18 AM

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

What are some popular Python libraries and their uses? What are some popular Python libraries and their uses? Mar 21, 2025 pm 06:46 PM

The article discusses popular Python libraries like NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, Django, Flask, and Requests, detailing their uses in scientific computing, data analysis, visualization, machine learning, web development, and H

How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? Apr 02, 2025 am 07:15 AM

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

See all articles