-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
143 lines (120 loc) · 4.12 KB
/
Makefile
File metadata and controls
143 lines (120 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
.PHONY: lint format test clean install update fix-lint build publish test-publish coverage bump-patch bump-minor bump-major release
# Python version
PYTHON := python3
# Virtual environment
VENV := .venv
VENV_PYTHON := $(VENV)/bin/python
# Source directories
SRC_DIRS := .
# Default target
all: lint format test
# Linting
lint:
@echo "Running ruff..."
uv run ruff check $(SRC_DIRS)
@echo "Running mypy..."
uv run mypy $(SRC_DIRS)
# Fix linting errors
fix-lint:
@echo "Fixing ruff errors..."
uv run ruff check --fix $(SRC_DIRS)
@echo "Running black..."
uv run black $(SRC_DIRS)
@echo "Running isort..."
uv run isort $(SRC_DIRS)
# Formatting
format:
@echo "Running black..."
uv run black $(SRC_DIRS)
@echo "Running isort..."
uv run isort $(SRC_DIRS)
# Testing
test:
@echo "Running tests..."
uv run pytest
# Coverage
coverage:
@echo "Running tests with coverage..."
uv run pytest --cov=grafana_loki_mcp --cov-report=term --cov-report=xml --cov-report=html
# Clean up
clean:
@echo "Cleaning up..."
rm -rf .pytest_cache .mypy_cache .ruff_cache
find . -type d -name __pycache__ -exec rm -rf {} +
find . -type f -name "*.pyc" -delete
rm -rf build/ dist/ *.egg-info/ htmlcov/ .coverage coverage.xml
# Install dependencies
install:
@echo "Installing dependencies..."
uv pip install -e ".[dev]"
# Update dependencies
update:
@echo "Updating dependencies..."
uv pip install --upgrade -e ".[dev]"
# Build package
build: clean
@echo "Building package..."
uv run python -m build
# Test publish to TestPyPI
test-publish: build
@echo "Publishing to TestPyPI..."
uv run twine upload --repository-url https://test.pypi.org/legacy/ dist/*
# Publish to PyPI
publish: build
@echo "Publishing to PyPI..."
uv run twine upload dist/*
# Version bumping
VERSION_FILE := grafana_loki_mcp/__version__.py
# Helper function to update version
define update_version
@echo "Updating version to $(1)"
@sed -i.bak 's/__version__ = "[^"]*"/__version__ = "$(1)"/' $(VERSION_FILE)
@rm -f $(VERSION_FILE).bak
@git add $(VERSION_FILE)
@git commit -m "Bump version to $(1)"
@git tag -a v$(1) -m "Version $(1)"
@echo "Version updated to $(1). Don't forget to push with: git push && git push --tags"
endef
# Get current version (macOS compatible)
CURRENT_VERSION := $(shell grep -o '"[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*[^"]*"' $(VERSION_FILE) | tr -d '"')
VERSION_BASE := $(shell echo $(CURRENT_VERSION) | sed -E 's/([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
VERSION_SUFFIX := $(shell echo $(CURRENT_VERSION) | grep -o -- "-[a-zA-Z0-9]\+" || echo "")
MAJOR := $(shell echo $(VERSION_BASE) | cut -d. -f1)
MINOR := $(shell echo $(VERSION_BASE) | cut -d. -f2)
PATCH := $(shell echo $(VERSION_BASE) | cut -d. -f3)
BETA_NUM := $(shell echo $(CURRENT_VERSION) | grep -o "beta[0-9]\+" | grep -o "[0-9]\+" || echo "0")
# Bump patch version (0.0.x)
bump-patch:
$(eval NEW_PATCH := $(shell echo $$(($(PATCH) + 1))))
$(eval NEW_VERSION := $(MAJOR).$(MINOR).$(NEW_PATCH))
$(call update_version,$(NEW_VERSION))
# Bump minor version (0.x.0)
bump-minor:
$(eval NEW_MINOR := $(shell echo $$(($(MINOR) + 1))))
$(eval NEW_VERSION := $(MAJOR).$(NEW_MINOR).0)
$(call update_version,$(NEW_VERSION))
# Bump major version (x.0.0)
bump-major:
$(eval NEW_MAJOR := $(shell echo $$(($(MAJOR) + 1))))
$(eval NEW_VERSION := $(NEW_MAJOR).0.0)
$(call update_version,$(NEW_VERSION))
# Bump beta version (x.x.x-beta)
bump-beta:
@if echo "$(CURRENT_VERSION)" | grep -q "beta"; then \
NEW_BETA_NUM=$$(($(BETA_NUM) + 1)); \
NEW_VERSION="$(VERSION_BASE)-beta$$NEW_BETA_NUM"; \
else \
NEW_PATCH=$$(($(PATCH) + 1)); \
NEW_VERSION="$(MAJOR).$(MINOR).$$NEW_PATCH-beta1"; \
fi; \
echo "Updating version to $$NEW_VERSION"; \
sed -i.bak "s/__version__ = \"[^\"]*\"/__version__ = \"$$NEW_VERSION\"/" $(VERSION_FILE); \
rm -f $(VERSION_FILE).bak; \
git add $(VERSION_FILE); \
git commit -m "Bump version to $$NEW_VERSION"; \
git tag -a "v$$NEW_VERSION" -m "Version $$NEW_VERSION"; \
echo "Version updated to $$NEW_VERSION. Don't forget to push with: git push && git push --tags"
# Remove beta suffix for release (x.x.x-betaX -> x.x.x)
release:
$(eval NEW_VERSION := $(VERSION_BASE))
$(call update_version,$(NEW_VERSION))