From 834cb7f9d096ecd596d28721fe2ea11cba831d0f Mon Sep 17 00:00:00 2001 From: memsharded Date: Mon, 27 May 2024 00:02:40 +0200 Subject: [PATCH] proposal for user/channel in local-recipes-index --- .../client/rest_client_local_recipe_index.py | 13 +++++++++- .../remote/test_local_recipes_index.py | 24 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/conans/client/rest_client_local_recipe_index.py b/conans/client/rest_client_local_recipe_index.py index 36d3b516eec..041406d5021 100644 --- a/conans/client/rest_client_local_recipe_index.py +++ b/conans/client/rest_client_local_recipe_index.py @@ -10,6 +10,7 @@ from conan.api.output import ConanOutput from conan.internal.cache.home_paths import HomePaths from conans.client.cmd.export import cmd_export +from conans.client.loader import ConanFileLoader from conans.errors import ConanException, PackageNotFoundException, RecipeNotFoundException from conans.model.conf import ConfDefinition from conans.model.recipe_ref import RecipeReference @@ -190,6 +191,8 @@ def get_recipes_references(self, pattern): recipes.sort() ret = [] excluded = set() + + loader = ConanFileLoader(None) for r in recipes: if not fnmatch(r, name_pattern): continue @@ -207,10 +210,18 @@ def get_recipes_references(self, pattern): # This check can be removed after compatibility with 2.0 conanfile = os.path.join(recipes_dir, r, subfolder, "conanfile.py") conanfile_content = load(conanfile) + if "from conans" in conanfile_content or "import conans" in conanfile_content: excluded.add(r) continue - ret.append(RecipeReference.loads(ref)) + ref = RecipeReference.loads(ref) + try: + recipe = loader.load_basic(conanfile) + ref.user = recipe.user + ref.channel = recipe.channel + except Exception as e: + ConanOutput().warning(f"Couldn't load recipe {conanfile}: {e}") + ret.append(ref) if excluded: ConanOutput().warning(f"Excluding recipes not Conan 2.0 ready: {', '.join(excluded)}") return ret diff --git a/test/integration/remote/test_local_recipes_index.py b/test/integration/remote/test_local_recipes_index.py index e96dddce3d0..2876832b65c 100644 --- a/test/integration/remote/test_local_recipes_index.py +++ b/test/integration/remote/test_local_recipes_index.py @@ -270,6 +270,30 @@ def source(self): assert "zlib/0.1: Copied 1 file: patch1" in client.out assert "zlib/0.1: Apply patch (file): patches/patch1" in client.out + 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 = GenConanfile("zlib").with_class_attribute("user='myuser'")\ + .with_class_attribute("channel='mychannel'") + conandata_yml = textwrap.dedent("""\ + versions: + "0.1": + """) + save_files(recipes_folder, {"zlib/config.yml": zlib_config, + "zlib/all/conanfile.py": str(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") + assert "zlib/0.1@myuser/mychannel:" in client.out + client.run("list * -r=local") + assert "zlib/0.1@myuser/mychannel" in client.out + class TestRestrictedOperations: def test_upload(self):