mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-23 05:54:19 +02:00
Add --python, --project, and --with-requirements options to CLI commands (#1190)
This commit is contained in:
parent
1b953820b3
commit
a65bfd10be
16 changed files with 1140 additions and 40 deletions
|
|
@ -90,6 +90,94 @@ class TestMainCLI:
|
|||
]
|
||||
assert cmd == expected
|
||||
|
||||
def test_build_uv_command_with_python_version(self):
|
||||
"""Test building uv command with Python version."""
|
||||
cmd = _build_uv_command("server.py", python_version="3.11")
|
||||
expected = [
|
||||
"uv",
|
||||
"run",
|
||||
"--python",
|
||||
"3.11",
|
||||
"--with",
|
||||
"fastmcp",
|
||||
"fastmcp",
|
||||
"run",
|
||||
"server.py",
|
||||
]
|
||||
assert cmd == expected
|
||||
|
||||
def test_build_uv_command_with_project(self):
|
||||
"""Test building uv command with project directory."""
|
||||
project_path = Path("/path/to/project")
|
||||
cmd = _build_uv_command("server.py", project=project_path)
|
||||
expected = [
|
||||
"uv",
|
||||
"run",
|
||||
"--project",
|
||||
str(project_path),
|
||||
"--with",
|
||||
"fastmcp",
|
||||
"fastmcp",
|
||||
"run",
|
||||
"server.py",
|
||||
]
|
||||
assert cmd == expected
|
||||
|
||||
def test_build_uv_command_with_requirements(self):
|
||||
"""Test building uv command with requirements file."""
|
||||
req_path = Path("requirements.txt")
|
||||
cmd = _build_uv_command("server.py", with_requirements=req_path)
|
||||
expected = [
|
||||
"uv",
|
||||
"run",
|
||||
"--with",
|
||||
"fastmcp",
|
||||
"--with-requirements",
|
||||
"requirements.txt",
|
||||
"fastmcp",
|
||||
"run",
|
||||
"server.py",
|
||||
]
|
||||
assert cmd == expected
|
||||
|
||||
def test_build_uv_command_with_all_options(self):
|
||||
"""Test building uv command with all options."""
|
||||
project_path = Path("/my/project")
|
||||
editable_path = Path("/local/pkg")
|
||||
requirements_path = Path("reqs.txt")
|
||||
cmd = _build_uv_command(
|
||||
"server.py",
|
||||
python_version="3.10",
|
||||
project=project_path,
|
||||
with_packages=["pandas", "numpy"],
|
||||
with_requirements=requirements_path,
|
||||
with_editable=editable_path,
|
||||
no_banner=True,
|
||||
)
|
||||
expected = [
|
||||
"uv",
|
||||
"run",
|
||||
"--python",
|
||||
"3.10",
|
||||
"--project",
|
||||
str(project_path),
|
||||
"--with",
|
||||
"fastmcp",
|
||||
"--with-editable",
|
||||
str(editable_path),
|
||||
"--with",
|
||||
"pandas",
|
||||
"--with",
|
||||
"numpy",
|
||||
"--with-requirements",
|
||||
str(requirements_path),
|
||||
"fastmcp",
|
||||
"run",
|
||||
"server.py",
|
||||
"--no-banner",
|
||||
]
|
||||
assert cmd == expected
|
||||
|
||||
|
||||
class TestVersionCommand:
|
||||
"""Test the version command."""
|
||||
|
|
@ -167,6 +255,29 @@ class TestDevCommand:
|
|||
assert bound.arguments["inspector_version"] == "1.0.0"
|
||||
assert bound.arguments["ui_port"] == 3000
|
||||
|
||||
def test_dev_command_parsing_with_new_options(self):
|
||||
"""Test dev command parsing with new uv options."""
|
||||
command, bound, _ = app.parse_args(
|
||||
[
|
||||
"dev",
|
||||
"server.py",
|
||||
"--python",
|
||||
"3.10",
|
||||
"--project",
|
||||
"/workspace",
|
||||
"--with-requirements",
|
||||
"dev-requirements.txt",
|
||||
"--with",
|
||||
"pytest",
|
||||
]
|
||||
)
|
||||
assert command is not None
|
||||
assert bound.arguments["server_spec"] == "server.py"
|
||||
assert bound.arguments["python"] == "3.10"
|
||||
assert bound.arguments["project"] == Path("/workspace")
|
||||
assert bound.arguments["with_requirements"] == Path("dev-requirements.txt")
|
||||
assert bound.arguments["with_packages"] == ["pytest"]
|
||||
|
||||
|
||||
class TestRunCommand:
|
||||
"""Test the run command."""
|
||||
|
|
@ -236,6 +347,32 @@ class TestRunCommand:
|
|||
assert "log_level" not in bound.arguments
|
||||
assert "path" not in bound.arguments
|
||||
|
||||
def test_run_command_parsing_with_new_options(self):
|
||||
"""Test run command parsing with new uv options."""
|
||||
command, bound, _ = app.parse_args(
|
||||
[
|
||||
"run",
|
||||
"server.py",
|
||||
"--python",
|
||||
"3.11",
|
||||
"--with",
|
||||
"pandas",
|
||||
"--with",
|
||||
"numpy",
|
||||
"--project",
|
||||
"/path/to/project",
|
||||
"--with-requirements",
|
||||
"requirements.txt",
|
||||
]
|
||||
)
|
||||
|
||||
assert command is not None
|
||||
assert bound.arguments["server_spec"] == "server.py"
|
||||
assert bound.arguments["python"] == "3.11"
|
||||
assert bound.arguments["with_packages"] == ["pandas", "numpy"]
|
||||
assert bound.arguments["project"] == Path("/path/to/project")
|
||||
assert bound.arguments["with_requirements"] == Path("requirements.txt")
|
||||
|
||||
def test_run_command_transport_aliases(self):
|
||||
"""Test that both 'http' and 'streamable-http' are accepted as valid transport options."""
|
||||
# Test with 'http' transport
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue