2## EPITECH PROJECT, 2024
8# The variables in charge of tracking the files for the program
11SRC = $(SRC_DIR)/server_main.py
13# Coverage report location
15COVERAGE_DIR = ./coverage_data
21# Level precision of the build process
25# The name of the python environement that will be used
29# The location in which the dependencies used during the build process
32BUILD_LOCATION = ./build/
34# The location of the final built binary
36BINARY_LOCATION = ./dist/
38# The desired destinations for the binary
40BINARY_DESTINATION_ONE = ./
42BINARY_DESTINATION_TWO = ../../../
44# The python binary that is available on the system
46CC = $(shell command -v python3 2>/dev/null || \
47 command -v python 2>/dev/null || \
48 command -v py 2>/dev/null \
51# Break the code if no python instance was found
54 $(error Python interpreter not found. Please install Python.)
57# Search for pip version
58MY_PIP_BIN = pip # Please update it manually {the automation check seems to break the environment}
60# Break the code if no python instance was found
63 $(error Pip interpreter not found. Please install a pip interpreter.)
66# Silence the outputs we wish not to listen to
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)
81all: build_binary update_binary_location
83# This is the all in one version of the setup
84omega: create_environement install_dependencies all
86# Create the python environement
88 @echo -e "$(C_CYAN)Creating python environment$(C_RESET)"
89 $(SILENT) $(CC) -m venv $(ENV_NAME)
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 && \
97 $(MY_PIP_BIN) list && \
98 echo -e "$(C_CYAN)Installing python dependencies$(C_RESET)" &&\
99 $(MY_PIP_BIN) install -r requirements.txt
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
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" && \
112 echo "Environement deactivated" && \
113 echo "Exit code: $$STATUS" && \
116activate: activate_environement
118# Build the python code as a binary
120 @echo -e "$(C_BLUE)Building binary '$(C_YELLOW)$(NAME)$(C_BLUE)'$(C_RESET)"
121 $(SILENT) . ./$(ENV_NAME)/bin/activate && \
124 --workpath $(BUILD_LOCATION) --distpath $(BINARY_LOCATION) \
125 --onefile --noconfirm \
127 --log-level=$(LOG_LEVEL) \
129 @echo -ne "$(C_BLUE)Binary '$(C_YELLOW)$(NAME)$(C_BLUE)' "
130 @echo -e "$(C_GREEN)built$(C_RESET)"
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)"
139# This is a rebind for the main makefile
140build: build_binary update_binary_location
143# Clean the cache projects
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)"
156# Clean the binaries produced
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)"
164# Clean the coverage produced
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)"
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)"
182# Proceed to a full environement wipe (
183# ex: usefull when changing python version
185fclean: clean clean_coverage
186 $(SILENT) rm -vf $(BINARY_DESTINATION_ONE)$(NAME)
187 $(SILENT) rm -vf $(BINARY_DESTINATION_TWO)$(NAME)
189# Function in charge of doing a full clean
190ffclean: fclean clean_env clean_docker
192# Run the tests for the programs
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 && \
199 @echo -e "$(C_RED)Unit tests $(C_GREEN)run$(C_RESET)"
201# Check the coverage for the programs
203 @echo -e "$(C_CYAN)Generating coverage report$(C_RESET)"
204 $(SILENT) mkdir -p $(COVERAGE_DIR)
205 $(SILENT) . ./$(ENV_NAME)/bin/activate && \
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 && \
209 coverage report --data-file=$(COVERAGE_DIR)/.coverage > $(COVERAGE_DIR)/report.txt && \
210 cat $(COVERAGE_DIR)/report.txt && \
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 && \
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)"
218# Create the debug versions for the program (no idea what to put in it)
222# Rule to re-build everything
226# Disable silent build
228 @echo -e "$(C_PINK)Silent mode is $(C_RED)inactive$(C_RESET)"
230 $(eval LOG_LEVEL=INFO)
232# This is a no operation function, it is used
233# by the parent makefile for silent builds
235 @echo -e "$(C_PINK)Silent mode is $(C_GREEN)active$(C_RESET)"
237 $(eval LOG_LEVEL=WARN)
241# The source code in production mode
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 && \
248 echo -e "$(C_CYAN) Environement deactivated $(C_RESET)"
250# Run the source code in production mode
253# The .PHONY to to avoid functions being overridden
256 all omega create_environement install_dependencies activate_environement \
258 build build_binary update_binary_location \
259 clean clean_env clean_coverage clean_docker \