Skip to content

Commit b93737a

Browse files
lengauCopilotjames-garner-canonicalbepriCopilot
authored
feat(charmlibs): warn of deprecation on all charmlibs commands (#2691)
Warns about the deprecation of charmhub-hosted charmlibs in all charmlibs-related commands. --------- Signed-off-by: Alex Lowe <alex.lowe@canonical.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: James Garner <james.garner@canonical.com> Co-authored-by: Imani Pelton <imani.pelton@canonical.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 3fcdf8a commit b93737a

3 files changed

Lines changed: 62 additions & 2 deletions

File tree

charmcraft/application/commands/store.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ class _ResourceType(typing.NamedTuple):
7676
getattr(attenuations, x) for x in dir(attenuations) if x.isupper()
7777
}
7878
BUNDLE_REGISTRATION_REMOVAL_URL = "https://discourse.charmhub.io/t/15344"
79+
CHARMLIBS_DEPRECATION_WARNING = (
80+
"WARNING: Charmhub-hosted charm libraries are deprecated. "
81+
"Go to https://ubu.link/charmhub-libraries-deprecation for more information."
82+
)
83+
84+
85+
def _emit_charmlibs_deprecation_warning() -> None:
86+
emit.progress(CHARMLIBS_DEPRECATION_WARNING, permanent=True)
7987

8088

8189
class LoginCommand(CharmcraftCommand):
@@ -1255,6 +1263,7 @@ def fill_parser(self, parser):
12551263

12561264
def run(self, parsed_args):
12571265
"""Run the command."""
1266+
_emit_charmlibs_deprecation_warning()
12581267
lib_name = parsed_args.name
12591268
valid_all_chars = set(string.ascii_lowercase + string.digits + "_")
12601269
valid_first_char = string.ascii_lowercase
@@ -1349,6 +1358,7 @@ def fill_parser(self, parser):
13491358

13501359
def run(self, parsed_args):
13511360
"""Run the command."""
1361+
_emit_charmlibs_deprecation_warning()
13521362
charm_name = (
13531363
self._services.get("project").get().name or utils.get_name_from_yaml()
13541364
)
@@ -1515,6 +1525,7 @@ def fill_parser(self, parser):
15151525

15161526
def run(self, parsed_args: argparse.Namespace) -> None:
15171527
"""Run the command."""
1528+
_emit_charmlibs_deprecation_warning()
15181529
if parsed_args.library:
15191530
local_libs_data = [utils.get_lib_info(full_name=parsed_args.library)]
15201531
else:
@@ -1666,6 +1677,7 @@ class FetchLibs(CharmcraftCommand):
16661677

16671678
def run(self, parsed_args: argparse.Namespace) -> None:
16681679
"""Fetch libraries."""
1680+
_emit_charmlibs_deprecation_warning()
16691681
store = cast("StoreService", self._services.get("store"))
16701682
project = cast("CharmcraftProject", self._services.get("project").get())
16711683
charm_libs = project.charm_libs
@@ -1774,6 +1786,7 @@ def fill_parser(self, parser):
17741786

17751787
def run(self, parsed_args):
17761788
"""Run the command."""
1789+
_emit_charmlibs_deprecation_warning()
17771790
if parsed_args.name:
17781791
charm_name = parsed_args.name
17791792
else:

tests/integration/commands/test_store_commands.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828

2929
from charmcraft import errors, utils
3030
from charmcraft.application.commands import FetchLibCommand
31-
from charmcraft.application.commands.store import CreateTrack
31+
from charmcraft.application.commands.store import (
32+
CHARMLIBS_DEPRECATION_WARNING,
33+
CreateTrack,
34+
)
3235
from tests import factory
3336

3437
OPERATOR_LIBS_LINUX_APT_ID = "7c3dbc9c2ad44a47bd6fcb25caa270e5"
@@ -52,6 +55,7 @@ def test_fetchlib_simple_downloaded(
5255
)
5356
FetchLibCommand(config).run(args)
5457

58+
emitter.assert_progress(CHARMLIBS_DEPRECATION_WARNING, permanent=True)
5559
assert saved_file.exists()
5660

