Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,65 @@ Once the servers passes the checks, register the new MCP server:

For running or adding tests, as well as contributing to the official repository, see `./tests/README.md`.

### Warning Suppression for Dependencies

Some third-party dependencies (like cclib) may emit warnings during compilation or runtime. Here's how to suppress them:

#### For MCP Server Usage (Compile-time warnings)

Warnings like `SyntaxWarning` occur when Python compiles source files. To suppress them, set the `PYTHONWARNINGS` environment variable in your MCP configuration:

```json
{
"servers": {
"parse-patrol": {
"command": "uv",
"args": ["run", "python", "-m", "parse_patrol"],
"env": {
"PYTHONWARNINGS": "ignore::SyntaxWarning"
}
}
}
}
```

This is already configured in all template files under `templates/`.

#### For Direct Python Usage (Runtime warnings)

For runtime warnings when using parsers as direct dependencies, parse-patrol includes specialized `__init__.py` files in parser modules (e.g., `src/parse_patrol/parsers/cclib/__init__.py`) that automatically suppress known dependency warnings before imports.

If you need additional suppression in your own scripts, use Python's warnings module:

```python
import warnings
warnings.filterwarnings("ignore", category=SyntaxWarning)

from parse_patrol import cclib_parse
```

Alternatively, set the environment variable before running your script:

```bash
export PYTHONWARNINGS="ignore::SyntaxWarning"
python your_script.py
```

#### For pytest (Test suite)

Warning filters are configured in `pyproject.toml`:

```toml
[tool.pytest.ini_options]
filterwarnings = [
"ignore::DeprecationWarning",
"ignore::PendingDeprecationWarning",
"ignore::SyntaxWarning",
]
```

This ensures tests run cleanly without noise from dependency warnings.

## Online Resources

The following links explain the basics of MCP, including the distinction between *tools*, *resources*, and *prompts*. **Make sure to respect these distinctions!**
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ addopts = [
filterwarnings = [
"ignore::DeprecationWarning",
"ignore::PendingDeprecationWarning",
"ignore::SyntaxWarning",
]

[build-system]
Expand Down
6 changes: 3 additions & 3 deletions src/parse_patrol/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ def register_parsers():
module = import_module(config["module"], package=__package__)

# Register tools
for tool_name in getattr(config, "tools", []):
for tool_name in config.get("tools", []):
tool_func = getattr(module, tool_name)
mcp.tool()(tool_func)

# Register resources
for resource_name in getattr(config, "resources", []):
for resource_name in config.get("resources", []):
resource_func = getattr(module, resource_name)
mcp.resource(f"{RESOURCE_PREFIX}{resource_name.replace('_', '/')}")(resource_func)

# Register prompts
for prompt_name in getattr(config, "prompts", []):
for prompt_name in config.get("prompts", []):
prompt_func = getattr(module, prompt_name)
mcp.prompt()(prompt_func)

Expand Down
15 changes: 15 additions & 0 deletions src/parse_patrol/parsers/cclib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
CCLib parser module initialization.
Suppresses SyntaxWarning from cclib before module imports.
"""

import warnings
import importlib

# Suppress SyntaxWarning from cclib's invalid escape sequences
warnings.filterwarnings("ignore", category=SyntaxWarning, module="cclib")

# Explicitly import the external cclib package to avoid self-import
external_cclib = importlib.import_module("cclib")

__all__ = ["external_cclib"]
6 changes: 3 additions & 3 deletions src/parse_patrol/parsers/cclib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This module provides sync functions that can be imported and used directly.
"""

import cclib
from . import external_cclib
Comment thread
ndaelman-hu marked this conversation as resolved.
Outdated
from typing import Optional, Dict, List, Any
from pydantic import BaseModel, Field # pyright: ignore[reportMissingImports]

Expand Down Expand Up @@ -93,7 +93,7 @@ class Config:
zpve: Optional[float] = Field(None, description="Zero-point vibrational energy correction (hartree/particle, float)")


def ccdata_to_model(ccdata: cclib.parser.data.ccData, filepath: str = None) -> CCDataModel: # type: ignore
def ccdata_to_model(ccdata: external_cclib.parser.data.ccData, filepath: str = None) -> CCDataModel: # type: ignore
"""Convert ccData object to CCDataModel (Pydantic) format.

Args:
Expand Down Expand Up @@ -151,7 +151,7 @@ def cclib_parse(filepath: str) -> CCDataModel:
FileNotFoundError: If file cannot be opened
ValueError: If file cannot be parsed
"""
filereader = cclib.io.ccopen(filepath) # type: ignore
filereader = external_cclib.io.ccopen(filepath) # type: ignore
if filereader is None:
raise FileNotFoundError(f"File not found or unsupported format: {filepath}")

Expand Down
3 changes: 2 additions & 1 deletion templates/claude-desktop-mcp.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"args": ["run", "python", "-m", "parse_patrol"],
"cwd": "/path/to/parse-patrol",
"env": {
"PYTHONPATH": "/path/to/parse-patrol/src"
"PYTHONPATH": "/path/to/parse-patrol/src",
"PYTHONWARNINGS": "ignore::SyntaxWarning"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion templates/neovim-mcp.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"args": ["run", "python", "-m", "parse_patrol"],
"cwd": "/path/to/parse-patrol",
"env": {
"PYTHONPATH": "/path/to/parse-patrol/src"
"PYTHONPATH": "/path/to/parse-patrol/src",
"PYTHONWARNINGS": "ignore::SyntaxWarning"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion templates/vscode-mcp.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"args": ["run", "python", "-m", "parse_patrol"],
"cwd": "${workspaceFolder}",
"env": {
"PYTHONPATH": "${workspaceFolder}/src"
"PYTHONPATH": "${workspaceFolder}/src",
"PYTHONWARNINGS": "ignore::SyntaxWarning"
}
}
}
Expand Down