Search code examples
pythonrpmpackagingrpm-specpython-packaging

How to create dummy RPM which pretends to provide Python modules?


I need to create a dummy RPM which appears to install some Python modules in site-packages to resolve an RPM dependency issue.

The real modules will be installed using PIP inside of a Python Virtual Environment, but in order for the system to work the modules which are imported need to be provided in the global site packages, so that needs to be faked.

The imports look as follows (example): from pear.apple.peach import Fruit

When performing an RPM Build on the package that has these imports it fails on dependency generation, so I need an RPM in the local repo to pretend to provide these so the dependency generation passes.


Solution

  • I was able to solve this issue by replicating every import with an empty file, and using empty __init__.py files at every folder level.

    For example, to resolve from pear.apple.peach import Fruit, I would have needed to install the following file tree in site-packages:

    -> pear
      -> __init__.py
      -> apple
        -> peach.py
    

    The relevant lines of the spec file for the dummy rpm:

    ...
    source:FruitDummy.tar.gz    
    ...
    % install
    mkdir -p $RPM_BUILD_ROOT%{python_sitelib}/pear/apple/
    
    install __init__.py $RPM_BUILD_ROOT%{python_sitelib}/pear/
    install peach.py $RPM_BUILD_ROOT%{python_sitelib}/pear/apple/
    ...
    %files
    %defattr(-,root,root,-)
    %{python_sitelib}/pear/__init__.py*
    %{python_sitelib}/pear/apple/peach.py*
    ...
    

    __init__.py and peach.py were stored in the FruitDummy.tar.gz that was used to build the RPM.