Skip to content

Commit 231b22f

Browse files
committed
Replace black/isort/flake8 with ruff for linting and formatting
- Update GitHub workflow to use ruff instead of separate tools - Add ruff configuration to pyproject.toml with extended rule set - Apply ruff formatting to existing code - Add .claude, .vscode, demo/ to .gitignore - Update type annotations to modern Python syntax
1 parent 5e0c49a commit 231b22f

File tree

6 files changed

+56
-24
lines changed

6 files changed

+56
-24
lines changed

.github/workflows/tests.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,11 @@ jobs:
2929
3030
- name: Run linting
3131
run: |
32-
# Install linting tools
33-
pip install flake8 black isort
34-
# Check formatting
35-
black --check --diff .
36-
# Check import sorting
37-
isort --check-only --diff .
38-
# Run flake8
39-
flake8 jupyter_server_mcp tests
32+
# Install ruff
33+
pip install ruff
34+
# Check linting and formatting
35+
ruff check jupyter_server_mcp tests
36+
ruff format --check jupyter_server_mcp tests
4037
4138
- name: Run unit tests
4239
run: |

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Byte-compiled / optimized / DLL files
2+
.claude
3+
.vscode
4+
demo/
25
__pycache__/
36
*.py[codz]
47
*$py.class

jupyter_server_mcp/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""Jupyter Server MCP Extension with configurable tools."""
22

3-
from typing import Any, Dict, List
3+
from typing import Any
44

55
from .extension import MCPExtensionApp
66

77
__version__ = "0.1.0"
88

99

10-
def _jupyter_server_extension_points() -> List[Dict[str, Any]]:
10+
def _jupyter_server_extension_points() -> list[dict[str, Any]]:
1111
# pragma: no cover
1212
return [
1313
{

pyproject.toml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ test = [
3333
"pytest-tornasync>=0.6.0",
3434
"pytest-mock>=3.10.0"
3535
]
36+
dev = [
37+
"ruff>=0.1.0"
38+
]
3639
full = [
3740
"jupyterlab-commands-toolkit",
3841
"jupyter_ai_tools>=0.2.0"
@@ -48,4 +51,41 @@ jupyter_server_mcp = "jupyter_server_mcp.extension:MCPExtensionApp"
4851
path = "jupyter_server_mcp/__init__.py"
4952

5053
[tool.hatch.build.targets.wheel.shared-data]
51-
"jupyter-config" = "etc/jupyter"
54+
"jupyter-config" = "etc/jupyter"
55+
56+
[tool.ruff]
57+
line-length = 88
58+
target-version = "py310"
59+
60+
[tool.ruff.lint]
61+
extend-select = [
62+
"B", # flake8-bugbear
63+
"I", # isort
64+
"ARG", # flake8-unused-arguments
65+
"C4", # flake8-comprehensions
66+
"EM", # flake8-errmsg
67+
"ICN", # flake8-import-conventions
68+
"ISC", # flake8-implicit-str-concat
69+
"PGH", # pygrep-hooks
70+
"PIE", # flake8-pie
71+
"PL", # pylint
72+
"PT", # flake8-pytest-style
73+
"PTH", # flake8-use-pathlib
74+
"RET", # flake8-return
75+
"RUF", # Ruff-specific
76+
"SIM", # flake8-simplify
77+
"T20", # flake8-print
78+
"UP", # pyupgrade
79+
"YTT", # flake8-2020
80+
"EXE", # flake8-executable
81+
]
82+
ignore = [
83+
"PLR", # Design related pylint codes
84+
"ISC001", # Conflicts with formatter
85+
]
86+
87+
[tool.ruff.format]
88+
docstring-code-format = true
89+
90+
[tool.ruff.lint.per-file-ignores]
91+
"tests/**" = ["T20"]

tests/conftest.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pathlib import Path
66

77
import pytest
8+
from tornado.web import Application
89

910
from jupyter_server_mcp.extension import MCPExtensionApp
1011
from jupyter_server_mcp.mcp_server import MCPServer
@@ -36,7 +37,6 @@ def mcp_extension():
3637
@pytest.fixture
3738
def mock_serverapp():
3839
"""Create a mock Jupyter Server app for testing."""
39-
from tornado.web import Application
4040

4141
class MockServerApp:
4242
def __init__(self):
@@ -59,19 +59,15 @@ def warning(self, msg):
5959
@pytest.fixture
6060
def mcp_server_simple():
6161
"""Create a simple MCP server for testing."""
62-
return MCPServer(
63-
port=3097, log_level="WARNING"
64-
) # Use WARNING to reduce test noise
62+
return MCPServer(port=3097, log_level="WARNING") # Use WARNING to reduce test noise
6563

6664

6765
# Pytest configuration
6866
def pytest_configure(config):
6967
"""Configure pytest with custom markers."""
7068
config.addinivalue_line("markers", "asyncio: mark test as async")
7169
config.addinivalue_line("markers", "slow: mark test as slow running")
72-
config.addinivalue_line(
73-
"markers", "integration: mark test as integration test"
74-
)
70+
config.addinivalue_line("markers", "integration: mark test as integration test")
7571

7672

7773
# Auto-use asyncio for async tests

tests/test_extension.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,8 @@ def test_load_function_from_string_invalid_module(self):
227227
"""Test loading functions from non-existent modules."""
228228
extension = MCPExtensionApp()
229229

230-
with pytest.raises(
231-
ImportError, match="Could not import module"
232-
):
233-
extension._load_function_from_string(
234-
"nonexistent_module:some_func"
235-
)
230+
with pytest.raises(ImportError, match="Could not import module"):
231+
extension._load_function_from_string("nonexistent_module:some_func")
236232

237233
def test_load_function_from_string_invalid_function(self):
238234
"""Test loading non-existent functions from valid modules."""

0 commit comments

Comments
 (0)