Skip to content

Commit 3e9882f

Browse files
authored
Merge pull request #201 from IBM/pyrefly-check
Add pyrefly static type checker to Makefile and dev dependencies
2 parents 0132505 + 3074b62 commit 3e9882f

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mcp-servers/go/fast-time-server/Dockerfile
12
Dockerfile
23
Dockerfile.*
34
Containerfile.*

Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ images:
337337
# help: fawltydeps - Detect undeclared / unused deps
338338
# help: wily - Maintainability report
339339
# help: pyre - Static analysis with Facebook Pyre
340+
# help: pyrefly - Static analysis with Facebook Pyrefly
340341
# help: depend - List dependencies in ≈requirements format
341342
# help: snakeviz - Profile & visualise with snakeviz
342343
# help: pstats - Generate PNG call-graph from cProfile stats
@@ -348,7 +349,7 @@ images:
348349

349350
# List of individual lint targets; lint loops over these
350351
LINTERS := isort flake8 pylint mypy bandit pydocstyle pycodestyle pre-commit \
351-
ruff pyright radon pyroma pyre spellcheck importchecker \
352+
ruff pyright radon pyroma pyrefly spellcheck importchecker \
352353
pytype check-manifest markdownlint
353354

354355
.PHONY: lint $(LINTERS) black fawltydeps wily depend snakeviz pstats \
@@ -439,6 +440,9 @@ wily: ## 📈 Maintainability report
439440
pyre: ## 🧠 Facebook Pyre analysis
440441
@$(VENV_DIR)/bin/pyre
441442

443+
pyrefly: ## 🧠 Facebook Pyrefly analysis (faster, rust)
444+
@$(VENV_DIR)/bin/pyrefly check mcpgateway
445+
442446
depend: ## 📦 List dependencies
443447
pdm list --freeze
444448

@@ -654,8 +658,9 @@ sonar-deps-podman:
654658
python3 -m pip install --quiet podman-compose
655659

656660
sonar-deps-docker:
657-
@echo "🔧 Ensuring docker-compose is available …"
658-
@which docker-compose >/dev/null || python3 -m pip install --quiet docker-compose
661+
@echo "🔧 Ensuring $(COMPOSE_CMD) is available …"
662+
@command -v $(firstword $(COMPOSE_CMD)) >/dev/null || \
663+
python3 -m pip install --quiet docker-compose
659664

660665
## ─────────── Run SonarQube server (compose) ────────────────────────────
661666
sonar-up-podman:
@@ -665,10 +670,11 @@ sonar-up-podman:
665670
@sleep 30 && podman ps | grep sonarqube || echo "⚠️ Server may still be starting."
666671

667672
sonar-up-docker:
668-
@echo "🚀 Starting SonarQube (v$(SONARQUBE_VERSION)) with docker-compose"
673+
@echo "🚀 Starting SonarQube (v$(SONARQUBE_VERSION)) with $(COMPOSE_CMD)"
669674
SONARQUBE_VERSION=$(SONARQUBE_VERSION) \
670-
docker-compose -f podman-compose-sonarqube.yaml up -d
671-
@sleep 30 && docker ps | grep sonarqube || echo "⚠️ Server may still be starting."
675+
$(COMPOSE_CMD) -f podman-compose-sonarqube.yaml up -d
676+
@sleep 30 && $(COMPOSE_CMD) ps | grep sonarqube || \
677+
echo "⚠️ Server may still be starting."
672678

673679
## ─────────── Containerised Scanner CLI (Docker / Podman) ───────────────
674680
sonar-submit-docker:

