Enhance and clean Makefile
- Use .ONESHELL to use the same shell for a single goal. This allows to stay in a venv without dirty (cmd; \ cmd; \) hacks. - Replace /usr/bin/env bash with bash, as it doesn't work with .ONESHELL. - Use make targets dependencies to check it was reached. - Simplify help generator and make help comment obvious.
This commit is contained in:
		
							parent
							
								
									4185f44164
								
							
						
					
					
						commit
						c062523c62
					
				
							
								
								
									
										41
									
								
								Makefile
								
								
								
								
							
							
						
						
									
										41
									
								
								Makefile
								
								
								
								
							|  | @ -1,30 +1,31 @@ | ||||||
| VENV_DIR := .venv | VENV_DIR := .venv | ||||||
| SHELL := /usr/bin/env bash | SHELL := bash | ||||||
| .DEFAULT_GOAL := help | .DEFAULT_GOAL := help | ||||||
|  | .ONESHELL: | ||||||
| 
 | 
 | ||||||
| help: | help: | ||||||
| 	@grep -E '^[a-zA-Z1-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
 | 	@grep '^#?.*' $(MAKEFILE_LIST) \
 | ||||||
| 		| awk 'BEGIN { FS = ":.*?## " }; { printf "\033[36m%-30s\033[0m %s\n", $$1, $$2 }' | 	| awk -F ':' '{ $$1 = substr($$1, 4); printf "\033[36m%-30s\033[0m %s\n", $$1, $$2 }' | ||||||
| 
 | 
 | ||||||
| install: ## Install all necessary tools
 | $(VENV_DIR): | ||||||
| 	$(MAKE) \
 | 	$(shell command -v python3) -m venv $(VENV_DIR) | ||||||
| 		venv \
 |  | ||||||
| 		install-pip-packages |  | ||||||
| 	@echo -e "\n--> You should now activate the python3 venv with:" |  | ||||||
| 	@echo -e "source $(VENV_DIR)/bin/activate" |  | ||||||
| 
 | 
 | ||||||
| venv: ## Create python3 venv if it does not exists
 | #? install: Install all necessary tools
 | ||||||
| 	[[ -d $(VENV_DIR) ]] || $(shell command -v python3) -m venv $(VENV_DIR) | install: install-pip-packages | ||||||
|  | 	@$(info --> You should now activate the python3 venv with:) | ||||||
|  | 	@$(info source $(VENV_DIR)/bin/activate) | ||||||
| 
 | 
 | ||||||
| install-pip-packages: ## Install python3 requirements
 | #? install-pip-packages: Install python3 requirements
 | ||||||
| 	$(info --> Install requirements via `pip3`) | install-pip-packages: $(VENV_DIR) | ||||||
| 	@( \
 | 	@$(info --> Install requirements via `pip3`) | ||||||
| 			source $(VENV_DIR)/bin/activate; \
 | 	@source $(VENV_DIR)/bin/activate | ||||||
| 			pip3 install -r requirements.txt; \
 | 	@pip3 install -r requirements.txt | ||||||
| 	) |  | ||||||
| 
 | 
 | ||||||
| upgrade-pip-packages: ## Upgrade python3 requirements
 | #? upgrade-pip-packages: Upgrade python3 requirements
 | ||||||
| 	$(shell command -v pip3) -U -r requirements.txt | upgrade-pip-packages: $(VENV_DIR) | ||||||
|  | 	@source $(VENV_DIR)/bin/activate | ||||||
|  | 	@pip3 install --upgrade -r requirements.txt | ||||||
| 
 | 
 | ||||||
| clean: ## Clean venv
 | #? clean: Clean venv
 | ||||||
|  | clean: | ||||||
| 	[[ ! -d $(VENV_DIR) ]] || rm -rf $(VENV_DIR) | 	[[ ! -d $(VENV_DIR) ]] || rm -rf $(VENV_DIR) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue