Is there a way to add python dependencies to conan package
Asked Answered
L

1

6

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

Lariat answered 2/2, 2019 at 13:3 Comment(0)
K
6

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!

Kingcup answered 7/2, 2019 at 13:3 Comment(1)
Thank you for your answer! It looks like a good solution to me. I had been doing trying to solve python dependencies in a call to pip in configure method which was running everytime a dependent package was installing it. I didn't think of system_requirements.Lariat

© 2022 - 2024 — McMap. All rights reserved.