Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cloudsmith_cli/cli/commands/mcp.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
"""Main command/entrypoint."""

from __future__ import annotations

import json
import os
import shutil
import sys
import tempfile
from pathlib import Path
from typing import TYPE_CHECKING

import click
import json5

from ...core.mcp import server
from ...core.mcp.data import OpenAPITool
if TYPE_CHECKING:
from ...core.mcp import server
from ...core.mcp.data import OpenAPITool

from .. import command, decorators, utils
from .main import main

Expand Down
3 changes: 2 additions & 1 deletion cloudsmith_cli/cli/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
disabled_detectors_from_env,
registered_detectors,
)
from ..core.mcp import server
from ..core.rest import create_requests_session as _create_session
from . import config, utils

Expand Down Expand Up @@ -627,6 +626,8 @@ def initialise_mcp(f):
@click.pass_context
@functools.wraps(f)
def wrapper(ctx, *args, **kwargs):
from ..core.mcp import server

opts = kwargs.get("opts")

all_tools = kwargs.pop("all_tools")
Expand Down
37 changes: 37 additions & 0 deletions cloudsmith_cli/cli/tests/test_startup_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Tests that a CLI import does not load heavy dependencies.

The credential helpers run the CLI on every package-manager request, so
module-level imports are the dominant startup cost. These tests import the
CLI in a subprocess and inspect ``sys.modules``.
"""

import json
import subprocess
import sys

HEAVY_PREFIXES = ("mcp", "httpx")


def modules_loaded_by_cli_import():
code = (
"import json, sys\n"
"import cloudsmith_cli.cli.commands\n"
"print(json.dumps(sorted(sys.modules)))\n"
)
result = subprocess.run(
[sys.executable, "-c", code],
capture_output=True,
text=True,
)
assert result.returncode == 0, result.stderr
return json.loads(result.stdout)


def test_cli_import_does_not_load_heavy_modules():
modules = modules_loaded_by_cli_import()
heavy = [
name
for name in modules
if any(name == p or name.startswith(p + ".") for p in HEAVY_PREFIXES)
]
assert heavy == []
Loading