Skip to content

Commit

Permalink
Deprecate the --package arguments in conan copy and conan download.
Browse files Browse the repository at this point in the history
  • Loading branch information
DodoMomo committed Jun 5, 2019
1 parent 47d4586 commit 9acacf5
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 21 deletions.
52 changes: 44 additions & 8 deletions conans/client/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,25 @@ def download(self, *args):

args = parser.parse_args(*args)

try:
pref = PackageReference.loads(args.reference, validate=True)
except ConanException:
reference = args.reference
package_id_list = args.package

if package_id_list:
self._user_io.out.warn("Usage of `--package` argument is deprecated."
" Use a full reference instead: "
"`conan download [...] {}:{}`".format(reference, package_id_list[0]))
else:
reference = pref.ref.full_repr()
package_id_list = [pref.id]
if args.package:
raise ConanException("Use a full package reference (preferred) or the `--package`"
" command argument, but not both.")

self._warn_python2()
return self._conan.download(reference=args.reference, package=args.package,
return self._conan.download(reference=reference, package_list=package_id_list,
remote_name=args.remote, recipe=args.recipe)

def install(self, *args):
Expand Down Expand Up @@ -998,13 +1015,33 @@ def copy(self, *args):
help='Override destination packages and the package recipe')
args = parser.parse_args(*args)

if args.all and args.package:
raise ConanException("Cannot specify both --all and --package")
try:
pref = PackageReference.loads(args.reference, validate=True)
except ConanException:
reference = args.reference
package_id_list = args.package

if package_id_list:
self._user_io.out.warn("Usage of `--package` argument is deprecated."
" Use a full reference instead: "
"`conan download [...] {}:{}`".format(reference, package_id_list[0]))

if args.all and package_id_list:
raise ConanException("Cannot specify both --all and --package")
else:
reference = pref.ref.full_repr()
package_id_list = [pref.id]
if args.package:
raise ConanException("Use a full package reference (preferred) or the `--package`"
" command argument, but not both.")

if args.all:
raise ConanException("'--all' argument cannot be used together with full reference")

self._warn_python2()

return self._conan.copy(reference=args.reference, user_channel=args.user_channel,
force=args.force, packages=args.package or args.all)
return self._conan.copy(reference=reference, user_channel=args.user_channel,
force=args.force, packages=package_id_list or args.all)

