Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions conan/cli/commands/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from conan.cli.command import conan_command, OnceArgument, conan_subcommand

from conan.cli import make_abs_path
from conan.cli.args import common_graph_args, validate_common_graph_args
from conan.cli.args import common_graph_args, validate_common_graph_args, \
add_common_install_arguments, add_lockfile_args
from conan.cli.printers.graph import print_graph_packages, print_graph_basic
from conan.errors import ConanException
from conan.api.model import RecipeReference
Expand Down Expand Up @@ -239,20 +240,38 @@ def lock_upgrade_config(conan_api, parser, subparser, *args):
"""
(Experimental) Upgrade config requires in a lockfile
"""
common_graph_args(subparser)
# This is similar to common_graph_args(subparser) but without the name/version args
subparser.add_argument("path", nargs="?", help="Path to a conanconfig.yml file",
default=None)
add_common_install_arguments(subparser)
subparser.add_argument("--requires", action="append",
help='Directly provide requires instead of a conanfile')
subparser.add_argument("--tool-requires", action='append',
help='Directly provide tool-requires instead of a conanfile')
add_lockfile_args(subparser)

subparser.add_argument('--update-config-requires', action="append",
help='Update config-requires from lockfile')
args = parser.parse_args(*args)
validate_common_graph_args(args)

# This is a bit repeated from validate_common_graph_args() but without name/version args
if args.path and (args.requires or args.tool_requires):
raise ConanException("--requires and --tool-requires arguments are incompatible with "
f"[path] '{args.path}' argument")

if not args.requires and not args.tool_requires and args.path is None:
args.path = "."

# graph build-order command does not define a build-require argument
if not args.path and getattr(args, "build_require", False):
raise ConanException("--build-require should only be used with <path> argument")

if not args.update_config_requires:
raise ConanException("At least one --update-config-requires should be specified")

cwd = os.getcwd()
path = conan_api.local.get_conanfile_path(args.path, cwd, py=None) if args.path else None
remotes = conan_api.remotes.list(args.remote) if not args.no_remote else []
lockfile = conan_api.lockfile.get_lockfile(lockfile=args.lockfile, conanfile_path=path,
cwd=cwd, partial=True)
lockfile = conan_api.lockfile.get_lockfile(lockfile=args.lockfile, cwd=cwd, partial=True)
if lockfile is None:
raise ConanException("No lockfile specified and default conan.lock not found")
profile_host, profile_build = conan_api.profiles.get_profiles_from_args(args)
Expand Down
5 changes: 5 additions & 0 deletions test/integration/lockfile/test_user_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,3 +499,8 @@ def _check_cache(refs):
_check_cache(["config/1.0"])
c.run("config install-pkg . --lockfile=conan.lock")
_check_cache(["config/2.0"])

def test_config_upgrade_conanfile(self):
c = TestClient(light=True)
c.run("lock upgrade-config -h")
assert "Path to a conanconfig.yml file" in c.out
Loading