From ce7888293c518e274da60e41defd4aed57f602be Mon Sep 17 00:00:00 2001 From: Alex Lowe Date: Tue, 2 Apr 2024 18:01:17 -0400 Subject: [PATCH 1/2] experimental: allow choosing a lp instance --- snapcraft/providers.py | 1 + snapcraft/remote/launchpad.py | 3 ++- snapcraft_legacy/cli/remote.py | 1 + snapcraft_legacy/internal/remote_build/_launchpad.py | 7 ++++--- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/snapcraft/providers.py b/snapcraft/providers.py index 19c7c7f196..d6acc25a4f 100644 --- a/snapcraft/providers.py +++ b/snapcraft/providers.py @@ -39,6 +39,7 @@ ) SNAPCRAFT_BASE_TO_PROVIDER_BASE = { + "core": bases.BuilddBaseAlias.XENIAL, "core18": bases.BuilddBaseAlias.BIONIC, "core20": bases.BuilddBaseAlias.FOCAL, "core22": bases.BuilddBaseAlias.JAMMY, diff --git a/snapcraft/remote/launchpad.py b/snapcraft/remote/launchpad.py index f16c3f3638..7907bbe82d 100644 --- a/snapcraft/remote/launchpad.py +++ b/snapcraft/remote/launchpad.py @@ -19,6 +19,7 @@ import gzip import logging +import os import shutil import time from datetime import datetime, timedelta, timezone @@ -266,7 +267,7 @@ def _login(self) -> Launchpad: try: return Launchpad.login_with( f"{self._app_name} remote-build", - "production", + os.getenv("CRAFT_LAUNCHPAD_INSTANCE", "production"), self._cache_dir, credentials_file=str(self._credentials), version="devel", diff --git a/snapcraft_legacy/cli/remote.py b/snapcraft_legacy/cli/remote.py index 4c5b492e47..ad85bceeea 100644 --- a/snapcraft_legacy/cli/remote.py +++ b/snapcraft_legacy/cli/remote.py @@ -119,6 +119,7 @@ def remote_build( snapcraft remote-build --status snapcraft remote-build --status --build-id snapcraft-my-snap-b98a6bd3 """ + echo.warning("legacy") project = get_project() if build_for: diff --git a/snapcraft_legacy/internal/remote_build/_launchpad.py b/snapcraft_legacy/internal/remote_build/_launchpad.py index c042fb7c48..86b80ca285 100644 --- a/snapcraft_legacy/internal/remote_build/_launchpad.py +++ b/snapcraft_legacy/internal/remote_build/_launchpad.py @@ -254,7 +254,7 @@ def login(self) -> Launchpad: try: return Launchpad.login_with( "snapcraft remote-build {}".format(snapcraft_legacy.__version__), - "production", + os.getenv("CRAFT_LAUNCHPAD_INSTANCE", "production"), self._cache_dir, credentials_file=self._credentials, version="devel", @@ -266,10 +266,11 @@ def get_git_repo_path(self) -> str: return f"~{self._lp_user}/+git/{self._lp_name}" def get_git_https_url(self, token: Optional[str] = None) -> str: + lp_domain = self._lp._root_uri.host[4:] if token: - return f"https://{self._lp_user}:{token}@git.launchpad.net/~{self._lp_user}/+git/{self._lp_name}/" + return f"https://{self._lp_user}:{token}@git.{lp_domain}/~{self._lp_user}/+git/{self._lp_name}/" else: - return f"https://{self._lp_user}@git.launchpad.net/~{self._lp_user}/+git/{self._lp_name}/" + return f"https://{self._lp_user}@git.{lp_domain}/~{self._lp_user}/+git/{self._lp_name}/" def _create_git_repository(self, force=False) -> Entry: """Create git repository.""" From 0e2dd829377e814770e290fc3ecdcc9f4109f814 Mon Sep 17 00:00:00 2001 From: Alex Lowe Date: Wed, 3 Apr 2024 10:53:10 -0400 Subject: [PATCH 2/2] fix: lp location --- snapcraft/remote/launchpad.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/snapcraft/remote/launchpad.py b/snapcraft/remote/launchpad.py index 7907bbe82d..ea654422a8 100644 --- a/snapcraft/remote/launchpad.py +++ b/snapcraft/remote/launchpad.py @@ -281,16 +281,11 @@ def get_git_repo_path(self) -> str: def get_git_https_url(self, token: Optional[str] = None) -> str: """Get url for launchpad repository.""" + lp_domain = self._lp._root_uri.host[4:] if token: - return ( - f"https://{self._lp_user}:{token}@git.launchpad.net/" - f"~{self._lp_user}/+git/{self._lp_name}/" - ) - - return ( - f"https://{self._lp_user}@git.launchpad.net/" - f"~{self._lp_user}/+git/{self._lp_name}/" - ) + return f"https://{self._lp_user}:{token}@git.{lp_domain}/~{self._lp_user}/+git/{self._lp_name}/" + else: + return f"https://{self._lp_user}@git.{lp_domain}/~{self._lp_user}/+git/{self._lp_name}/" def _create_git_repository(self, force=False) -> Entry: """Create git repository."""