-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
143 lines (119 loc) · 4.47 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
# Credit: Ment, Alex (former Intern) and #https://github.com/mattharrison/sample_nb_code_project/blob/main/Makefile
# .ONESHELL tells make to run each recipe line in a single shell
.ONESHELL:
# .DEFAULT_GOAL tells make which target to run when no target is specified
.DEFAULT_GOAL := all
# Specify python location in virtual environment
# Specify pip location in virtual environment
# Specify the name of the docker container for easy edits.
PYTHON := .venv/bin/python3
PIP := .venv/bin/pip3
DOCKER_IMAGE_NAME := func_calling_ollama
DOCKER_IMAGE_VERSION := v0.0.0
DOCKER_IMAGE_TAG := $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_VERSION)
venv/bin/activate: requirements.txt #requirements.txt is a requirement, otherwise this command won't run
# create virtual environment
python3 -m venv .venv
# make command executable
# chmod is a bash command, +x is giving the ADMIN user permission to execute it
# if it's a+x, that means anyone can run it, even if you aren't an ADMIN
chmod +x .venv/bin/activate
# activate virtual environment
. .venv/bin/activate
activate:
# activate virtual environment
. .venv/bin/activate
install: venv/bin/activate requirements.txt # prerequisite
# install commands
# tells pip to install from remote repository which is pip, instead of from the local cached version
$(PIP) --no-cache-dir install --upgrade pip &&\
$(PIP) --no-cache-dir install -r requirements.txt
docstring: activate
# format docstring, might have to change this as well
# write a template using a numpydoc convention and output it to my python file
# so basically just document functions, classes etc. in the numpy style
pyment -w -o numpydoc *.py
format: activate
# format code
black *.py utils/*.py tests/*.py
clean:
# clean directory of cache
# files like pychache are gen'd after running py files
# the data speeds up execution of py files in subsequent runs
# reduces size of repo
# during version control, removing them would avoid conflicts with other dev's cached files
# add code to remove ipynb checkpoints
# the &&\ is used to say, after running this successfully, run the next...
echo @cleaning up your directory
rm -rf __pycache__ &&\
rm -rf .pytest_cache &&\
rm -rf .venv
rm -rf .ipynb_checkpoints
rm -rf utils/__pycache__
rm -rf utils/*.log
rm -rf *.log
rm -rf tests/__pycache__
rm -rf .cache
rm -rf tts_output.mp3
lint: activate install
#flake8 or #pylint
# In this scenario it'll only tell as errors found in your code
# R - refactor
# C - convention
pylint --disable=R,C --errors-only *.py
test: activate install
# run tests
echo @running tests
echo @we used this signature to run tests: $(PYTHON) -m pytest tests/testcases.py
echo @for single tests, we used this signature: $(PYTHON) -m pytest tests/testcases.py::test_function_name
$(PYTHON) -m pytest tests/test_cases.py -v
$(PYTHON) -m pytest tests/test_run.py -v --asyncio-mode=strict
run: activate install format
# run test_app
# run each file separately, bc if one fails, all fail
$(PYTHON) utils/function_call.py
run_gradio: activate install format
# run gradio
$(PYTHON) app.py
run_gradio_stt: activate install format
# run gradio
$(PYTHON) voice_stt_mode.py
docker_build: Dockerfile
#build container
# docker build -t $(DOCKER_IMAGE_TAG) .
docker_run_test: Dockerfile.app Dockerfile.ollama
# linting Dockerfile
docker run --rm -i hadolint/hadolint < Dockerfile.ollama
docker run --rm -i hadolint/hadolint < Dockerfile.app
docker_clean: Dockerfile.ollama Dockerfile.app
# clean docker
# remove docker images
docker rmi tool_calling_api-ollama -f || true
docker rmi tool_calling_api-app -f || true
docker system prune -af --volumes
docker_run: Dockerfile.ollama Dockerfile.app
# run docker
# this is basically a test to see if a docker image is being created successfully
docker-compose up --build
setup_readme: ## Create a README.md
@if [ ! -f README.md ]; then \
echo "# Project Name\n\
Description of the project.\n\n\
## Installation\n\
- Step 1\n\
- Step 2\n\n\
## Usage\n\
Explain how to use the project here.\n\n\
## Contributing\n\
Explain how to contribute to the project.\n\n\
## License\n\
License information." > README.md; \
echo "README.md created."; \
else \
echo "README.md already exists."; \
fi
docker_push: docker_build
#deploy
# .Phony is used to tell make that these targets are not files
.PHONY: activate format clean lint test build run docker_build docker_run docker_push docker_clean docker_run_test
all: setup_readme install format lint test run docker_build docker_run docker_push