Zappy - Year end project 2
This is a project that Epitech asked us to create in order to allow us to reveiw the notions of the current year.
Loading...
Searching...
No Matches
Makefile
Go to the documentation of this file.
1##
2## EPITECH PROJECT, 2024
3## Makefile
4## File description:
5## jitter jitter
6##
7
8# The variables in charge of tracking the files for the program
9SRC_DIR = ./src
10
11SRC = $(SRC_DIR)/main.py \
12
13# The variables concerning unit testing
14
15TEST_DIR = ./tests
16
17TEST_FILES = $(TEST_DIR)/test_main.py \
18 $(TEST_DIR)/test_constants.py \
19
20# Coverage report location
21
22COVERAGE_DIR = ./coverage_data
23
24# Binary name
25
26NAME = zappy_ai
27
28# Level precision of the build process
29
30LOG_LEVEL = WARN
31
32# The name of the python environement that will be used
33
34ENV_NAME = ai_env
35
36# The location in which the dependencies used during the build process
37# will be stored
38
39BUILD_LOCATION = ./build/
40
41# The location of the final built binary
42
43BINARY_LOCATION = ./dist/
44
45# The desired destinations for the binary
46
47BINARY_DESTINATION_ONE = ./
48
49BINARY_DESTINATION_TWO = ../../
50
51# The python binary that is available on the system
52
53CC = $(shell command -v python3.9 2>/dev/null || \
54 command -v python3 2>/dev/null || \
55 command -v python 2>/dev/null || \
56 command -v py 2>/dev/null \
57)
58
59# Break the code if no python instance was found
60
61ifndef CC
62 $(error Python interpreter not found. Please install Python.)
63endif
64
65# Search for pip version
66MY_PIP_BIN = pip3 # Please update it manually {the automation check seems to break the environment}
67
68# Break the code if no python instance was found
69
70ifndef MY_PIP_BIN
71 $(error Pip interpreter not found. Please install a pip interpreter.)
72endif
73
74# Silence the outputs we wish not to listen to
75SILENT = @
76
77# Colour codes
78C_BACKGROUND = \033[48;5;16m
79C_RED = \033[38;5;9m$(C_BACKGROUND)
80C_PINK = \033[38;5;206m$(C_BACKGROUND)
81C_CYAN = \033[38;5;87m$(C_BACKGROUND)
82C_BLUE = \033[38;5;45m$(C_BACKGROUND)
83C_WHITE = \033[38;5;15m$(C_BACKGROUND)
84C_GREEN = \033[38;5;46m$(C_BACKGROUND)
85C_RESET = \033[0m$(C_BACKGROUND)
86C_YELLOW = \033[38;5;226m$(C_BACKGROUND)
87
88# Compile the project
89all: install_dependencies build_binary update_binary_location clean
90
91my_all: create_environement all
92
93# Create the python environement
94create_environement:
95 @echo -e "$(C_CYAN)Creating python environment$(C_RESET)"
96 $(SILENT) $(CC) -m venv $(ENV_NAME)
97
98# Install the python dependencies
99install_dependencies:
100 $(SILENT) echo -e "$(C_CYAN)Upgrading pip$(C_RESET)" &&\
101 $(CC) -m pip install --upgrade pip && \
102 . $(ENV_NAME)/bin/activate && \
103 $(MY_PIP_BIN) install --upgrade pip && \
104\
105 $(MY_PIP_BIN) list && \
106 echo -e "$(C_CYAN)Installing python dependencies$(C_RESET)" &&\
107 $(MY_PIP_BIN) install -r requirements.txt
108
109# Activate the python environement (
110# this is a shortcut to help you keep your
111# environement up to date and also avoid mistakes in the name or process
112# )
113activate_environement: install_dependencies
114 @echo -e "$(C_PINK)Activating environement '$(ENV_NAME)'$(C_RESET)"
115 $(SILENT) . ./$(ENV_NAME)/bin/activate && \
116 export PYTHONPATH=.:$$PYTHONPATH; \
117 echo "Environement activated" && \
118 /bin/bash ; \
119 STATUS=$$? ; \
120 echo "Environement deactivated" && \
121 echo "Exit code: $$STATUS" && \
122 exit $$STATUS
123
124activate: activate_environement
125
126# Build the python code as a binary
127build_binary:
128 @echo -e "$(C_BLUE)Building binary '$(C_YELLOW)$(NAME)$(C_BLUE)'$(C_RESET)"
129 $(SILENT) . ./$(ENV_NAME)/bin/activate && \
130 pyinstaller \
131 $(SRC) \
132 --workpath $(BUILD_LOCATION) --distpath $(BINARY_LOCATION) \
133 --onefile --noconfirm \
134 --name $(NAME) \
135 --log-level=$(LOG_LEVEL) \
136 -y
137 @echo -ne "$(C_BLUE)Binary '$(C_YELLOW)$(NAME)$(C_BLUE)' "
138 @echo -e "$(C_GREEN)built$(C_RESET)"
139
140# Update the location of the binary so that it can be easily accessed
141update_binary_location:
142 @echo -e "$(C_PINK)Updating binary locations$(C_RESET)"
143 $(SILENT) cp -vf $(BINARY_LOCATION)$(NAME) $(BINARY_DESTINATION_ONE)
144 $(SILENT) cp -vf $(BINARY_LOCATION)$(NAME) $(BINARY_DESTINATION_TWO)
145 @echo -e "$(C_PINK)Binary locations $(C_GREEN)updated$(C_RESET)"
146
147# Clean the cache projects
148
149clean:
150 @echo -e "$(C_YELLOW)Cleaning $(C_CYAN)cache and build data$(C_RESET)"
151# Removing the spec files that were used for the executable
152 $(SILENT) rm -vf *.spec
153# Removing the build and distribution folder of the executable
154 $(SILENT) rm -rvf $(BUILD_LOCATION)
155 $(SILENT) rm -rvf $(BINARY_LOCATION)
156# Removing python runtime cache
157 $(SILENT) find . -type d -name __pycache__ -exec rm -rvf {} +
158 @echo -e "$(C_GREEN)Cleaned $(C_CYAN)cache and build data$(C_RESET)"
159
160# Clean the binaries produced
161clean_env:
162 @echo -ne "$(C_YELLOW)Cleaning $(C_CYAN)environement "
163 @echo -e "'$(C_RED)$(ENV_NAME)$(C_CYAN)'$(C_RESET)"
164 $(SILENT) rm -rf ./$(ENV_NAME)
165 @echo -ne "$(C_CYAN)Environement '$(C_RED)$(ENV_NAME)$(C_CYAN)' "
166 @echo -e "$(C_GREEN)cleaned$(C_RESET)"
167
168# Clean the coverage produced
169clean_coverage:
170 @echo -e "$(C_YELLOW)Cleaning coverage$(C_RESET)"
171 $(SILENT) rm -rf $(COVERAGE_DIR)
172 $(SILENT) rm -rf .coverage
173 @echo -e "$(C_GREEN)Coverage cleaned$(C_RESET)"
174
175# Proceed to removing the python environement
176fclean_env: clean_env
177
178# Proceed to a full environement wipe (
179# ex: usefull when changing python version
180# )
181fclean: clean clean_coverage
182 $(SILENT) rm -vf $(BINARY_DESTINATION_ONE)$(NAME)
183 $(SILENT) rm -vf $(BINARY_DESTINATION_TWO)$(NAME)
184
185# Run the tests for the programs
186tests_run: install_dependencies
187 @echo -e "$(C_RED)Running unit tests$(C_RESET)"
188# Updating the path for python to find the imports
189 $(SILENT) export PYTHONPATH=.:$$PYTHONPATH; \
190 . ./$(ENV_NAME)/bin/activate && \
191 $(CC) -m unittest discover -s $(TEST_DIR)
192 @echo -e "$(C_RED)Unit tests $(C_GREEN)run$(C_RESET)"
193
194# Check the coverage for the programs
195coverage: install_dependencies
196 @echo -e "$(C_CYAN)Generating coverage report$(C_RESET)"
197 $(SILENT) mkdir -p $(COVERAGE_DIR)
198 $(SILENT) . ./$(ENV_NAME)/bin/activate && \
199 \
200 coverage run --data-file $(COVERAGE_DIR)/report.coverage \
201 -m unittest discover -s $(TEST_DIR) && \
202 \
203 coverage run --branch --data-file $(COVERAGE_DIR)/branch_report.coverage \
204 -m unittest discover -s $(TEST_DIR) && \
205 \
206 coverage report \
207 --data-file $(COVERAGE_DIR)/report.coverage > \
208 $(COVERAGE_DIR)/report.txt && \
209 \
210 coverage report \
211 --data-file $(COVERAGE_DIR)/branch_report.coverage > \
212 $(COVERAGE_DIR)/branch_report.txt && \
213 \
214 cat $(COVERAGE_DIR)/report.txt && \
215 cat $(COVERAGE_DIR)/branch_report.txt && \
216 \
217 coverage html --directory $(COVERAGE_DIR)/html_report \
218 --data-file=$(COVERAGE_DIR)/report.coverage && \
219 \
220 coverage html --directory $(COVERAGE_DIR)/branch_html_report \
221 --data-file=$(COVERAGE_DIR)/branch_report.coverage
222 @echo -e "$(C_CYAN)Coverage report $(C_GREEN)generated$(C_RESET)"
223
224# Create the debug versions for the program (no idea what to put in it)
225
226debug: all
227
228# Rule to re-build everything
229
230re: fclean all
231
232# Clean the slate, remove the environement and start anew
233my_re: fclean fclean_env my_all
234
235# Disable silent build
236noisy:
237 @echo -e "$(C_PINK)Silent mode is $(C_RED)inactive$(C_RESET)"
238 $(eval SILENT=)
239 $(eval LOG_LEVEL=INFO)
240
241# This is a no operation function, it is used
242# by the parent makefile for silent builds
243noop:
244 @echo -e "$(C_PINK)Silent mode is $(C_GREEN)active$(C_RESET)"
245 $(eval SILENT=@)
246 $(eval LOG_LEVEL=WARN)
247
248silent: noop
249
250run: clean install_dependencies
251 $(SILENT) echo -e "$(C_CYAN) Activating environement $(C_RESET)" && \
252 . ./$(ENV_NAME)/bin/activate && \
253 echo -e "$(C_CYAN) Starting program $(C_RESET)" && \
254 $(CC) $(SRC_DIR)/main.py && \
255 deactivate && \
256 echo -e "$(C_CYAN) Environement deactivated $(C_RESET)"
257
258# The .PHONY to to avoid functions being overridden
259
260.PHONY: all create_environement install_dependencies activate_environement \
261 activate build_binary update_binary_location clean clean_env \
262 clean_coverage fclean tests_run coverage debug re noop silent run \
263 my_all fclean_env my_re