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

Upload using pref as the recommended way #5224

Merged
merged 5 commits into from May 29, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 30 additions & 7 deletions conans/client/command.py
Expand Up @@ -83,6 +83,7 @@ def _fill_text(self, text, width, indent):
_QUERY_EXAMPLE = ("os=Windows AND (arch=x86 OR compiler=gcc)")
_PATTERN_EXAMPLE = ("boost/*")
_REFERENCE_EXAMPLE = ("MyPackage/1.2@user/channel")
_PREF_EXAMPLE = ("MyPackage/1.2@user/channel:af7901d8bdfde621d086181aa1c495c25a17b137")

_BUILD_FOLDER_HELP = ("Directory for the build process. Defaulted to the current directory. A "
"relative path to current directory can also be specified")
Expand All @@ -91,7 +92,11 @@ def _fill_text(self, text, width, indent):
_KEEP_SOURCE_HELP = ("Do not remove the source folder in local cache, even if the recipe changed. "
"Use this for testing purposes only")
_PATTERN_OR_REFERENCE_HELP = ("Pattern or package recipe reference, e.g., '%s', "
"'%s'" % (_REFERENCE_EXAMPLE, _PATTERN_EXAMPLE))
"'%s'" % (_PATTERN_EXAMPLE, _REFERENCE_EXAMPLE))
_PATTERN_REF_OR_PREF_HELP = ("Pattern, recipe reference or package reference e.g., '%s', "
"'%s', '%s'" % (_PATTERN_EXAMPLE, _REFERENCE_EXAMPLE, _PREF_EXAMPLE))
_PREF_OR_PREF_HELP = ("Recipe reference or package reference e.g., '%s', "
lasote marked this conversation as resolved.
Show resolved Hide resolved
"'%s'" % (_REFERENCE_EXAMPLE, _PREF_EXAMPLE))
_PATH_HELP = ("Path to a folder containing a conanfile.py or to a recipe file "
"e.g., my_folder/conanfile.py")
_QUERY_HELP = ("Packages query: '%s'. The 'pattern_or_reference' parameter has "
Expand Down Expand Up @@ -1192,9 +1197,10 @@ def upload(self, *args):
parser = argparse.ArgumentParser(description=self.upload.__doc__,
prog="conan upload",
formatter_class=SmartFormatter)
parser.add_argument('pattern_or_reference', help=_PATTERN_OR_REFERENCE_HELP)
parser.add_argument("-p", "--package", default=None, action=OnceArgument,
help='package ID to upload')
parser.add_argument('pattern_or_reference', help=_PATTERN_REF_OR_PREF_HELP)
parser.add_argument("-p", "--package", default=None,
help="Package ID [DEPRECATED: use full reference instead]",
action=OnceArgument)
parser.add_argument('-q', '--query', default=None, action=OnceArgument,
help="Only upload packages matching a specific query. " + _QUERY_HELP)
parser.add_argument("-r", "--remote", action=OnceArgument,
Expand Down Expand Up @@ -1222,7 +1228,24 @@ def upload(self, *args):

args = parser.parse_args(*args)

if args.query and args.package:
try:
jgsogo marked this conversation as resolved.
Show resolved Hide resolved
pref = PackageReference.loads(args.pattern_or_reference, validate=True)
reference = pref.ref.full_repr()
package_id = pref.id
except ConanException:
reference = args.pattern_or_reference
package_id = args.package

if package_id:
lasote marked this conversation as resolved.
Show resolved Hide resolved
self._user_io.out.warn("Usage of `--package` argument is deprecated."
" Use a full reference instead: "
"`conan upload [...] {}:{}`".format(reference, package_id))
else:
if args.package:
raise ConanException("Use a full package reference (preferred) or the `--package`"
lasote marked this conversation as resolved.
Show resolved Hide resolved
" command argument, but not both.")

if args.query and package_id:
raise ConanException("'-q' and '-p' parameters can't be used at the same time")

cwd = os.getcwd()
Expand Down Expand Up @@ -1250,7 +1273,7 @@ def upload(self, *args):
policy = None

try:
info = self._conan.upload(pattern=args.pattern_or_reference, package=args.package,
info = self._conan.upload(pattern=reference, package=package_id,
query=args.query, remote_name=args.remote,
all_packages=args.all, policy=policy,
confirm=args.confirm, retry=args.retry,
Expand Down Expand Up @@ -1453,7 +1476,7 @@ def get(self, *args):
parser = argparse.ArgumentParser(description=self.get.__doc__,
prog="conan get",
formatter_class=SmartFormatter)
parser.add_argument('reference', help='package recipe reference')
parser.add_argument('reference', help=_PREF_OR_PREF_HELP)
parser.add_argument('path',
help='Path to the file or directory. If not specified will get the '
'conanfile if only a reference is specified and a conaninfo.txt '
Expand Down
32 changes: 32 additions & 0 deletions conans/test/functional/command/upload_test.py
Expand Up @@ -115,6 +115,38 @@ def non_existing_package_error_test(self):
client.run("upload Pkg/0.1@user/channel -p hash1", assert_error=True)
self.assertIn("ERROR: Recipe not found: 'Pkg/0.1@user/channel'", client.out)

def deprecated_p_arg_test(self):
client = self._client()
client.save({"conanfile.py": conanfile})
client.run("create . user/testing")
client.run("upload Hello0/1.2.1@user/testing -p {} -c".format(NO_SETTINGS_PACKAGE_ID))
self.assertIn("WARN: Usage of `--package` argument is deprecated. "
"Use a full reference instead: `conan upload [...] "
"Hello0/1.2.1@user/testing:{}`".format(NO_SETTINGS_PACKAGE_ID), client.out)

def upload_with_pref_test(self):
client = self._client()
client.save({"conanfile.py": conanfile})
client.run("create . user/testing")
client.run("upload Hello0/1.2.1@user/testing:{} -c".format(NO_SETTINGS_PACKAGE_ID))
self.assertNotIn("WARN: Usage of `--package` argument is deprecated. "
"Use a full reference instead: `conan upload [...] "
"Hello0/1.2.1@user/testing:{}`".format(NO_SETTINGS_PACKAGE_ID),
client.out)
self.assertIn("Uploading package 1/1: {} to 'default'".format(NO_SETTINGS_PACKAGE_ID),
client.out)

def upload_with_pref_and_p_test(self):
client = self._client()
client.save({"conanfile.py": conanfile})
client.run("create . user/testing")
client.run("upload Hello0/1.2.1@user/testing:{} -c -p {}".format(NO_SETTINGS_PACKAGE_ID,
NO_SETTINGS_PACKAGE_ID),
assert_error=True)

self.assertIn("Use a full package reference (preferred) or the "
"`--package` command argument, but not both.", client.out)

def _client(self):
if not hasattr(self, "_servers"):
servers = {}
Expand Down