-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMakefile
85 lines (69 loc) · 3.46 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
.PHONY: requirements clean lint help
#################################################################################
# GLOBALS #
#################################################################################
PROJECT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
PROFILE = default
PROJECT_NAME = agential
PYTHON_INTERPRETER = python
PYTHON_VERSION = 3.11
POETRY_VERSION = 1.8.2
ifeq (,$(shell which conda 2>/dev/null))
HAS_CONDA=False
else
HAS_CONDA=True
endif
#################################################################################
# COMMANDS #
#################################################################################
requirements: test_environment ## Install Python dependencies with requirements.txt.
$(PYTHON_INTERPRETER) -m pip install -U pip setuptools wheel
$(PYTHON_INTERPRETER) -m pip install -r requirements.txt
poetry_requirements: test_environment ## Install Python dependencies with Poetry.
$(PYTHON_INTERPRETER) -m pip install pipx
pipx install poetry=$(POETRY_VERSION)
poetry check
poetry check --lock
poetry install
create_requirements: test_environment ## Create requirements.txt (and dev) from pyproject.toml.
poetry export -f requirements.txt --output requirements.txt --without-hashes
poetry export -f requirements.txt --output requirements-dev.txt --without-hashes --only=dev
clean: ## Delete all compiled Python files.
find . -type f -name "*.py[co]" -delete
find . -type d -name "__pycache__" -delete
lint: ## Lint using black and ruff, static check mypy exclude tests.
poetry run mypy agential
poetry run black --check agential tests
poetry run ruff check agential tests
auto_lint: ## Automatic format & lint using black and ruff.
poetry run black agential tests
poetry run ruff agential tests --fix --show-fixes --show-source
test: ## Run all pytest tests.
poetry run pytest --cov=agential \
--cov-report xml \
--cov-report term-missing:skip-covered \
tests/
create_environment: ## Set up conda environment.
ifeq (True,$(HAS_CONDA))
@echo ">>> Detected conda, creating conda environment."
ifeq (3,$(findstring 3,$(PYTHON_INTERPRETER)))
conda create --name $(PROJECT_NAME) python=$(PYTHON_VERSION)
else
conda create --name $(PROJECT_NAME) python=2.7
endif
@echo ">>> New conda env created. Activate with:\nsource activate $(PROJECT_NAME)"
else
$(PYTHON_INTERPRETER) -m pip install -q virtualenv virtualenvwrapper
@echo ">>> Installing virtualenvwrapper if not already installed.\nMake sure the following lines are in shell startup file\n\
export WORKON_HOME=$$HOME/.virtualenvs\nexport PROJECT_HOME=$$HOME/Devel\nsource /usr/local/bin/virtualenvwrapper.sh\n"
@bash -c "source `which virtualenvwrapper.sh`;mkvirtualenv $(PROJECT_NAME) --python=$(PYTHON_INTERPRETER)"
@echo ">>> New virtualenv created. Activate with:\nworkon $(PROJECT_NAME)"
endif
test_environment: ## Test python environment is setup correctly.
$(PYTHON_INTERPRETER) test_environment.py
#################################################################################
# Self Documenting Commands #
#################################################################################
.DEFAULT_GOAL := help
help: ## Show all Makefile targets.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[33m%-30s\033[0m %s\n", $$1, $$2}'