Skip to content

Demo RPM builder for python packages

License

Notifications You must be signed in to change notification settings

mbrav/rpm-python-pack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Create Release Create Release

rpm-python-pack

Demo RPM builder for python packages

Clone repo

git clone https://github.com/mbrav/rpm-python-pack.git && \
cd rpm-python-pack/

Option 1: Build Package with PyInstaller

Pyinstaller is by far the best option as it packages all script's dependencies into a binary file that takes up many times less space than a regular python package with all its dependencies.

  1. Install PyInstaller

    pip3 install pyinstaller
  2. Build package

    pyinstaller cli.py --name python-pack-script --onefile
  3. Run binary

    ./dist/python-pack-script
    ✅ You should see output:

    This is python-pack-script v0.0.7!
    

Option 2: Build Python RPM package with setup.py

  1. Install rpm package tools

    sudo dnf install -y rpmdevtools rpmlint
  2. Build with Python's standard rpm build tool

    python3 setup.py bdist --formats=rpm
    python3 setup.py bdist_wheel --universal
    ℹ️ Convert pyproject.toml to setup.py

    pip3 install poetry2setup --user && \
    poetry2setup > setup.py

  3. Install package:

    sudo dnf localinstall dist/python-pack-script-*.noarch.rpm
  4. Check package info

    rpm -qi python-pack-script && which python-pack-script
    ✅ You should see info about package like so

    Name        : python-pack-script
    Version     : 0.0.7
    Release     : 1
    Architecture: noarch
    Install Date: Wed 27 Apr 2022 09:15:34 AM UTC
    Group       : Development/Libraries
    Size        : 1155
    License     : UNKNOWN
    Signature   : (none)
    Source RPM  : python-pack-script-0.0.7-1.src.rpm
    Build Date  : Wed 27 Apr 2022 09:11:18 AM UTC
    Build Host  : rocky.local
    Relocations : /usr
    Vendor      : mbrav <mbrav@protonmail.com>
    Summary     : Demo RPM builder for python packages
    Description :
    UNKNOWN
    

  5. Run package

    python-pack-script --help
    ✅ You should see output

    This is python-pack-script v0.0.7!
    

✏️ Notes

Setup rpmbuild folder

rpmdev-setuptree

It will create the following folder in your home directory:

rpmbuild/
├── BUILD
├── RPMS
├── SOURCES
├── SPECS
└── SRPMS

Build spec:

rpmbuild -ba ./build/bdist.linux-x86_64/rpm/SPECS/python-pack-script.spec

Option 3: Build Python package with Poetry (WIP)

This uses the new PEP 518 pyproject.yml standard, but a standard process for building rpm packages seems to yet be established

  1. Install poetry

  2. Build Python package

    poetry build
    ℹ️ Install package with pip

    Create a new python environment and activate it

    python3 -m venv venv && source venv/bin/activate

    Install script into environment

    pip3 install --no-cache-dir --force-reinstall \
    dist/python_pack_script-*-py3-none-any.whl
  3. Run script

    python -m python_pack_script --help

    ✅ You should see a print in your terminal

Resources