|
| 1 | +# .PHONY defines parts of the makefile that are not dependant on any specific file |
| 2 | +# This is most often used to store functions |
| 3 | +.PHONY = help install test run |
| 4 | + |
| 5 | +# Defines the default target that `make` will to try to make, or in the case of a phony target, execute the specified commands |
| 6 | +# This target is executed whenever we just type `make` |
| 7 | +.DEFAULT_GOAL = help |
| 8 | + |
| 9 | +# Server status evaluation |
| 10 | +SERVER_PID := $(shell sh -c "ps | grep -v grep | grep 'src/main.py' | head -1 | cut -d \t -f1") |
| 11 | +ifeq ('$(strip $(SERVER_PID))','') |
| 12 | + SERVER_RUNNING=FALSE |
| 13 | +else |
| 14 | + SERVER_RUNNING=TRUE |
| 15 | +endif |
| 16 | + |
| 17 | +CHILD_PID := $(shell sh -c "ps -ax | grep -i spawn_main | grep -v grep | cut -d ' ' -f1") |
| 18 | +ifeq ('$(strip $(CHILD_PID))','') |
| 19 | + HAVE_CHILD=FALSE |
| 20 | +else |
| 21 | + HAVE_CHILD=TRUE |
| 22 | +endif |
| 23 | + |
| 24 | + |
| 25 | +# The @ makes sure that the command itself isn't echoed in the terminal |
| 26 | +help: |
| 27 | + @echo "---------------HELP-----------------" |
| 28 | + @echo "- Setup the project : make install" |
| 29 | + @echo "- Run the server (blocking): make start" |
| 30 | + @echo "- Evaluate status of the server : make status" |
| 31 | + @echo "- Stop (killp) the server : make kill" |
| 32 | + @echo "- Run tests on a running server: make tests" |
| 33 | + @echo "------------------------------------" |
| 34 | + |
| 35 | +install: |
| 36 | + @poetry install |
| 37 | + |
| 38 | +status: |
| 39 | + @date |
| 40 | + @echo "Running status of server is $(SERVER_RUNNING)" |
| 41 | + @echo "Running status of child runners is $(HAVE_CHILD)" |
| 42 | + |
| 43 | +do_stop_server: |
| 44 | + @-kill -9 $(SERVER_PID) |
| 45 | +do_stop_children: |
| 46 | + @-kill -9 $(CHILD_PID) |
| 47 | +kill: status do_stop_server do_stop_children |
| 48 | + @echo "Killing server on PID $(SERVER_PID) and children on PID $(CHILD_PID)" |
| 49 | + @-lsof -i tcp:5000 |
| 50 | + |
| 51 | +tail: |
| 52 | + @tail run.log |
| 53 | + |
| 54 | +do_start: |
| 55 | + @poetry run python src/main.py >run.log 2>&1 & |
| 56 | + @$(shell sleep 3) |
| 57 | +start: do_start |
| 58 | + @echo Check run.log for logging |
| 59 | + |
| 60 | + |
| 61 | +tests: install |
| 62 | + @poetry run pytest |
| 63 | + |
| 64 | +serve: |
| 65 | + @poetry run mkdocs serve |
| 66 | + |
| 67 | +publish: |
| 68 | + @poetry run mkdocs gh-deploy |
| 69 | + |
0 commit comments