-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
161 lines (124 loc) · 4.99 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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
####----Cookiecutter commands----####
.PHONY: cookiecutter
bake: ## bake without inputs and overwrite if exists.
@cookiecutter --no-input . --overwrite-if-exists
bake-clear: ## remove a previous cookiecutter bake
@rm -rf testone || true
@rm -rf python-skeleton || true
bake-test: ## bake the base project to test
@rm -rf testone || true
@poetry run cookiecutter --no-input . --overwrite-if-exists --config-file config.yaml
@code testone
####----Basic configurations----####
.PHONY: pre-commit
install_pre_commit: ## configure and install pre commit tool
@poetry run pre-commit install
uninstall_pre_commit: ## configure and install pre commit tool
@poetry run pre-commit uninstall
update_pre_commit: ## update pre-commit version and rules
@poetry run pre-commit autoupdate
pre_commit: ## run pre-commit checks
@poetry run pre-commit run -a
.PHONY: install
install: ## Install the poetry and python environment
@echo "🚀 Creating virtual environment using pyenv and poetry"
@poetry install
@poetry shell
install-poetry: ## Install the poetry environment
@echo "🚀 Creating virtual environment using pyenv and poetry"
@poetry install
@poetry shell
.PHONY: check_project
check_project: ## Run code quality tools.
@echo "🚀 Checking Poetry lock file consistency with 'pyproject.toml': Running poetry lock --check"
@poetry lock --check
@echo "🚀 Linting code: Running pre-commit"
@poetry run pre-commit run -a
# echo "🚀 Checking for obsolete dependencies: Running deptry"
# poetry run deptry .
.PHONE: poetry_plugins
# poetry self add poetry-git-version-plugin
poetry_plugins_install: ## Install and configure the poetry plugins
@echo "Install poetry-plugin-sort"
@poetry self add poetry-plugin-sort
@poetry self add poetry-plugin-up
poetry_plugins: ## Launch the poetry plugins
@echo "Launching poetry-plugin-sort"
@poetry sort
poetry_update: ## Update the poetry environment
@echo "🚀 Updating virtual environment using poetry"
@poetry self update
.PHONY: test
test: ## Test the code with pytest.
@echo "🚀 Testing code: Running pytest"
@poetry run pytest --cov --cov-config=pyproject.toml --cov-report=xml tests
### Project specific tasks
.PHONY: project
launch_py3: # Launch the main file with python 3
@export PYTHONPATH=$(pwd) && python3 app/main.py
launch_py: # Launch the main file with python
@export PYTHONPATH=$(pwd) && python app/main.py
####----Package Release----####
.PHONY: build
build: clean-build ## Build wheel file using poetry
@echo "🚀 Creating wheel file"
@poetry build
.PHONY: clean-build
clean-build: ## clean build artifacts
@rm -rf dist
.PHONY: publish
publish: ## publish a release to pypi.
@echo "🚀 Publishing: Dry run."
@poetry config pypi-token.pypi $(PYPI_TOKEN)
@poetry publish --dry-run
@echo "🚀 Publishing."
@poetry publish
.PHONY: build-and-publish
build-and-publish: build publish ## Build and publish.
####----Documentation----####
.PHONY: docs
docs: ## Launch mkdocs documentation locally
poetry run mkdocs serve
docs_build: ## Build mkdocs for local test
poetry run mkdocs build
docs_launch_local: ## Launch mkdocs documentation locally with the local building artefacts
poetry run mkdocs build
poetry run mkdocs serve -v --dev-addr=0.0.0.0:8000
docs_deploy: ## Deploy mkdocs documentation to github pages
poetry run mkdocs build -c -v --site-dir public
poetry run mkdocs gh-deploy --force
docs_public: ## Build mkdocs for official online release
poetry run mkdocs build -c -v --site-dir public
####----Docker----####
.PHONY: docker
create_network: ## create the docker network for the project
docker network create template
launch: ## launch the python application containers
docker-compose -p template up --build -d
launch_all: ## launch the backend project containers only
docker-compose -p template up --build -d app
launch_db: ## launch the database container only
docker-compose -p template up --build -d db
check: ## check the status of the docker containers
docker ps -a | grep "template"
check_logs: ## check the logs of the application container
docker logs -t app
check_exec: ## exec bash in the python app container
docker exec -it app /bin/bash
stop: ## stop all containers
docker-compose -p template down
# docker-compose down -v
stop_clear: ## stop containers and clean the volumes
docker-compose -p template down -v
clean_volumes: ## clean the docker volumes
docker volume prune
####----Project----####
.PHONY: help
help: ## Ask for help in the Makefile
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
.PHONY: project_restore
clean: ## Clean the projects of unwanted cached folders
rm -rf **/.ipynb_checkpoints **/.pytest_cache **/__pycache__ **/**/__pycache__ ./notebooks/ipynb_checkpoints .pytest_cache ./dist ./volumes
restore: ## Restore the projects to the start (hard clean)
rm -rf **/.ipynb_checkpoints **/.pytest_cache **/__pycache__ **/**/__pycache__ ./notabooks/ipynb_checkpoints .pytest_cache ./dist .venv poetry.lock
.DEFAULT_GOAL := help