-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
124 lines (104 loc) · 3.7 KB
/
Copy pathMakefile
File metadata and controls
124 lines (104 loc) · 3.7 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
# Makefile for managing the tools project
# Variables
VENV_NAME = .venv
PYTHON_FILES = $(shell python -c "import toml; print(' '.join(toml.load('pyproject.toml')['tool']['setuptools']['packages']['find']['include']))")
# Detect the operating system
ifeq ($(OS),Windows_NT)
OS_NAME := Windows
else
OS_NAME := $(shell uname -s)
endif
# install uv
install_uv:
ifeq ($(OS_NAME),Linux)
@echo "Detected Linux OS"
curl -LsSf https://astral.sh/uv/install.sh | sh
else ifeq ($(OS_NAME),Darwin)
@echo "Detected macOS"
curl -LsSf https://astral.sh/uv/install.sh | sh
else ifeq ($(OS_NAME),Windows)
@echo "Detected Windows OS"
powershell -ExecutionPolicy Bypass -Command "irm https://astral.sh/uv/install.ps1 | iex"
# "If you are on Windows and this doesn't work, check your permissions or run the command manually."
endif
# Create a virtual environment
venv:
uv venv $(VENV_NAME)
@echo "Virtual $(VENV_NAME) environment created."
@echo "To activate the virtual environment, please run: source $(VENV_NAME)/bin/activate"
# Install dependencies using uv
install:
uv pip install -r requirements.txt
uv pip install pandas-stubs
@echo "Dependencies installed."
@echo "To activate the virtual environment, please run: source $(VENV_NAME)/bin/activate or the corresponding command for your operating system."
# Pre-commit hooks
pre_commit:
pre-commit install
@echo "Pre-commit hooks installed."
# Clean up
clean:
ifeq ($(OS_NAME),Windows)
del /s /q $(VENV_NAME)
rmdir /s /q $(VENV_NAME)
else
rm -rf $(VENV_NAME)
endif
@echo "Cleaned up the environment."
# Tests
test:
pytest
@echo "Tests executed."
# Linting and formatting
.PHONY: format
format:
black --line-length=99 $(PYTHON_FILES)
isort --profile black --line-length 99 $(PYTHON_FILES)
@echo "Formatting completed."
.PHONY: check-format
check-format:
black --check --line-length=99 $(PYTHON_FILES)
isort --check --diff --profile black --line-length 99 $(PYTHON_FILES)
@echo "Format check completed."
.PHONY: flake8
flake8:
flake8 --max-line-length=99 --ignore=E501,W503,E203 $(PYTHON_FILES)
@echo "Flake8 check completed."
.PHONY: bandit
bandit:
bandit --skip=B101 -r $(PYTHON_FILES) --exclude tests/
@echo "Bandit security check completed."
.PHONY: mypy
mypy: ## Run mypy type checker
mypy --config-file pyproject.toml $(PYTHON_FILES)
@echo "MyPy type checking completed."
.PHONY: pyupgrade
pyupgrade:
python -c "import glob, subprocess; subprocess.run(['pyupgrade', '--py312-plus'] + glob.glob('src/**/*.py', recursive=True) + glob.glob('config/**/*.py', recursive=True))"
@echo "Python code upgraded to Python 3.12+ syntax."
.PHONY: lint
lint: format flake8 pyupgrade
@echo "All linting checks completed."
.PHONY: check-all
check-all: check-format lint test
@echo "All checks and tests completed."
# Help
help:
@echo "Makefile for tools"
@echo "Usage:"
@echo " make venv - Create a virtual environment"
@echo " make activate - Activate the virtual environment"
@echo " make install - Install dependencies using uv"
@echo " make pre_commit - Install pre-commit hooks"
@echo " make pyupgrade - Upgrade Python syntax to 3.12+"
@echo " make pre-commit-hooks - Run basic pre-commit hooks"
@echo " make format - Format code with black and isort"
@echo " make check-format - Check formatting without changing files"
@echo " make flake8 - Run flake8 linting"
@echo " make bandit - Run bandit security checks"
@echo " make mypy - Run mypy type checking"
@echo " make lint - Run all linting tools"
@echo " make test - Run pytest"
@echo " make check-all - Run all checks and tests"
@echo " make clean - Clean up the environment"
@echo " make help - Display this help message"