Skip to content

Commit 96f7e17

Browse files
committed
Fix lint errors
1 parent 30996b9 commit 96f7e17

5 files changed

Lines changed: 24 additions & 27 deletions

File tree

packages/datacommons-mcp/datacommons_mcp/app.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
SERVER_INSTRUCTION_FILE = "server.md"
3737

3838

39-
40-
4139
class DCApp:
4240
"""Core application wrapper for Data Commons MCP."""
4341

@@ -95,17 +93,20 @@ def _load_instruction(self, filename: str) -> str:
9593
# Fallback to package resources
9694
return read_package_content(DEFAULT_INSTRUCTIONS_PACKAGE, filename)
9795

98-
9996
def register_tool(self, func: Callable[..., Any], instruction_file: str) -> None:
10097
"""Register a tool with instructions loaded from a file.
101-
98+
10299
Args:
103100
func: The tool function to register.
104101
instruction_file: Path to instruction file relative to instructions dir.
105102
"""
106103
description = self._load_instruction(instruction_file)
107104
if not description:
108-
logger.warning("No description found for tool %s from file %s", func.__name__, instruction_file)
105+
logger.warning(
106+
"No description found for tool %s from file %s",
107+
func.__name__,
108+
instruction_file,
109+
)
109110

110111
# Create tool from function and add description
111112
tool = Tool.from_function(func, description=description)

packages/datacommons-mcp/datacommons_mcp/server.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717

1818
import logging
1919

20-
from fastmcp import FastMCP
2120
from starlette.requests import Request
2221
from starlette.responses import JSONResponse
2322

24-
import datacommons_mcp.settings as settings
2523
import datacommons_mcp.tools as tools
2624
from datacommons_mcp.app import app
2725
from datacommons_mcp.version import __version__

packages/datacommons-mcp/datacommons_mcp/utils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def read_external_content(base_path: str, filename: str) -> str | None:
108108
Example:
109109
>>> content = read_external_content("/path/to/instructions", "server.md")
110110
"""
111-
# TODO: Add support for GCS if needed. This is useful for Custom DCs deployed in the cloud.
111+
# TODO(keyurs): Add support for GCS if needed. This is useful for Custom DCs deployed in the cloud.
112112
try:
113113
path = Path(base_path) / filename
114114
if path.exists() and path.is_file():
@@ -146,9 +146,8 @@ def read_package_content(package: str, filename: str) -> str:
146146

147147
if resource.is_file():
148148
return resource.read_text(encoding="utf-8")
149-
else:
150-
logger.warning("Instruction resource %s not found in package", filename)
151-
return ""
149+
logger.warning("Instruction resource %s not found in package", filename)
150+
return ""
152151

153152
except Exception as e:
154153
logger.warning("Failed to load instruction %s: %s", filename, e)

packages/datacommons-mcp/tests/test_app.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@
1818
from unittest.mock import MagicMock, patch
1919

2020
import pytest
21-
2221
from datacommons_mcp.app import DCApp
2322

2423

2524
@pytest.fixture
2625
def mock_settings():
26+
from datacommons_mcp.data_models.settings import BaseDCSettings
27+
2728
with patch("datacommons_mcp.app.settings.get_dc_settings") as mock:
28-
mock.return_value = MagicMock(instructions_dir=None, api_key="test-key")
29+
# Return a real BaseDCSettings object
30+
mock.return_value = BaseDCSettings(api_key="test-key")
2931
yield mock
3032

3133

@@ -44,7 +46,7 @@ def mock_fastmcp():
4446
yield mock
4547

4648

47-
def test_app_initialization_default(mock_settings, mock_client, mock_fastmcp):
49+
def test_app_initialization_default(mock_settings, mock_fastmcp): # noqa: ARG001
4850
"""Test that DCApp initializes with default instructions."""
4951
_ = DCApp()
5052

@@ -56,7 +58,7 @@ def test_app_initialization_default(mock_settings, mock_client, mock_fastmcp):
5658

5759

5860
def test_app_initialization_override(
59-
mock_settings, mock_client, mock_fastmcp, tmp_path, create_test_file
61+
mock_settings, mock_fastmcp, tmp_path, create_test_file
6062
):
6163
"""Test that DCApp loads instructions from DC_INSTRUCTIONS_DIR."""
6264
# Create custom instructions
@@ -74,9 +76,7 @@ def test_app_initialization_override(
7476
assert instructions == "Custom Server Instructions"
7577

7678

77-
def test_load_instruction_tool_override(
78-
mock_settings, mock_client, mock_fastmcp, tmp_path, create_test_file
79-
):
79+
def test_load_instruction_tool_override(mock_settings, tmp_path, create_test_file):
8080
"""Test loading tool instructions with override."""
8181
# Create custom instructions
8282
custom_dir = tmp_path / "instructions"
@@ -90,7 +90,7 @@ def test_load_instruction_tool_override(
9090
assert content == "Custom Tool Instructions"
9191

9292

93-
def test_load_instruction_fallback(mock_settings, mock_client, mock_fastmcp, tmp_path):
93+
def test_load_instruction_fallback(mock_settings, tmp_path):
9494
"""Test that override falls back to default if file likely doesn't exist."""
9595
# Create custom dir but empty
9696
custom_dir = tmp_path / "instructions"
@@ -100,15 +100,13 @@ def test_load_instruction_fallback(mock_settings, mock_client, mock_fastmcp, tmp
100100
mock_settings.return_value.instructions_dir = str(custom_dir)
101101

102102
app = DCApp()
103-
103+
104104
# Should fall back to default package resource (server.md exists in package)
105105
content = app._load_instruction("server.md")
106106
assert "Data Commons" in content
107107

108108

109-
def test_register_tool(
110-
mock_settings, mock_client, mock_fastmcp, tmp_path, create_test_file
111-
):
109+
def test_register_tool(mock_settings, mock_fastmcp, tmp_path, create_test_file):
112110
"""Test tool registration with instruction loading."""
113111
# Create custom instructions
114112
create_test_file("instructions/tools/sample.md", "Sample Tool Description")
@@ -124,7 +122,7 @@ def sample_tool():
124122

125123
# Verify add_tool was called
126124
mock_mcp_instance.add_tool.assert_called_once()
127-
125+
128126
# Verify the description was loaded correctly
129127
tool_arg = mock_mcp_instance.add_tool.call_args[0][0]
130128
assert tool_arg.description == "Sample Tool Description"

packages/datacommons-mcp/tests/test_utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
1516
import pytest
1617
import requests
17-
from unittest.mock import MagicMock, mock_open, patch
1818
from datacommons_client.models.observation import Observation
1919
from datacommons_mcp.data_models.observations import DateRange
2020
from datacommons_mcp.exceptions import APIKeyValidationError, InvalidAPIKeyError
@@ -97,13 +97,14 @@ def test_read_external_content_subdir(self, tmp_path, create_test_file):
9797
def test_read_external_content_missing(self, tmp_path):
9898
assert read_external_content(str(tmp_path), "missing.md") is None
9999

100-
101100
def test_read_package_content_success(self):
102101
# Read actual content from the package
103102
content = read_package_content("datacommons_mcp.instructions", "server.md")
104103
assert "Data Commons" in content
105104

106105
def test_read_package_content_missing(self):
107106
# Read a file that definitely doesn't exist in the package
108-
content = read_package_content("datacommons_mcp.instructions", "non_existent_file.md")
107+
content = read_package_content(
108+
"datacommons_mcp.instructions", "non_existent_file.md"
109+
)
109110
assert content == ""

0 commit comments

Comments
 (0)