pyproject.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ dev = [
123123
"pylint>=3.3.7",
124124
"pylint-pydantic>=0.3.5",
125125
"pyre-check>=0.9.23",
126+
"pyrefly>=0.21.0",
126127
"pyright>=1.1.402",
127128
"pyroma>=4.2",
128129
"pyspelling>=2.10",
@@ -365,3 +366,14 @@ ignore_unused = [
365366
"twine",
366367
"uvicorn"
367368
]
369+
370+
# --------------------------------------------------------------------
371+
# 🛠 https://github.com/facebook/pyrefly (replaces pyre)
372+
# --------------------------------------------------------------------
373+
[tool.pyrefly]
374+
project-excludes = [
375+
"**/build/",
376+
'**/\.venv/',
377+
'**/\.mypy_cache/',
378+
]
379+
python-version = "3.11.0"

tests/unit/mcpgateway/services/test_resource_service.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ async def test_register_resource_success(self, resource_service, mock_db, sample
177177
patch.object(resource_service, "_notify_resource_added", new_callable=AsyncMock),
178178
patch.object(resource_service, "_convert_resource_to_read") as mock_convert,
179179
):
180-
181180
mock_convert.return_value = ResourceRead(
182181
id=1,
183182
uri=sample_resource_create.uri,
@@ -263,7 +262,6 @@ async def test_register_resource_integrity_error(self, resource_service, mock_db
263262

264263
# Mock validation success
265264
with patch.object(resource_service, "_is_valid_uri", return_value=True), patch.object(resource_service, "_detect_mime_type", return_value="text/plain"):
266-
267265
# Mock IntegrityError on commit
268266
mock_db.commit.side_effect = IntegrityError("", "", "")
269267

@@ -290,7 +288,6 @@ async def test_register_resource_binary_content(self, resource_service, mock_db)
290288
patch.object(resource_service, "_notify_resource_added", new_callable=AsyncMock),
291289
patch.object(resource_service, "_convert_resource_to_read") as mock_convert,
292290
):
293-
294291
mock_convert.return_value = ResourceRead(
295292
id=1,
296293
uri=binary_resource.uri,
@@ -443,7 +440,6 @@ async def test_toggle_resource_status_activate(self, resource_service, mock_db,
443440
mock_db.get.return_value = mock_inactive_resource
444441

445442
with patch.object(resource_service, "_notify_resource_activated", new_callable=AsyncMock), patch.object(resource_service, "_convert_resource_to_read") as mock_convert:
446-
447443
mock_convert.return_value = ResourceRead(
448444
id=2,
449445
uri=mock_inactive_resource.uri,
@@ -478,7 +474,6 @@ async def test_toggle_resource_status_deactivate(self, resource_service, mock_db
478474
mock_db.get.return_value = mock_resource
479475

480476
with patch.object(resource_service, "_notify_resource_deactivated", new_callable=AsyncMock), patch.object(resource_service, "_convert_resource_to_read") as mock_convert:
481-
482477
mock_convert.return_value = ResourceRead(
483478
id=1,
484479
uri=mock_resource.uri,
@@ -564,7 +559,6 @@ async def test_update_resource_success(self, resource_service, mock_db, mock_res
564559
mock_db.execute.return_value = mock_scalar
565560

566561
with patch.object(resource_service, "_notify_resource_updated", new_callable=AsyncMock), patch.object(resource_service, "_convert_resource_to_read") as mock_convert:
567-
568562
mock_convert.return_value = ResourceRead(
569563
id=1,
570564
uri=mock_resource.uri,
@@ -634,7 +628,6 @@ async def test_update_resource_binary_content(self, resource_service, mock_db, m
634628
mock_db.execute.return_value = mock_scalar
635629

636630
with patch.object(resource_service, "_notify_resource_updated", new_callable=AsyncMock), patch.object(resource_service, "_convert_resource_to_read") as mock_convert:
637-
638631
mock_convert.return_value = ResourceRead(
639632
id=1,
640633
uri=mock_resource.uri,
@@ -983,7 +976,6 @@ async def test_read_template_resource_error(self, resource_service):
983976
resource_service._template_cache["template"] = template
984977

985978
with patch.object(resource_service, "_uri_matches_template", return_value=True), patch.object(resource_service, "_extract_template_params", side_effect=Exception("Template error")):
986-
987979
with pytest.raises(ResourceError) as exc_info:
988980
await resource_service._read_template_resource(uri)
989981

@@ -1002,7 +994,6 @@ async def test_read_template_resource_binary_not_supported(self, resource_servic
1002994
resource_service._template_cache["binary"] = template
1003995

1004996
with patch.object(resource_service, "_uri_matches_template", return_value=True), patch.object(resource_service, "_extract_template_params", return_value={"id": "123"}):
1005-
1006997
with pytest.raises(ResourceError) as exc_info:
1007998
await resource_service._read_template_resource(uri)
1008999

@@ -1257,7 +1248,6 @@ async def test_register_resource_generic_error(self, resource_service, mock_db,
12571248

12581249
# Mock validation success
12591250
with patch.object(resource_service, "_is_valid_uri", return_value=True), patch.object(resource_service, "_detect_mime_type", return_value="text/plain"):
1260-
12611251
# Mock generic error on add
12621252
mock_db.add.side_effect = Exception("Generic error")
12631253

0 commit comments

Comments
 (0)