Last active
July 24, 2024 09:17
-
-
Save Shuyib/ae87774fd82c69706803725db9a681dc to your computer and use it in GitHub Desktop.
Data science and Machine learning Makefile for Python projects or in general :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Thank you @Earthly https://www.youtube.com/watch?v=w2UeLF7EEwk | |
# Can be adapted to pipenv, and poetry | |
# Other languages coming soon especially R and Julia | |
# .ONESHELL tells make to run each recipe line in a single shell | |
.ONESHELL: | |
# .DEFAULT_GOAL tells make which target to run when no target is specified | |
.DEFAULT_GOAL := all | |
# Specify python location in virtual environment | |
# Specify pip location in virtual environment | |
PYTHON := .venv/bin/python3 | |
PIP := .venv/bin/pip3 | |
DOCKER_CONTAINER_NAME := test_app:v0.0.0 | |
venv/bin/activate: requirements.txt | |
# create virtual environment | |
python3 -m venv .venv | |
# make command executable | |
chmod +x .venv/bin/activate | |
# activate virtual environment | |
. .venv/bin/activate | |
activate: | |
# activate virtual environment | |
. .venv/bin/activate | |
install: venv/bin/activate requirements.txt # prerequisite | |
# install commands | |
$(PIP) --no-cache-dir install --upgrade pip &&\ | |
$(PIP) --no-cache-dir install -r requirements.txt | |
docstring: activate | |
# format docstring | |
pyment -w -o numpydoc *.py | |
format: activate | |
# format code | |
black *.py utils/*.py testing/*.py | |
clean: | |
# clean directory of cache | |
rm -rf __pycache__ &&\ | |
rm -rf utils/__pycache__ &&\ | |
rm -rf testing/__pycache__ &&\ | |
rm -rf .pytest_cache &&\ | |
rm -rf .venv | |
lint: activate install format | |
# flake8 or #pylint | |
pylint --disable=R,C --errors-only *.py utils/*.py testing/*.py | |
setup_readme: ## Create a README.md | |
@if [ ! -f README.md ]; then \ | |
echo "# Project Name\n\ | |
Description of the project.\n\n\ | |
## Installation\n\ | |
- Step 1\n\ | |
- Step 2\n\n\ | |
## Usage\n\ | |
Explain how to use the project here.\n\n\ | |
## Contributing\n\ | |
Explain how to contribute to the project.\n\n\ | |
## License\n\ | |
License information." > README.md; \ | |
echo "README.md created."; \ | |
else \ | |
test: activate install format | |
# test | |
$(PYTHON) -m pytest testing/*.py | |
run: activate install format lint | |
# run application | |
# example $(PYTHON) app.py | |
docker_build: Dockerfile | |
# build container | |
#docker build -t plot-timeseries-app:v0 . | |
docker_run_test: Dockerfile | |
# linting Dockerfile | |
docker run --rm -i hadolint/hadolint < Dockerfile | |
docker_clean: Dockerfile | |
# remove dangling images, containers, volumes and networks | |
docker system prune -a | |
docker_run: Dockerfile docker_build | |
# run docker | |
# docker run -e ENDPOINT_URL -e SECRET_KEY -e SPACES_ID -e SPACES_NAME plot-timeseries-app:v0 | |
docker_push: docker_build | |
# push to registry | |
# docker tag <my-image> registry.digitalocean.com/<my-registry>/<my-image> | |
# docker push registry.digitalocean.com/<my-registry>/<my-image> | |
# .PHONY tells make that these targets do not represent actual files | |
.PHONY: activate format clean lint test build run docker_build docker_run docker_push docker_clean docker_run_test | |
all: install format lint test run docker_build docker_run docker_push |
An attempt for java script
# Thank you @Earthly https://www.youtube.com/watch?v=w2UeLF7EEwk
# Can be adapted to pipenv, and poetry
# Other languages coming soon especially R and Julia
# .ONESHELL tells make to run each recipe line in a single shell
.ONESHELL:
# .DEFAULT_GOAL tells make which target to run when no target is specified
.DEFAULT_GOAL := all
# Specify node location in virtual environment
NODE := node
# Specify npm location in virtual environment
NPM := npm
# Specify Docker container name
DOCKER_CONTAINER_NAME := test_app:v0.0.0
venv/bin/activate: requirements.txt
# create virtual environment
npm install -g venv
# make command executable
chmod +x venv/bin/activate
# activate virtual environment
. venv/bin/activate
activate:
# activate virtual environment
. venv/bin/activate
install: venv/bin/activate requirements.txt # prerequisite
# install commands
npm install --no-cache-dir --upgrade npm &&\
npm install -r requirements.txt
docstring: activate
# format docstring
javascriptdoc -w -o numpydoc *.js
format: activate
# format code
prettier --write *.js utils/*.js testing/*.js
clean:
# clean directory of cache
rm -rf __pycache__ &&\
rm -rf utils/__pycache__ &&\
rm -rf testing/__pycache__ &&\
rm -rf .pytest_cache &&\
rm -rf .venv
lint: activate install format
# eslint or #jshint
eslint --fix --ignore-path .gitignore *.js utils/*.js testing/*.js
setup_readme: ## Create a README.md
@if [ ! -f README.md ]; then \
echo "# Project Name\n\
Description of the project.\n\n\
## Installation\n\
- Step 1\n\
- Step 2\n\n\
## Usage\n\
Explain how to use the project here.\n\n\
## Contributing\n\
Explain how to contribute to the project.\n\n\
## License\n\
License information." > README.md; \
echo "README.md created."; \
else \
test: activate install format
# test
npm test
run: activate install format lint
# run application
# example node app.js
docker_build: Dockerfile
# build container
docker build -t plot-timeseries-app:v0 .
docker_run_test: Dockerfile
# linting Dockerfile
docker run --rm -i hadolint/hadolint < Dockerfile
docker_clean: Dockerfile
# remove dangling images, containers, volumes and networks
docker system prune -a
docker_run: Dockerfile docker_build
# run docker
# docker run -e ENDPOINT_URL -e SECRET_KEY -e SPACES_ID -e SPACES_NAME plot-timeseries-app:v0
docker_push: docker_build
# push to registry
# docker tag <my-image> registry.digitalocean.com/<my-registry>/<my-image>
# docker push registry.digitalocean.com/<my-registry>/<my-image>
# .PHONY tells make that these targets do not represent actual files
.PHONY: activate format clean lint test build run docker_build docker_run docker_push docker_clean docker_run_test
all: install format lint test run docker_build docker_run docker_push
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Template for Julia needs edits