Pavel Zagalsky
Pavel Zagalsky

Reputation: 1636

Add module from RPM as a requirement

So I have this project with many dependencies that are being installed from pip and are documented in requirements.txt I need to add another dependency now that doesn't exist on pip and I have it as an RPM in some address. What is the most Pythonic way to install it as a requirement? Thanks! The code will run on RHEL and Fedora

Upvotes: 13

Views: 1748

Answers (3)

Rcynic
Rcynic

Reputation: 392

Since we're discussing options - I'll throw in one that hasn't been discussed.

Docker containers.

You can install a base image with the OS you want, and then the Docker file will install all the dependencies you need. It can also pip install the requirements.

This keeps the server clean of any installations it doesn't need, and versioning is easy since you'll just have a new container with new code/dependencies without overlapping with the old version.

Upvotes: 0

Alex Smith
Alex Smith

Reputation: 1535

In this case, the Pythonic thing to do would be to simply fail if a dependency cannot be met. It's okay, and your users will appreciate a helpful error if they haven't satisfied a prerequisite for the installation. Consider the numerous Python packages out there with C library dependencies in order to be built and installed correctly. In your project, still declare all of your Python dependencies in your "setup.py" and "requirements.txt" files, but there's nothing in the Python packaging toolchain which will install an RPM for you (nor should it!), so just stop there and let the install fail if an RPM wasn't installed.

Aside from that, you may want to consider packaging your Python application itself as an RPM. You have RPM dependencies, and your target platform is Fedora/RHEL. By packaging your application as an RPM, you can declare dependencies on other RPMs which automates installation of those required packages. Worry about being Pythonic within the build phase of your RPM, and use RPM magic to do the rest.

I recommend against the use of configuration management tools (Puppet, Ansible, etc.), as they will overly complicate your build process. Those tools are great for their intended uses, but here it would be like using a cannon to swat a fly.

Upvotes: 7

dusty
dusty

Reputation: 573

The conventional way to manage such dependencies is using a Configuration Management system, such as SaltStack — I personally recommend it, since it is written in Python and can be extended with Python modules. Other choices include Puppet, Chef or Ansible.

Using a configuration management system, you declare the packages, config files and services to install and configure on target operation system. Then, you run the agent and it does all the heavy lifting: copying files, installing RPM packages and enabling/disabling services. The advantages are huge: your OS configuration is described as a code, you always get predictable results and save time on future installations.

Please note, that using CM introduces quite steep learning curve. However, when you wrap your head around it, you are never going back to doing OS configuration by hand.

The simpler approach could be wrapping the necessary commands in a bash script, called something like install_dependencies.sh. One is supposed to run this script as a part of application deployment, so it is a good idea to document the process somewhere.

Upvotes: 5

Related Questions