Conan: Reference local conanfile.py files?

Created on 22 Jul 2017  路  3Comments  路  Source: conan-io/conan

It'd be great if I could just "call" local recipe files to manage packages. So instead of providing a recipe path like OpenCV/1.0.6@user/stable, I want provide a local path that points to a conanfile.py and use it as a dependency to my project. I think the current solution is to run and configure a local server seems like an overkill.

The idea is to be able to distribute a few conanfile.py with my source code, so that people won't have to configure conan in a special way just to build. I can't seem to find information on how to do this or if it's even possible.

Thanks in advance, and sorry for the noob question!

question

Most helpful comment

Ah, it was a classic case of RTFM. I kept skimming over the relevant path. 'export' was the command I was looking for. If anyone else is interested, here's an example of how I got it to work.

import os

from conans import ConanFile


class HelloConan(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    generators = "cmake"

    def include_package(self, name, version, recipe=None):
        recipes_path = os.path.join(self.conanfile_directory, "conan_recipes")
        if recipe is None:
            recipe = name + ".py"

        self.run("conan export user/stable --file %s" % recipe, cwd=recipes_path)
        self.requires(("%s/%s@user/stable" % (name, version)))

    def requirements(self):
        self.include_package("Hello", "1.0.0")
        self.include_package("World", "2.0.0", "world.py")

The recipe files are under a subdirectory named conan_recipes. I don't suppose there's an easier way to do this, but this is good enough for me.

All 3 comments

Ah, it was a classic case of RTFM. I kept skimming over the relevant path. 'export' was the command I was looking for. If anyone else is interested, here's an example of how I got it to work.

import os

from conans import ConanFile


class HelloConan(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    generators = "cmake"

    def include_package(self, name, version, recipe=None):
        recipes_path = os.path.join(self.conanfile_directory, "conan_recipes")
        if recipe is None:
            recipe = name + ".py"

        self.run("conan export user/stable --file %s" % recipe, cwd=recipes_path)
        self.requires(("%s/%s@user/stable" % (name, version)))

    def requirements(self):
        self.include_package("Hello", "1.0.0")
        self.include_package("World", "2.0.0", "world.py")

The recipe files are under a subdirectory named conan_recipes. I don't suppose there's an easier way to do this, but this is good enough for me.

Hi!
Good that you discovered RTFM, lol

While your approach might work in some cases, I think it can have problems in the long term or for larger dependency graphs, can confuse users because of the nested conan execution, etc.

I would certainly decouple it, and provide a script (python, bat, sh) in the root folder that would basically do:

cd Hello && conan create user/stable
cd World && conan create user/stable
cd Bye && conan create user/stable

This would be much more maintainable and easy to debug in case of problems. It will also fail fast, if the first package fails to create (create actually not only export, but build the binary package)

Please take into account, that if your code is OSS, you don't need to setup a server, you can use Bintray for free to distribute your recipes and/or packages.

Please tell me what you think. Thanks!

Seems nothing to do here, but please comment or re-open otherwise. Thanks!

Was this page helpful?
0 / 5 - 0 ratings