|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +# Configures the shell for recipes to use bash, enabling bash commands and ensuring |
| 19 | +# that recipes exit on any command failure (including within pipes). |
| 20 | +SHELL = /usr/bin/env bash -o pipefail |
| 21 | +.SHELLFLAGS = -ec |
| 22 | + |
| 23 | +## Variables |
| 24 | +PYTHON ?= python3 |
| 25 | +VENV_DIR := .venv |
| 26 | +ACTIVATE = source $(VENV_DIR)/bin/activate |
| 27 | + |
| 28 | +## Version information |
| 29 | +GIT_COMMIT := $(shell git rev-parse HEAD) |
| 30 | +UV_VERSION := $(shell cat pyproject.toml | grep -A1 tool.uv | grep -v tool.uv | grep required-version | sed 's/required-version *= *"\([^"]*\)".*/\1/') |
| 31 | + |
| 32 | +##@ General |
| 33 | + |
| 34 | +.PHONY: help |
| 35 | +help: ## Display this help |
| 36 | + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9\.-]+:.*?##/ { printf " \033[36m%-40s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) |
| 37 | + |
| 38 | +.PHONY: version |
| 39 | +version: ## Display version information |
| 40 | + @echo "Git commit: ${GIT_COMMIT}" |
| 41 | + @echo "UV version: ${UV_VERSION}" |
| 42 | + |
| 43 | +##@ MCP Server |
| 44 | + |
| 45 | +# Target to create the virtual environment directory |
| 46 | +$(VENV_DIR): |
| 47 | + @echo "Setting up Python virtual environment at $(VENV_DIR)..." |
| 48 | + @$(PYTHON) -m venv $(VENV_DIR) |
| 49 | + @echo "Virtual environment created." |
| 50 | + |
| 51 | +.PHONY: install-dependencies |
| 52 | +install-dependencies: $(VENV_DIR) |
| 53 | + @echo "Installing UV and project dependencies into $(VENV_DIR) for MCP project..." |
| 54 | + @$(VENV_DIR)/bin/pip install --upgrade pip |
| 55 | + @if [ ! -f "$(VENV_DIR)/bin/uv" ]; then \ |
| 56 | + $(VENV_DIR)/bin/pip install --upgrade "uv$(UV_VERSION)"; \ |
| 57 | + fi |
| 58 | + @$(ACTIVATE) && uv lock && uv sync --active --all-extras |
| 59 | + @echo "uv and dependencies installed for MCP project." |
| 60 | + |
| 61 | +.PHONY: setup-env |
| 62 | +setup-env: $(VENV_DIR) install-dependencies |
| 63 | + |
| 64 | +.PHONY: build |
| 65 | +build: setup-env ## Build the distribution files (sdist and wheel) for MCP project |
| 66 | + @echo "--- Building distribution for MCP project ---" |
| 67 | + @$(ACTIVATE) && uv build |
| 68 | + @echo "--- Distribution build complete for MCP project ---" |
| 69 | + |
| 70 | +.PHONY: cleanup |
| 71 | +cleanup: ## Cleanup virtual environment and build artifacts for MCP project |
| 72 | + @echo "--- Cleaning up virtual environment and build artifacts for MCP project ---" |
| 73 | + @rm -rf "$(VENV_DIR)" build/ dist/ .pytest_cache/ apache_polaris_mcp.egg-info/ |
| 74 | + @find . -type d -name "__pycache__" -exec rm -rf {} + |
| 75 | + @echo "--- Cleanup complete for MCP project ---" |
| 76 | + |
| 77 | +.PHONY: lint |
| 78 | +lint: setup-env ## Lint the MCP project |
| 79 | + @echo "--- Running linting checks for MCP project ---" |
| 80 | + @$(ACTIVATE) && uv run pre-commit run --all-files |
| 81 | + @echo "--- Linting checks complete for MCP project ---" |
| 82 | + |
| 83 | +.PHONY: run |
| 84 | +run: setup-env ## Start MCP server (stdin/stdout transport) |
| 85 | + @echo "--- Starting MCP server ---" |
| 86 | + @$(ACTIVATE) && uv run polaris-mcp |
| 87 | + @echo "--- MCP server finished ---" |
| 88 | + |
| 89 | +.PHONY: test |
| 90 | +test: setup-env ## Run unit tests for MCP project |
| 91 | + @echo "--- Running unit tests for MCP project ---" |
| 92 | + @$(ACTIVATE) && uv run pytest tests/ |
| 93 | + @echo "--- Unit tests complete for MCP project---" |
0 commit comments