Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal for user/channel in local-recipes-index #16342

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion conans/client/rest_client_local_recipe_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
24 changes: 24 additions & 0 deletions test/integration/remote/test_local_recipes_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down