generated from ilkersigirci/python-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
197 lines (149 loc) · 6.44 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# Oneshell means one can run multiple lines in a recipe in the same shell, so one doesn't have to
# chain commands together with semicolon
.ONESHELL:
SHELL=/bin/bash
ROOT_DIR=bert-score-api
PACKAGE=src/bert_score_api
PYTHON = python
PYTHON_VERSION=3.11
DOC_DIR=./docs
TEST_DIR=./tests
TEST_MARKER=placeholder
TEST_OUTPUT_DIR=tests_outputs
PRECOMMIT_FILE_PATHS=./bert_score_api/__init__.py
PROFILE_FILE_PATH=./bert_score_api/__init__.py
DOCKER_IMAGE=bert-score-api
DOCKER_TARGET=development
# TODO: add source for rye
PYPI_URLS=
.PHONY: help install test clean build publish doc pre-commit format lint profile
.DEFAULT_GOAL=help
help:
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) |\
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m\
%s\n", $$1, $$2}'
# If .env file exists, include it and export its variables
ifeq ($(shell test -f .env && echo 1),1)
include .env
export
endif
python-info: ## List information about the python environment
@which ${PYTHON}
@${PYTHON} --version
update-pip:
${PYTHON} -m pip install -U pip
install-rye:
! command -v rye &> /dev/null && curl -sSf https://rye.astral.sh/get | RYE_NO_AUTO_INSTALL=1 RYE_INSTALL_OPTION="--yes" bash
# echo 'source "$HOME/.rye/env"' >> ~/.bashrc
install-base: ## Installs only package dependencies
rye sync --no-dev --no-lock
install: ## Installs the development version of the package
$(MAKE) install-rye
rye sync --no-lock
$(MAKE) install-precommit
# # FIXME: Currently not supported by rye
# install-no-cache: ## Installs the development version of the package
# FIXME: Currently not supported by rye
# install-test: ## Install only test version of the package
install-precommit: ## Install pre-commit hooks
pre-commit install
install-lint:
pip install ruff==0.5.7
install-doc:
pip install mkdocs mkdocs-material mkdocstrings[python]
update-dependencies: ## Updates the lockfiles and installs dependencies. Dependencies are updated if necessary
rye sync
# Updates the lockfiles without installing dependencies
# rye lock
upgrade-dependencies: ## Updates the lockfiles and installs the latest version of the dependencies
rye sync --update-all
test-one: ## Run specific tests with TEST_MARKER=<test_name>, default marker is `placeholder`
${PYTHON} -m pytest -m ${TEST_MARKER}
test-one-parallel: ## Run specific tests with TEST_MARKER=<test_name> in parallel, default marker is `placeholder`
${PYTHON} -m pytest -n auto -m ${TEST_MARKER}
test-all: ## Run all tests
# mkdir -p ${TEST_OUTPUT_DIR}
# cp .coveragerc ${TEST_OUTPUT_DIR}
# cp setup.cfg ${TEST_OUTPUT_DIR}
${PYTHON} -m pytest
test-all-parallel: ## Run all tests with parallelization
${PYTHON} -m pytest -n auto
test-coverage: ## Run all tests with coverage
${PYTHON} -m pytest --cov=${PACKAGE} --cov-report=html:coverage
test-coverage-parallel:
${PYTHON} -m pytest -n auto --cov=${PACKAGE} --cov-report=html:coverage
test-docs: ## Test documentation examples with doctest
${PYTHON} -m pytest --doctest-modules ${PACKAGE}
test: clean-test test-all ## Cleans and runs all tests
test-parallel: clean-test test-all-parallel ## Cleans and runs all tests with parallelization
clean-build: ## Clean build dist and egg directories left after install
rm -rf ./build ./dist */*.egg-info *.egg-info
rm -rf ./pytest_cache
rm -rf ./junit
find . -type f -iname "*.so" -delete
find . -type f -iname '*.pyc' -delete
find . -type d -name '*.egg-info' -prune -exec rm -rf {} \;
find . -type d -name '__pycache__' -prune -exec rm -rf {} \;
find . -type d -name '.ruff_cache' -prune -exec rm -rf {} \;
find . -type d -name '.mypy_cache' -prune -exec rm -rf {} \;
clean-test: ## Clean test related files left after test
# rm -rf ./htmlcov
# rm -rf ./coverage.xml
find . -type f -regex '\.\/\.*coverage[^rc].*' -delete
rm -rf ${TEST_OUTPUT_DIR}
find ${TEST_DIR} -type f -regex '\.\/\.*coverage[^rc].*' -delete
find ${TEST_DIR} -type d -name 'htmlcov' -exec rm -r {} +
find . -type d -name '.pytest_cache' -prune -exec rm -rf {} \;
clean: clean-build clean-test ## Cleans build and test related files
build: ## Make Python source distribution
$(MAKE) clean-build
rye build --sdist --out dist
# NOTE: Below will fail if there is no dist folder
# See: https://github.com/mitsuhiko/rye/issues/475
# rye build --clean --sdist --out dist
build-wheel: ## Make Python wheel distribution
$(MAKE) clean-build
rye build --wheel --out dist
publish: ## Builds the project and publish the package to Pypi
# $(MAKE) build
rye publish dist/*
# rye publish --repository-url https://test.pypi.org/legacy/ dist/*
doc: ## Build documentation with mkdocs
mkdocs build
doc-github: ## Build documentation with mkdocs and deploy to github pages
mkdocs gh-deploy --force
doc-dev: ## Show documentation preview with mkdocs
mkdocs serve -w ${PACKAGE}
pre-commit-one: ## Run pre-commit with specific files
pre-commit run --files ${PRECOMMIT_FILE_PATHS}
pre-commit: ## Run pre-commit for all package files
pre-commit run --all-files
pre-commit-clean: ## Clean pre-commit cache
pre-commit clean
lint: ## Lint code with ruff
${PYTHON} -m ruff format ${PACKAGE} --check --diff
${PYTHON} -m ruff check ${PACKAGE}
lint-report: ## Lint report for gitlab
${PYTHON} -m ruff format ${PACKAGE} --check --diff
${PYTHON} -m ruff check ${PACKAGE} --format gitlab > gl-code-quality-report.json
format: ## Run ruff for all package files. CHANGES CODE
${PYTHON} -m ruff format ${PACKAGE}
${PYTHON} -m ruff check ${PACKAGE} --fix --show-fixes
typecheck: ## Checks code with mypy
${PYTHON} -m mypy --package ${PACKAGE}
# MYPYPATH=src ${PYTHON} -m mypy --package ${PACKAGE}
typecheck-no-cache: ## Checks code with mypy no cache
${PYTHON} -m mypy --package ${PACKAGE} --no-incremental
typecheck-report: ## Checks code with mypy and generates html report
${PYTHON} -m mypy --package ${PACKAGE} --html-report mypy_report
profile: ## Profile the file with scalene and shows the report in the terminal
${PYTHON} -m scalene --cli --reduced-profile ${PROFILE_FILE_PATH}
profile-gui: ## Profile the file with scalene and shows the report in the browser
${PYTHON} -m scalene ${PROFILE_FILE_PATH}
profile-builtin: ## Profile the file with cProfile and shows the report in the terminal
${PYTHON} -m cProfile -s tottime ${PROFILE_FILE_PATH}
docker-build: ## Build docker image
docker build --tag ${DOCKER_IMAGE} --file ./Dockerfile --target ${DOCKER_TARGET} .
backend-server: ## Run the backend server
# uvicorn bert_score_api.main:app --host 0.0.0.0 --port 8888
${PYTHON} -m bert_score_api.__main__