Skip to content

Commit dbf7dca

Browse files
committed
Drop the preview-only lint rule, gate the pre-commit hook too, tolerate a BOM in the Claude config
- pyproject.toml: remove PLW1514 and lint.preview. Preview mode also changes stable rules on ruff upgrades (0.15.x flags a load-bearing `import mcp` as a fixable F401), which costs more than an incomplete edit-time check buys; the EncodingWarning gate is the enforcement. - .pre-commit-config.yaml: run the README snippet check with the same -X warn_default_encoding -W error::EncodingWarning flags as CI. - mcp install: read claude_desktop_config.json as utf-8-sig so a BOM written by Windows tooling doesn't make a valid config unreadable; the rewrite stays plain UTF-8. The existing test seeds a BOM.
1 parent f72016f commit dbf7dca

5 files changed

Lines changed: 6 additions & 11 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ repos:
5656
pass_filenames: false
5757
- id: readme-snippets
5858
name: Check README snippets are up to date
59-
entry: uv run --frozen python scripts/update_readme_snippets.py --check
59+
entry: uv run --frozen python -X warn_default_encoding -W error::EncodingWarning scripts/update_readme_snippets.py --check
6060
language: system
6161
files: ^(README\.md|docs_src/.*\.py|scripts/update_readme_snippets\.py)$
6262
pass_filenames: false

AGENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
tests that re-import a module).
4949
- Always pass `encoding=` (normally `"utf-8"`) to text-mode `open()`,
5050
`Path.read_text()`/`write_text()`, `tempfile` and `subprocess` text pipes: the
51-
default is the process locale, not UTF-8. CI enforces this via
52-
`PYTHONWARNDEFAULTENCODING=1` (PEP 597) under pytest's `error` filter, plus ruff `PLW1514`.
51+
default is the process locale, not UTF-8. CI enforces this by running pytest with
52+
`PYTHONWARNDEFAULTENCODING=1` (PEP 597), which makes any omission an error under the `error` filter.
5353

5454
## Testing
5555

pyproject.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,6 @@ line-length = 120
195195
target-version = "py310"
196196

197197
[tool.ruff.lint]
198-
# lint.preview is required to select PLW1514 (text I/O without encoding=); it also opts the stable rules into their
199-
# preview behaviours and fixes. explicit-preview-rules only stops the prefixes below pulling in other preview rules.
200-
preview = true
201-
explicit-preview-rules = true
202-
extend-select = ["PLW1514"]
203198
select = [
204199
"C4", # flake8-comprehensions
205200
"C90", # mccabe

src/mcp/cli/claude.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def update_claude_config(
103103
return False
104104

105105
try:
106-
config = json.loads(config_file.read_text(encoding="utf-8"))
106+
config = json.loads(config_file.read_text(encoding="utf-8-sig"))
107107
if "mcpServers" not in config:
108108
config["mcpServers"] = {}
109109

tests/cli/test_claude.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ def test_existing_env_vars_preserved_without_new(config_dir: Path):
141141

142142

143143
def test_other_servers_preserved(config_dir: Path):
144-
"""Installing a new server must not clobber existing entries, non-ASCII text included (the file is UTF-8)."""
144+
"""Installing a new server must not clobber existing entries, non-ASCII text included (UTF-8, BOM tolerated)."""
145145
other = {"command": "C:\\Users\\张伟\\uv.exe", "env": {"CITY": "Zürich"}}
146146
config_file = config_dir / "claude_desktop_config.json"
147-
config_file.write_text(json.dumps({"mcpServers": {"文件": other}}, ensure_ascii=False), encoding="utf-8")
147+
config_file.write_text(json.dumps({"mcpServers": {"文件": other}}, ensure_ascii=False), encoding="utf-8-sig")
148148

149149
assert update_claude_config(file_spec="s.py:app", server_name="s")
150150

0 commit comments

Comments
 (0)