Skip to content

Commit

Permalink
lock upgrade feature
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded authored and perseoGI committed Jan 15, 2025
1 parent be3c03e commit 6aacfd1
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
41 changes: 41 additions & 0 deletions conan/cli/commands/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,44 @@ def lock_update(conan_api, parser, subparser, *args):
lockfile.update(requires=args.requires, build_requires=args.build_requires,
python_requires=args.python_requires, config_requires=args.config_requires)
conan_api.lockfile.save_lockfile(lockfile, args.lockfile_out)




@conan_subcommand()
def lock_upgrade(conan_api, parser, subparser, *args):
"""
Update requires, build-requires or python-requires from an existing lockfile.
References that matches the arguments package names will be replaced by the arguments.
References can be supplied with and without revisions like "--requires=pkg/version",
"""
subparser.add_argument('--requires', action="append", help='Update references to lockfile.')
subparser.add_argument('--build-requires', action="append",
help='Update build-requires from lockfile')
subparser.add_argument('--python-requires', action="append",
help='Update python-requires from lockfile')
subparser.add_argument('--config-requires', action="append",
help='Update config-requires from lockfile')
common_graph_args(subparser)
subparser.add_argument("--build-require", action='store_true', default=False,
help='Whether the provided reference is a build-require')
args = parser.parse_args(*args)

# parameter validation
validate_common_graph_args(args)

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 []
overrides = eval(args.lockfile_overrides) if args.lockfile_overrides else None
lockfile = conan_api.lockfile.get_lockfile(lockfile=args.lockfile, conanfile_path=path,
cwd=cwd, partial=True, overrides=overrides)
profile_host, profile_build = conan_api.profiles.get_profiles_from_args(args)


args = parser.parse_args(*args)

lockfile = conan_api.lockfile.get_lockfile(lockfile=args.lockfile, partial=True)
lockfile.update(requires=args.requires, build_requires=args.build_requires,
python_requires=args.python_requires, config_requires=args.config_requires)
conan_api.lockfile.save_lockfile(lockfile, args.lockfile_out)
33 changes: 33 additions & 0 deletions test/integration/lockfile/test_user_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,36 @@ def test_lock_update(self, kind, old, new):
lock = c.load("conan.lock")
assert old not in lock
assert new in lock


class TestLockUpgrade:
@pytest.mark.parametrize("kind, old, new", [
("requires", "math/*", "math/1.1"),
("build-requires", "cmake/1.0", "cmake/1.1"),
("python-requires", "mytool/1.0", "mytool/1.1"),
])
def test_lock_update(self, kind, old, new):
c = TestClient(light=True)
lock = textwrap.dedent("""\
{
"version": "0.5",
"requires": [
"math/1.0#85d927a4a067a531b1a9c7619522c015%1702683583.3411012",
"math/1.0#12345%1702683584.3411012",
"engine/1.0#fd2b006646a54397c16a1478ac4111ac%1702683583.3544693"
],
"build_requires": [
"cmake/1.0#85d927a4a067a531b1a9c7619522c015%1702683583.3411012",
"ninja/1.0#fd2b006646a54397c16a1478ac4111ac%1702683583.3544693"
],
"python_requires": [
"mytool/1.0#85d927a4a067a531b1a9c7619522c015%1702683583.3411012",
"othertool/1.0#fd2b006646a54397c16a1478ac4111ac%1702683583.3544693"
]
}
""")
c.save({"conan.lock": lock})
c.run(f"lock upgrade --requires={old}")
lock = c.load("conan.lock")
assert old not in lock
assert new in lock

0 comments on commit 6aacfd1

Please sign in to comment.