Search code examples
pythonconanpackage-management

Is there a way to add python dependencies to conan package


I am setting up a project using multiple libraries and packages in C/C++ and Python.

I would like to setup a binary repository for C/C++ packages and a python package index server for python packages.

I stumbled upon conan and artefactory to handle inter C/C++ libraries dependencies but I can't find a clear solution to add standard python package dependencies.

For instance, my project 'A' (C/C++) depends on 'B' (C/C++) that contains code generated using 'C' tool (Python).

I would like to set a requirement for 'B' to 'C' as a pip requirement for a specific distribution of my 'C' tool package.

So far, the solutions I see are:

  1. Create a conan package for my 'C'' tool and add requirement in 'B'
  2. Handle manually the 'C' package install in 'B' conanfile.py

I would like to avoid to add a conan package for a python package since python has already a package management system and my packages will be available on a python index server.

I would also avoid to add code to handle python package dependencies.

Does anyone have an idea if this is possible with conan in a simple matter ?

Thank you

Alex


Solution

  • Since a Conan recipe is also a Python script, you could run pip directly from the recipe:

     def system_requirements(self):
        import pip
        if hasattr(pip, "main"):
            pip.main(["install", "colorama"])
        else:
            from pip._internal import main
            main(['install', "colorama"])
    

    System requirements is the best place, because is related to a required package that is not a Conan package. If you have some condition to be added based on distro, you can use distro_info too.

    Take a look here in the documentation, to get more information about.

    Regards!