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