5761
message = emitter.interactions[-1].args[1]

tests/unit/commands/test_store.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
from charmcraft.application.commands import SetResourceArchitecturesCommand
3636
from charmcraft.application.commands import store as store_commands
3737
from charmcraft.application.commands.store import (
38+
CHARMLIBS_DEPRECATION_WARNING,
39+
CreateLibCommand,
3840
FetchLibs,
41+
ListLibCommand,
3942
LoginCommand,
4043
PublishLibCommand,
4144
)
@@ -162,7 +165,7 @@ def test_publish_lib_error(monkeypatch, new_path: pathlib.Path) -> None:
162165
)
163166

164167

165-
def test_publish_lib_same_is_noop(monkeypatch, new_path: pathlib.Path) -> None:
168+
def test_publish_lib_same_is_noop(monkeypatch, new_path: pathlib.Path, emitter) -> None:
166169
# Publishing the same version of a library with the same hash should not result
167170
# in an error return.
168171
mock_service_factory = mock.Mock(spec=craft_application.ServiceFactory)
@@ -197,6 +200,44 @@ def test_publish_lib_same_is_noop(monkeypatch, new_path: pathlib.Path) -> None:
197200
== 0
198201
)
199202

203+
emitter.assert_progress(CHARMLIBS_DEPRECATION_WARNING, permanent=True)
204+
205+
206+
def test_create_lib_warns_deprecation(
207+
monkeypatch, new_path: pathlib.Path, emitter, service_factory
208+
) -> None:
209+
mock_store = mock.Mock()
210+
mock_store.return_value.create_library_id.return_value = "lib-id"
211+
monkeypatch.setattr(store_commands, "Store", mock_store)
212+
mock_template = mock.Mock()
213+
mock_template.render.return_value = "LIBAPI = 0\nLIBID = 'lib-id'\nLIBPATCH = 1\n"
214+
mock_environment = mock.Mock()
215+
mock_environment.get_template.return_value = mock_template
216+
monkeypatch.setattr(
217+
store_commands.utils,
218+
"get_templates_environment",
219+
mock.Mock(return_value=mock_environment),
220+
)
221+
222+
cmd = CreateLibCommand({"app": APP_METADATA, "services": service_factory})
223+
224+
cmd.run(argparse.Namespace(name="my_lib", format=False))
225+
226+
emitter.assert_progress(CHARMLIBS_DEPRECATION_WARNING, permanent=True)
227+
228+
229+
def test_list_lib_warns_deprecation(monkeypatch, emitter, service_factory) -> None:
230+
mock_store = mock.Mock()
231+
mock_store.return_value.get_libraries_tips.return_value = {}
232+
monkeypatch.setattr(store_commands, "Store", mock_store)
233+
234+
cmd = ListLibCommand({"app": APP_METADATA, "services": service_factory})
235+
236+
cmd.run(argparse.Namespace(name="test-charm", format=False))
237+
238+
emitter.assert_progress(CHARMLIBS_DEPRECATION_WARNING, permanent=True)
239+
emitter.assert_message("No libraries found for charm test-charm.")
240+
200241

201242
@pytest.mark.parametrize(
202243
("updates", "expected"),
@@ -233,6 +274,7 @@ def test_fetch_libs_no_charm_libs(
233274
with pytest.raises(errors.LibraryError) as exc_info:
234275
fetch_libs.run(argparse.Namespace())
235276

277+
emitter.assert_progress(CHARMLIBS_DEPRECATION_WARNING, permanent=True)
236278
assert exc_info.value.resolution == "Add a 'charm-libs' section to charmcraft.yaml."
237279

238280

@@ -366,6 +408,7 @@ def test_fetch_libs_success(
366408

367409
fetch_libs.run(argparse.Namespace())
368410

411+
emitter.assert_progress(CHARMLIBS_DEPRECATION_WARNING, permanent=True)
369412
emitter.assert_progress("Getting library metadata from charmhub")
370413
emitter.assert_message("Downloaded 1 charm libraries.")
371414

0 commit comments

Comments
 (0)