Skip to content

Commit 0b78eee

Browse files
committed
Fixed /static mapping when running as pip wheel
Signed-off-by: Mihai Criveti <[email protected]>
1 parent e694546 commit 0b78eee

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

Makefile

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,7 @@ local-pypi-debug:
15841584

15851585
# =============================================================================
15861586
# 🏠 LOCAL DEVPI SERVER
1587+
# TODO: log in background, better cleanup/delete logic
15871588
# =============================================================================
15881589
# help: 🏠 LOCAL DEVPI SERVER
15891590
# help: devpi-install - Install devpi server and client
@@ -1596,9 +1597,11 @@ local-pypi-debug:
15961597
# help: devpi-clean - Full cycle: build → upload → install locally
15971598
# help: devpi-status - Show devpi server status
15981599
# help: devpi-web - Open devpi web interface
1600+
# help: devpi-delete - Delete mcpgateway==<ver> from devpi index
1601+
15991602

16001603
.PHONY: devpi-install devpi-init devpi-start devpi-stop devpi-setup-user devpi-upload \
1601-
devpi-test devpi-clean devpi-status devpi-web devpi-restart
1604+
devpi-delete devpi-test devpi-clean devpi-status devpi-web devpi-restart
16021605

16031606
DEVPI_HOST := localhost
16041607
DEVPI_PORT := 3141
@@ -1688,14 +1691,14 @@ devpi-setup-user: devpi-start
16881691
(devpi user -c $(DEVPI_USER) password=$(DEVPI_PASS) email=$(DEVPI_USER)@localhost.local 2>/dev/null || \
16891692
echo 'User $(DEVPI_USER) already exists') && \
16901693
devpi login $(DEVPI_USER) --password=$(DEVPI_PASS) && \
1691-
(devpi index -c dev bases=root/pypi volatile=False 2>/dev/null || \
1694+
(devpi index -c dev bases=root/pypi volatile=True 2>/dev/null || \
16921695
echo 'Index dev already exists') && \
16931696
devpi use $(DEVPI_INDEX)"
16941697
@echo "✅ User '$(DEVPI_USER)' and index 'dev' configured"
16951698
@echo "📝 Login: $(DEVPI_USER) / $(DEVPI_PASS)"
16961699
@echo "📍 Using index: $(DEVPI_INDEX)"
16971700

1698-
devpi-upload: devpi-setup-user
1701+
devpi-upload: dist devpi-setup-user ## Build wheel/sdist, then upload
16991702
@echo "📤 Uploading existing package to devpi..."
17001703
@if [ ! -d "dist" ] || [ -z "$$(ls -A dist/ 2>/dev/null)" ]; then \
17011704
echo "❌ No dist/ directory or files found. Run 'make dist' first."; \
@@ -1813,3 +1816,18 @@ devpi-unconfigure-pip:
18131816
else \
18141817
echo "ℹ️ No pip configuration found"; \
18151818
fi
1819+
1820+
# ─────────────────────────────────────────────────────────────────────────────
1821+
# 📦 Version helper (defaults to the version in pyproject.toml)
1822+
# override on the CLI: make VER=0.2.1 devpi-delete
1823+
# ─────────────────────────────────────────────────────────────────────────────
1824+
VER ?= $(shell python -c "import tomllib, pathlib; \
1825+
print(tomllib.loads(pathlib.Path('pyproject.toml').read_text())['project']['version'])" \
1826+
2>/dev/null || echo 0.0.0)
1827+
1828+
devpi-delete: devpi-setup-user ## Delete mcpgateway==$(VER) from index
1829+
@echo "🗑️ Removing mcpgateway==$(VER) from $(DEVPI_INDEX)"
1830+
@/bin/bash -c "source $(VENV_DIR)/bin/activate && \
1831+
devpi use $(DEVPI_INDEX) && \
1832+
devpi remove -y mcpgateway==$(VER) || true"
1833+
@echo "✅ Delete complete (if it existed)"

mcpgateway/config.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import json
3333
from functools import lru_cache
34+
from importlib.resources import files
3435
from pathlib import Path
3536
from typing import Annotated, Any, Dict, List, Optional, Set, Union
3637

@@ -51,7 +52,15 @@ class Settings(BaseSettings):
5152
port: int = Field(4444, env="PORT")
5253
database_url: str = "sqlite:///./mcp.db"
5354
templates_dir: Path = Path("mcpgateway/templates")
54-
static_dir: Path = Path("mcpgateway/static")
55+
# Absolute paths resolved at import-time (still override-able via env vars)
56+
templates_dir: Path = Field(
57+
default=files("mcpgateway") / "templates",
58+
env="TEMPLATES_DIR",
59+
)
60+
static_dir: Path = Field(
61+
default=files("mcpgateway") / "static",
62+
env="STATIC_DIR",
63+
)
5564
app_root_path: str = ""
5665

5766
# Protocol

mcpgateway/main.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,7 @@ async def healthcheck(db: Session = Depends(get_db)):
19691969

19701970

19711971
# Mount static files
1972-
app.mount("/static", StaticFiles(directory=str(settings.static_dir)), name="static")
1972+
# app.mount("/static", StaticFiles(directory=str(settings.static_dir)), name="static")
19731973

19741974
# Include routers
19751975
app.include_router(version_router)
@@ -2001,7 +2001,19 @@ async def healthcheck(db: Session = Depends(get_db)):
20012001
if UI_ENABLED:
20022002
# Mount static files for UI
20032003
logger.info("Mounting static files - UI enabled")
2004-
app.mount("/static", StaticFiles(directory=str(settings.static_dir)), name="static")
2004+
try:
2005+
app.mount(
2006+
"/static",
2007+
StaticFiles(directory=str(settings.static_dir)),
2008+
name="static",
2009+
)
2010+
logger.info("Static assets served from %s", settings.static_dir)
2011+
except RuntimeError as exc:
2012+
logger.warning(
2013+
"Static dir %s not found – Admin UI disabled (%s)",
2014+
settings.static_dir,
2015+
exc,
2016+
)
20052017

20062018
# Redirect root path to admin UI
20072019
@app.get("/")

0 commit comments

Comments
 (0)