From 6e3d908bd4053583962eca4f3f305ec728fa1587 Mon Sep 17 00:00:00 2001 From: Carlos Zoido Date: Thu, 7 Nov 2024 10:29:54 +0100 Subject: [PATCH] Use center2.conan.io as new default remote and warn about having the old one. (#17284) * add warning * move and add tests --- conan/api/subapi/remotes.py | 4 ++-- conan/cli/cli.py | 15 +++++++++++++ test/integration/command/remote_test.py | 29 ++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/conan/api/subapi/remotes.py b/conan/api/subapi/remotes.py index 77fe0dd3480..1c2c6c47e0b 100644 --- a/conan/api/subapi/remotes.py +++ b/conan/api/subapi/remotes.py @@ -254,7 +254,7 @@ def user_auth(self, remote: Remote, with_user=False): def _load(remotes_file): if not os.path.exists(remotes_file): - remote = Remote(CONAN_CENTER_REMOTE_NAME, "https://center.conan.io", True, False) + remote = Remote(CONAN_CENTER_REMOTE_NAME, "https://center2.conan.io", True, False) _save(remotes_file, [remote]) return [remote] @@ -313,7 +313,7 @@ def _validate_url(url): if url.startswith("https://conan.io/center"): raise ConanException("Wrong ConanCenter remote URL. You are adding the web " "https://conan.io/center the correct remote API is " - "https://center.conan.io") + "https://center2.conan.io") address = urlparse(url) if not all([address.scheme, address.netloc]): out.warning(f"The URL '{url}' is invalid. It must contain scheme and hostname.") diff --git a/conan/cli/cli.py b/conan/cli/cli.py index 68769f6e562..8209d715dc2 100644 --- a/conan/cli/cli.py +++ b/conan/cli/cli.py @@ -190,6 +190,7 @@ def run(self, *args): try: command.run(self._conan_api, args[0][1:]) + _warn_frozen_center(self._conan_api) except Exception as e: # must be a local-import to get updated value if ConanOutput.level_allowed(LEVEL_TRACE): @@ -245,6 +246,20 @@ def _warn_python_version(): ConanOutput().warning("*" * 80, warn_tag="deprecated") +def _warn_frozen_center(conan_api): + remotes = conan_api.remotes.list() + for r in remotes: + if r.url == "https://center.conan.io": + ConanOutput().warning( + "The remote 'https://center.conan.io' is now frozen and has been replaced by 'https://center2.conan.io'. \n" + "Starting from Conan 2.9.2, the default remote is 'center2.conan.io'. \n" + "It is recommended to update to the new remote using the following command:\n" + f"'conan remote update {r.name} --url=\"https://center2.conan.io\"'", + warn_tag="deprecated" + ) + break + + def main(args): """ main entry point of the conan application, using a Command to parse parameters diff --git a/test/integration/command/remote_test.py b/test/integration/command/remote_test.py index d9b484f7e96..8a5b5b53ed3 100644 --- a/test/integration/command/remote_test.py +++ b/test/integration/command/remote_test.py @@ -337,11 +337,34 @@ def test_add_wrong_conancenter(): c = TestClient(light=True) c.run("remote add whatever https://conan.io/center", assert_error=True) assert "Wrong ConanCenter remote URL. You are adding the web https://conan.io/center" in c.out - assert "the correct remote API is https://center.conan.io" in c.out - c.run("remote add conancenter https://center.conan.io") + assert "the correct remote API is https://center2.conan.io" in c.out + c.run("remote add conancenter https://center2.conan.io") c.run("remote update conancenter --url=https://conan.io/center", assert_error=True) assert "Wrong ConanCenter remote URL. You are adding the web https://conan.io/center" in c.out - assert "the correct remote API is https://center.conan.io" in c.out + assert "the correct remote API is https://center2.conan.io" in c.out + + +def test_using_frozen_center(): + """ If the legacy center.conan.io is in the remote list warn about it. + """ + c = TestClient(light=True) + c.run("remote add whatever https://center.conan.io") + assert "The remote 'https://center.conan.io' is now frozen and has been replaced by 'https://center2.conan.io'." in c.out + assert 'conan remote update whatever --url="https://center2.conan.io"' in c.out + + c.run("remote list") + assert "The remote 'https://center.conan.io' is now frozen and has been replaced by 'https://center2.conan.io'." in c.out + + c.run("remote remove whatever") + + c.run("remote add conancenter https://center2.conan.io") + assert "The remote 'https://center.conan.io' is now frozen and has been replaced by 'https://center2.conan.io'." not in c.out + + c.run("remote list") + assert "The remote 'https://center.conan.io' is now frozen and has been replaced by 'https://center2.conan.io'." not in c.out + + c.run("remote update conancenter --url=https://center.conan.io") + assert "The remote 'https://center.conan.io' is now frozen and has been replaced by 'https://center2.conan.io'." in c.out def test_wrong_remotes_json_file():