-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
61 lines (48 loc) · 1.67 KB
/
Makefile
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
.PHONY: py-format-lint py-format isort black py-lint test all
current-branch := $(shell git rev-parse --abbrev-ref HEAD)
ifneq ($(current-branch), "main")
base-branch := origin/main
else
base-branch := @^
endif
# Get all files modified, including untracked files
py_files_changed = (git diff $(base-branch) --name-only --relative --diff-filter=d -- "*.py" | cat && git ls-files --exclude-standard -o "*.py")
apply_to_diff = $(py_files_changed) | xargs
# Run python linting/formatting as well as tests
all: py-format-lint test
# Run formatting and linting
py-format-lint: py-format py-lint
# Run both formatters
py-format: isort black
isort:
ifdef base-branch
@echo "\nRunning isort on all Python file changes between working directory and branch '$(base-branch)'...\n"
@$(apply_to_diff) isort
else
@echo "\nRunning isort on all Python files changed since last commit...\n"
@isort
endif
black:
ifdef base-branch
@echo "\nRunning Black formatter on all Python file changes between working directory and branch '$(base-branch)'...\n"
@$(apply_to_diff) black ./ --verbose
else
@echo "\nRunning Black formatter on all Python files changed since last commit...\n"
@black ./ --verbose
endif
py-lint:
ifdef base-branch
@echo "\nRunning flake8 on all Python file changes between working directory and branch '$(base-branch)'...\n"
@$(apply_to_diff) flake8 --config=setup.cfg
else
@echo "\nRunning flake8 on all Python files changed since last commit...\n"
@flake8 --config=setup.cfg
endif
test:
@python -m pytest
setup:
@echo "Creating python environment..."
@echo "...upgrading pip...\n"
@pip install --upgrade pip
@echo "...installing requirements...\n"
@pip install -r requirements.txt