[question] Install from local recipes index with user/channel
What is your question?
Hi, I have a question regarding the local recipes index and how/if it works together with user/channel:
For background information, we have a convention that we use unmodified packages from the conan-center-index without user/channel (e.g. zlib/1.3.1) but if we modify a package in any way or write it ourselves, we add a user/channel to clarify the source of the package (e.g. zlib/1.3.1@comp/stable).
Next to our (unmodified) conan-center-index fork, we have a small repo for our own/modified packages, which I'd like to make compatible to the new local recipes index feature in Conan 2.2. However, either I missed it or it isn't possible so far to install a package from a local index with adding user/channel. The package always seems to have the short package reference name/version instead.
I tried e.g. using the --allowed-packages */*@comp/stable parameter but it doesn't seem to handle that case.
Not sure how a solution could look like but using part of the --allowed-packages reference or maybe another setting per remote might work. I'd also be happy if it's possible to override user/channel on a per-package basis but it's not necessary.
Have you read the CONTRIBUTING guide?
- [X] I've read the CONTRIBUTING guide
Hi @fschoenm thanks a lot for your question
The reference for conan in the local recipe index will always match whatever the recipes in there have set, so unless you modify the conanfiles to have extra user = "foo" attributes, the recipes you get from the index will not have anything
@RubenRBS Thank you for the quick answer.
I think I tried that (setting user and channel attributes in the conanfile) but I'm pretty sure it didn't work. I can check again tomorrow when I'm back at my computer.
However, that doesn't seem like the best solution. I'd prefer another way to "override" user and channel without modifying the recipe itself.
I think such feature would fall outside our current vision for the feature, but I can check with the team to see what they think, thanks for bringing it up :) (Although I wouldn't hold my breath to get that)
Really? That's too bad.
There was even a recent comment from memsharded that recommends using the user for differentiating packages that are not from ConanCenter. And as far as I can think back it was possible to override user (and channel) from the recipe.
It would be nice if you could find a way to integrate this :)
The reference for conan in the local recipe index will always match whatever the recipes in there have set, so unless you modify the conanfiles to have extra
user = "foo"attributes, the recipes you get from the index will not have anything
Hello @RubenRBS, I tried this by adding user and channel attributes to the conanfile but it didn't have any effect.
Just in case, I have done a unit test to check if there was some functionality missing. This test is working:
def test_export_user_channel(self):
folder = temp_folder()
recipes_folder = os.path.join(folder, "recipes")
zlib_config = textwrap.dedent("""
versions:
"0.1":
folder: all
""")
zlib = textwrap.dedent("""
from conan import ConanFile
class Zlib(ConanFile):
name = "zlib"
user = "myuser"
channel = "mychannel"
""")
conandata_yml = textwrap.dedent("""\
versions:
"0.1":
""")
save_files(recipes_folder,
{"zlib/config.yml": zlib_config,
"zlib/all/conanfile.py": zlib,
"zlib/all/conandata.yml": conandata_yml})
client = TestClient()
client.run(f"remote add local '{folder}'")
client.run("install --requires=zlib/0.1@myuser/mychannel --build=missing")
print(client.out)
assert "zlib/0.1@myuser/mychannel:" in client.out
As a side note, check the recommendation from https://docs.conan.io/2/devops/conancenter/hosting_binaries.html
Do not add user/channel to these packages, it is way simpler to use them as zlib/1.2.13 without user-channel. The user/channel part would be mostly recommended for your own proprietary packages, but not for open source ConanCenter packages.
Changing the user/channel from a conan-center-index fork will also imply having to change all self.requires() with the appropriate user/channel, making the divergence from the upstream repo larger for little value. Keeping the packages without user/channel would be recommended in most cases.
Thanks for the answer @memsharded.
Just in case, I have done a unit test to check if there was some functionality missing.
I used conan list -r local * and it doesn't show the user/channel:
Found 1 pkg/version recipes matching * in local
local
dtoa
dtoa/1.0.0
I can't try to install it right now, though.
Changing the user/channel from a conan-center-index fork will also imply having to change all self.requires() with the appropriate user/channel, making the divergence from the upstream repo larger for little value. Keeping the packages without user/channel would be recommended in most cases.
I knew about that. On the other hand, we've used conan from long before the user/channel became optional so on the one hand, we're kind of used to it, and on the other hand, we only use user/channel for proprietary packages and packages that somehow deviate from the "official" recipe (which is very rare).
I used conan list -r local * and it doesn't show the user/channel:
Ok, I see the issue now.
The local-recipes-index uses just the config.yml files to list the existing versions, so it has no notion of the user/channel part, as that doesn't exist until the package is actually exported/installed. This is done in order to be fast, because otherwise it is necessary to do an export of the recipe and that is much slower. I'll check what is possible.
https://github.com/conan-io/conan/pull/16342 fixed this, it will be in next 2.4