def user(self, *args):
"""
Expand Down Expand Up @@ -1245,7 +1282,6 @@ def upload(self, *args):
if args.query:
raise ConanException("'--query' argument cannot be used together with full reference")


if args.force and args.no_overwrite:
raise ConanException("'--no-overwrite' argument cannot be used together with '--force'")
if args.force and args.skip_upload:
Expand Down Expand Up @@ -1490,8 +1526,6 @@ def get(self, *args):

try:
pref = PackageReference.loads(args.reference, validate=True)
reference = pref.ref.full_repr()
package_id = pref.id
except ConanException:
reference = args.reference
package_id = args.package
Expand All @@ -1501,6 +1535,8 @@ def get(self, *args):
" Use a full reference instead: "
"`conan get [...] {}:{}`".format(reference, package_id))
else:
reference = pref.ref.full_repr()
package_id = pref.id
if args.package:
raise ConanException("Use a full package reference (preferred) or the `--package`"
" command argument, but not both.")
Expand Down
15 changes: 7 additions & 8 deletions conans/client/conan_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,24 +421,23 @@ def export_pkg(self, conanfile_path, name, channel, source_folder=None, build_fo
raise

@api_method
def download(self, reference, remote_name=None, package=None, recipe=False):
# FIXME: The "package" parameter name is very bad, it is a list of package_ids
if package and recipe:
raise ConanException("recipe parameter cannot be used together with package")
def download(self, reference, remote_name=None, package_list=None, recipe=False):
if package_list and recipe:
raise ConanException("recipe parameter cannot be used together with package_list")
# Install packages without settings (fixed ids or all)
ref = ConanFileReference.loads(reference)
if check_valid_ref(ref, allow_pattern=False):
if package and ref.revision is None:
for package_id in package:
if package_list and ref.revision is None:
for package_id in package_list:
if "#" in package_id:
raise ConanException("It is needed to specify the recipe revision if you "
"specify a package revision")
"specify a package_list revision")
remotes = self._cache.registry.load_remotes()
remotes.select(remote_name)
self._python_requires.enable_remotes(remotes=remotes)
remote = remotes.get_remote(remote_name)
recorder = ActionRecorder()
download(ref, package, remote, recipe, self._remote_manager,
download(ref, package_list, remote, recipe, self._remote_manager,
self._cache, self._user_io.out, recorder, self._loader,
self._hook_manager, remotes=remotes)
else:
Expand Down
4 changes: 2 additions & 2 deletions conans/test/functional/command/copy_packages_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class Pkg(ConanFile):
packages = os.listdir(pkgdir)
self.assertEqual(len(packages), 3)

# Copy just one
client.run("copy Hello0/0.1@lasote/stable pepe/stable -p %s" % packages[0])
# Copy just one with --package argument
client.run("copy Hello0/0.1@lasote/stable:%s pepe/stable" % packages[0])
pkgdir = client.cache.package_layout(ConanFileReference.loads("Hello0/0.1@pepe/stable")).packages()
packages = os.listdir(pkgdir)
self.assertEqual(len(packages), 1)
Expand Down
40 changes: 37 additions & 3 deletions conans/test/functional/command/download_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from collections import OrderedDict

from conans.model.ref import ConanFileReference
from conans.test.utils.tools import TestClient, TestServer
from conans.test.utils.tools import TestClient, TestServer, NO_SETTINGS_PACKAGE_ID
from conans.util.files import load


Expand Down Expand Up @@ -104,7 +104,7 @@ class Pkg(ConanFile):

client.run("download pkg/0.1@lasote/stable")
# Check 'No remote binary packages found' warning
self.assertTrue("WARN: No remote binary packages found in remote", client.out)
self.assertIn("WARN: No remote binary packages found in remote", client.out)
# Check at least conanfile.py is downloaded
self.assertTrue(os.path.exists(client.cache.package_layout(ref).conanfile()))

Expand Down Expand Up @@ -155,11 +155,45 @@ class Pkg(ConanFile):
client.run("upload pkg/0.1@lasote/stable")
client.run("remove pkg/0.1@lasote/stable -f")

client.run("download pkg/0.1@lasote/stable -p=wrong", assert_error=True)
client.run("download pkg/0.1@lasote/stable:wrong", assert_error=True)
self.assertIn("ERROR: Binary package not found: 'pkg/0.1@lasote/stable:wrong'",
client.out)

def test_download_pattern(self):
client = TestClient()
client.run("download pkg/*@user/channel", assert_error=True)
self.assertIn("Provide a valid full reference without wildcards", client.out)

def download_full_reference_test(self):
server = TestServer()
servers = {"default": server}

client = TestClient(servers=servers, users={"default": [("lasote", "mypass")]})
conanfile = """from conans import ConanFile
class Pkg(ConanFile):
name = "pkg"
version = "0.1"
"""

client.save({"conanfile.py": conanfile})
client.run("create . lasote/stable")

ref = ConanFileReference.loads("pkg/0.1@lasote/stable")
package_layout = client.cache.package_layout(ref)
self.assertTrue(os.path.exists(package_layout.conanfile()))

package_folder = os.path.join(package_layout.packages(),
os.listdir(package_layout.packages())[0])

client.run("upload pkg/0.1@lasote/stable --all")
client.run("remove pkg/0.1@lasote/stable -f")
self.assertFalse(os.path.exists(package_layout.export()))

client.run("download pkg/0.1@lasote/stable:{}".format(NO_SETTINGS_PACKAGE_ID))

# Check not 'No remote binary packages found' warning
self.assertNotIn("WARN: No remote binary packages found in remote", client.out)
# Check at conanfile.py is downloaded
self.assertTrue(os.path.exists(package_layout.conanfile()))
# Check package folder created
self.assertTrue(os.path.exists(package_folder))

0 comments on commit 9acacf5

Please sign in to comment.