From 8e9e4c01d4ccc06102857f0e3d71060e85f2befc Mon Sep 17 00:00:00 2001 From: Matthias Hinrichs Date: Tue, 12 May 2026 23:55:58 +0200 Subject: [PATCH] style: refactor codebase to adhere to PEP 8 formatting standards throughout all source files --- README.md | 22 +++ scripts/hooks/pre-commit | 26 ++++ src/strava_mcp_server/__init__.py | 1 + src/strava_mcp_server/get_token.py | 16 ++- src/strava_mcp_server/main.py | 8 +- src/strava_mcp_server/strava_client.py | 82 +++++++++--- src/strava_mcp_server/tools/__init__.py | 2 + src/strava_mcp_server/tools/activities.py | 125 +++++++++++++----- src/strava_mcp_server/tools/athlete.py | 74 ++++++----- src/strava_mcp_server/tools/clubs.py | 29 +++- src/strava_mcp_server/tools/gear.py | 31 +++-- src/strava_mcp_server/tools/prompts.py | 8 +- src/strava_mcp_server/tools/routes.py | 40 ++++-- .../tools/segment_efforts.py | 47 +++++-- src/strava_mcp_server/tools/segments.py | 58 +++++--- src/strava_mcp_server/utils.py | 21 +-- tests/test_strava.py | 24 ++-- 17 files changed, 443 insertions(+), 171 deletions(-) create mode 100755 scripts/hooks/pre-commit diff --git a/README.md b/README.md index 62861dd..d06eb85 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ Built with [FastMCP](https://github.com/jlowin/fastmcp) and the [MCP Python SDK] - [Project Structure](#project-structure) - [Design Decisions](#design-decisions) - [CI/CD (Gitea Actions)](#cicd-gitea-actions) +- [Development & Testing](#️-development--testing) + - [Git Hooks](#git-hooks) - [Known Strava API Limitations](#known-strava-api-limitations) - [Troubleshooting](#troubleshooting) @@ -226,6 +228,26 @@ docker buildx build --platform linux/amd64,linux/arm64 -t strava-mcp-server:test --- +### 5. Git Hooks + +A `pre-commit` hook is provided to automatically run `ruff check` on staged Python files before every commit, catching linting errors before they enter the history. + +The hook is stored in the repository under `scripts/hooks/` for easy installation. + +**Install the hook:** +```bash +cp scripts/hooks/pre-commit .git/hooks/pre-commit +chmod +x .git/hooks/pre-commit +``` + +**Behaviour:** +- ✅ Commit proceeds if `ruff check` passes on all staged `.py` files. +- ❌ Commit is aborted if any linting errors are found. +- 🔧 Auto-fix lint issues with `uv run ruff check --fix`. +- ⚡ Bypass for emergencies: `git commit --no-verify`. + +--- + ## License MIT diff --git a/scripts/hooks/pre-commit b/scripts/hooks/pre-commit new file mode 100755 index 0000000..a8dc5a0 --- /dev/null +++ b/scripts/hooks/pre-commit @@ -0,0 +1,26 @@ +#!/bin/sh +# pre-commit hook: runs ruff check on staged Python files before every commit +# To bypass: git commit --no-verify + +# Get list of staged Python files +STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.py$') + +if [ -z "$STAGED_FILES" ]; then + exit 0 +fi + +echo "🔍 Running ruff check on staged files..." + +uv run ruff check $STAGED_FILES +exit_code=$? + +if [ $exit_code -ne 0 ]; then + echo "" + echo "❌ ruff check failed. Commit aborted." + echo " Fix the issues above or run: uv run ruff check --fix" + echo " To bypass: git commit --no-verify" + exit 1 +fi + +echo "✅ ruff check passed." +exit 0 diff --git a/src/strava_mcp_server/__init__.py b/src/strava_mcp_server/__init__.py index 3c6f6c8..7e4875f 100644 --- a/src/strava_mcp_server/__init__.py +++ b/src/strava_mcp_server/__init__.py @@ -1,2 +1,3 @@ """Strava MCP Server""" + __version__ = "0.1.0" diff --git a/src/strava_mcp_server/get_token.py b/src/strava_mcp_server/get_token.py index 12a2bf2..5b82478 100644 --- a/src/strava_mcp_server/get_token.py +++ b/src/strava_mcp_server/get_token.py @@ -11,6 +11,7 @@ Required scopes: Usage: uv run get_token.py """ + import os import webbrowser import httpx @@ -25,6 +26,7 @@ CLIENT_SECRET = os.getenv("STRAVA_CLIENT_SECRET") REDIRECT_URI = "http://localhost:8765/callback" SCOPES = "profile:read_all,activity:read_all,activity:read,profile:write" + class CallbackHandler(BaseHTTPRequestHandler): client_id: str = "" client_secret: str = "" @@ -50,14 +52,15 @@ class CallbackHandler(BaseHTTPRequestHandler): ) response.raise_for_status() self.tokens = response.json() - + self.send_response(200) self.send_header("Content-Type", "text/html; charset=utf-8") self.end_headers() - + refresh_token = self.tokens.get("refresh_token") - - self.wfile.write(f""" + + self.wfile.write( + f"""