diff --git a/cloudsmith_cli/cli/tests/commands/test_credential_helper_install.py b/cloudsmith_cli/cli/tests/commands/test_credential_helper_install.py index bc14fabd..fd1c0a0f 100644 --- a/cloudsmith_cli/cli/tests/commands/test_credential_helper_install.py +++ b/cloudsmith_cli/cli/tests/commands/test_credential_helper_install.py @@ -810,7 +810,7 @@ def _fake_list(*_a, **_kw): ] with patch( - "cloudsmith_cli.credential_helpers.custom_domains.list_custom_domains", + "cloudsmith_cli.core.api.orgs.list_custom_domains", _fake_list, ): result = get_custom_domains( diff --git a/cloudsmith_cli/cli/tests/test_startup_imports.py b/cloudsmith_cli/cli/tests/test_startup_imports.py index 9cd997ea..3eb1dcaf 100644 --- a/cloudsmith_cli/cli/tests/test_startup_imports.py +++ b/cloudsmith_cli/cli/tests/test_startup_imports.py @@ -12,10 +12,10 @@ HEAVY_PREFIXES = ("mcp", "httpx", "cloudsmith_api", "requests") -def modules_loaded_by_cli_import(): +def modules_loaded_by_import(module_name="cloudsmith_cli.cli.commands.main"): code = ( "import json, sys\n" - "import cloudsmith_cli.cli.commands.main\n" + f"import {module_name}\n" "print(json.dumps(sorted(sys.modules)))\n" ) result = subprocess.run( @@ -27,14 +27,16 @@ def modules_loaded_by_cli_import(): return json.loads(result.stdout) -def test_cli_import_does_not_load_heavy_modules(): - modules = modules_loaded_by_cli_import() - heavy = [ +def heavy_modules_in(modules): + return [ name for name in modules if any(name == p or name.startswith(p + ".") for p in HEAVY_PREFIXES) ] - assert heavy == [] + + +def test_cli_import_does_not_load_heavy_modules(): + assert heavy_modules_in(modules_loaded_by_import()) == [] def test_cli_import_does_not_load_command_modules(): @@ -42,7 +44,12 @@ def test_cli_import_does_not_load_command_modules(): allowed = {package + "main", package + "registry"} loaded = [ name - for name in modules_loaded_by_cli_import() + for name in modules_loaded_by_import() if name.startswith(package) and name not in allowed ] assert loaded == [] + + +def test_docker_helper_import_does_not_load_heavy_modules(): + modules = modules_loaded_by_import("cloudsmith_cli.credential_helpers.docker") + assert heavy_modules_in(modules) == [] diff --git a/cloudsmith_cli/credential_helpers/custom_domains.py b/cloudsmith_cli/credential_helpers/custom_domains.py index cec75ee6..1cdb53bc 100644 --- a/cloudsmith_cli/credential_helpers/custom_domains.py +++ b/cloudsmith_cli/credential_helpers/custom_domains.py @@ -19,9 +19,6 @@ from pathlib import Path from ..cli.config import get_default_config_path -from ..core.api.exceptions import ApiException -from ..core.api.init import initialise_api -from ..core.api.orgs import list_custom_domains from ..core.cache_utils import atomic_write_json from ..core.credentials.models import CredentialResult from .default_domains import DomainType, domain_type_from_server @@ -305,6 +302,10 @@ def get_custom_domains( logger.debug("Fetching custom domains from API for %s", org) + from ..core.api.exceptions import ApiException + from ..core.api.init import initialise_api + from ..core.api.orgs import list_custom_domains + if configure_api: initialise_api(host=api_host, credential=credential)