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

Fix several issues with download command and revisions #6138

Merged
merged 13 commits into from Nov 29, 2019
8 changes: 6 additions & 2 deletions conans/client/command.py
Expand Up @@ -403,8 +403,12 @@ def download(self, *args):
else:
reference = repr(pref.ref)
if pref.ref.user is None:
reference += "@"
packages_list = [pref.id]
if pref.ref.revision:
reference = "%s/%s@#%s" % (pref.ref.name, pref.ref.version, pref.ref.revision)
else:
reference += "@"
pkgref = "{}#{}".format(pref.id, pref.revision) if pref.revision else pref.id
packages_list = [pkgref]
if args.package:
raise ConanException("Use a full package reference (preferred) or the `--package`"
" command argument, but not both.")
Expand Down
3 changes: 3 additions & 0 deletions conans/client/conan_api.py
Expand Up @@ -430,6 +430,9 @@ def download(self, reference, remote_name=None, packages=None, recipe=False):
# Install packages without settings (fixed ids or all)
if check_valid_ref(reference):
ref = ConanFileReference.loads(reference)
if ref.revision and not self.app.config.revisions_enabled:
raise ConanException("Revisions not enabled in the client, specify a "
"reference without revision")
if packages and ref.revision is None:
for package_id in packages:
if "#" in package_id:
Expand Down
73 changes: 73 additions & 0 deletions conans/test/functional/command/download_test.py
Expand Up @@ -5,6 +5,7 @@
from conans.model.ref import ConanFileReference
from conans.test.utils.tools import (TestClient, TestServer, NO_SETTINGS_PACKAGE_ID, TurboTestClient,
GenConanfile)
from conans.util.env_reader import get_env
from conans.util.files import load


Expand Down Expand Up @@ -220,3 +221,75 @@ def no_user_channel_test(self):
client.run("download pkg/1.0@")
self.assertIn("pkg/1.0: Downloading pkg/1.0:%s" % NO_SETTINGS_PACKAGE_ID, client.out)
self.assertIn("pkg/1.0: Package installed %s" % NO_SETTINGS_PACKAGE_ID, client.out)

@unittest.skipIf(get_env("TESTING_REVISIONS_ENABLED", False), "No sense with revs")
def download_revs_disabled_with_rrev_test(self):
# https://github.com/conan-io/conan/issues/6106
client = TestClient(revisions_enabled=False)
client.run("download pkg/1.0@user/channel#fakerevision", assert_error=True)
self.assertIn(
"ERROR: Revisions not enabled in the client, specify a reference without revision",
client.out)

@unittest.skipUnless(get_env("TESTING_REVISIONS_ENABLED", False), "Only revisions")
def download_revs_enabled_with_fake_rrev_test(self):
client = TestClient(default_server_user=True, revisions_enabled=True)
client.save({"conanfile.py": GenConanfile()})
client.run("create . pkg/1.0@user/channel")
client.run("upload * --all --confirm")
client.run("remove * -f")
client.run("download pkg/1.0@user/channel#fakerevision", assert_error=True)
czoido marked this conversation as resolved.
Show resolved Hide resolved
self.assertIn("ERROR: Recipe not found: 'pkg/1.0@user/channel'", client.out)

@unittest.skipUnless(get_env("TESTING_REVISIONS_ENABLED", False), "Only revisions")
def download_revs_enabled_with_rrev_test(self):
ref = ConanFileReference.loads("pkg/1.0@user/channel")
czoido marked this conversation as resolved.
Show resolved Hide resolved
client = TurboTestClient(default_server_user=True, revisions_enabled=True)
pref = client.create(ref, conanfile=GenConanfile())
client.run("upload pkg/1.0@user/channel --all --confirm")
# create new revision from recipe
client.create(ref, conanfile=GenConanfile().with_build_msg("new revision"))
client.run("upload pkg/1.0@user/channel --all --confirm")
client.run("remove * -f")
client.run("download pkg/1.0@user/channel#{}".format(pref.ref.revision))
self.assertIn("pkg/1.0@user/channel: Package installed {}".format(pref.id), client.out)
search_result = client.search("pkg/1.0@user/channel --revisions")[0]
self.assertIn(pref.ref.revision, search_result["revision"])

@unittest.skipUnless(get_env("TESTING_REVISIONS_ENABLED", False), "Only revisions")
def download_revs_enabled_with_rrev_no_user_channel_test(self):
ref = ConanFileReference.loads("pkg/1.0@")
czoido marked this conversation as resolved.
Show resolved Hide resolved
servers = {"default": TestServer([("*/*@*/*", "*")], [("*/*@*/*", "*")],
users={"user": "password"})}
client = TurboTestClient(servers=servers, revisions_enabled=True,
memsharded marked this conversation as resolved.
Show resolved Hide resolved
users={"default": [("user", "password")]})
pref = client.create(ref, conanfile=GenConanfile())
client.run("upload pkg/1.0@ --all --confirm")
# create new revision from recipe
client.create(ref, conanfile=GenConanfile().with_build_msg("new revision"))
client.run("upload pkg/1.0@ --all --confirm")
client.run("remove * -f")
client.run("download pkg/1.0@#{}".format(pref.ref.revision))
self.assertIn("pkg/1.0: Package installed {}".format(pref.id), client.out)
search_result = client.search("pkg/1.0@ --revisions")[0]
self.assertIn(pref.ref.revision, search_result["revision"])

@unittest.skipUnless(get_env("TESTING_REVISIONS_ENABLED", False), "Only revisions")
def download_revs_enabled_with_prev_test(self):
# https://github.com/conan-io/conan/issues/6106
ref = ConanFileReference.loads("pkg/1.0@user/channel")
client = TurboTestClient(default_server_user=True, revisions_enabled=True)
pref = client.create(ref, conanfile=GenConanfile())
client.run("upload pkg/1.0@user/channel --all --confirm")
client.create(ref, conanfile=GenConanfile().with_build_msg("new revision"))
client.run("upload pkg/1.0@user/channel --all --confirm")
client.run("remove * -f")
client.run("download pkg/1.0@user/channel#{}:{}#{}".format(pref.ref.revision,
pref.id,
pref.revision))
self.assertIn("pkg/1.0@user/channel: Package installed {}".format(pref.id), client.out)
search_result = client.search("pkg/1.0@user/channel --revisions")[0]
self.assertIn(pref.ref.revision, search_result["revision"])
search_result = client.search(
"pkg/1.0@user/channel#{}:{} --revisions".format(pref.ref.revision, pref.id))[0]
self.assertIn(pref.revision, search_result["revision"])
3 changes: 2 additions & 1 deletion conans/test/utils/tools.py
Expand Up @@ -1236,7 +1236,8 @@ def export(self, ref, conanfile=GenConanfile(), args=None, assert_error=False):
def create(self, ref, conanfile=GenConanfile(), args=None, assert_error=False):
if conanfile:
self.save({"conanfile.py": conanfile})
self.run("create . {} {} --json {}".format(ref.full_str(),
full_str = "{}@".format(ref.full_str()) if not ref.user else ref.full_str()
self.run("create . {} {} --json {}".format(full_str,
args or "", self.tmp_json_name),
assert_error=assert_error)
rrev = self.cache.package_layout(ref).recipe_revision()
Expand Down