Skip to content

Instantly share code, notes, and snippets.

@keuv-grvl
Created May 13, 2025 15:46
Show Gist options
  • Save keuv-grvl/edd2b7bf3a2be2c030716fe06cc7a013 to your computer and use it in GitHub Desktop.
Save keuv-grvl/edd2b7bf3a2be2c030716fe06cc7a013 to your computer and use it in GitHub Desktop.
Makefile for simple python project dev
# TODO: replace black&isort by ruff
# TODO: how does this work with pre-commit?
# TODO: autopep/autoflake, bumpversion, docker build/push
SRC_DIR = my_project # CHANGE THIS
all: setup format lint-quick
help:
@echo "# TODO: help message"
@echo " Available targets: all, help, setup, check, format, lint-quick, lint, security, test"
# Setup
_check-deps:
@echo " -- Checking for dependencies. You may need to run:"
@echo " $ pip install black isort pylint flake8 Flake8-pyproject ruff bandit pytest"
@pip freeze | grep "^black" > /dev/null 2> /dev/null
@pip freeze | grep "^isort" > /dev/null 2> /dev/null
@pip freeze | grep "^pylint" > /dev/null 2> /dev/null
@pip freeze | grep "^flake8" > /dev/null 2> /dev/null
@pip freeze | grep "^ruff" > /dev/null 2> /dev/null
@pip freeze | grep "^bandit" > /dev/null 2> /dev/null
@pip freeze | grep "^pytest" > /dev/null 2> /dev/null
_setup-hooks: .hooks/pre-commit .hooks/pre-push .git/
@echo "Installing Git hooks"
ln -srf .hooks/pre-commit .git/hooks/pre-commit
ln -srf .hooks/pre-push .git/hooks/pre-push
setup: _check-deps _setup-hooks
# Code format (checks only)
check-format: $(SRC_DIR) | pyproject.toml
@echo " -- Check code formatting"
black --check $(SRC_DIR)
check-sortimports: $(SRC_DIR) | pyproject.toml
@echo " -- Check import sorting"
isort --check $(SRC_DIR)
check: check-format check-sortimports
# Code format
sortimports: $(SRC_DIR) | pyproject.toml
@echo " -- Sorting imports"
isort $(SRC_DIR)
format: sortimports | pyproject.toml
@echo " -- Formatting code"
black $(SRC_DIR)
_lint-pylint-hard: $(SRC_DIR) | pyproject.toml
@echo " -- Linting with pylint (hard)"
pylint $(SRC_DIR)
_lint-pylint-soft: $(SRC_DIR) | pyproject.toml
@echo " -- Linting with pylint (error only)"
pylint --errors-only $(SRC_DIR)
_lint-flake8: $(SRC_DIR) | pyproject.toml
@echo " -- Linting with flake8"
flake8 $(SRC_DIR)
_lint-ruff: $(SRC_DIR) | pyproject.toml
@echo " -- Linting with ruff"
ruff $(SRC_DIR)
lint-quick: _lint-ruff
lint: _lint-ruff _lint-flake8 _lint-pylint-soft
# Security
_bandit-hard: $(SRC_DIR)
@echo " -- Security analysis with bandit (hard)"
bandit --recursive --quiet --severity-level all --confidence all $(SRC_DIR)
_bandit-soft: $(SRC_DIR)
@echo " -- Security analysis with bandit (soft)"
bandit --recursive --quiet --severity-level medium --confidence medium $(SRC_DIR)
security: _bandit-soft
# Tests
test:
@echo " -- Running tests"
@echo "TODO"
# Dist
dist: $(SRC_DIR)
@echo " -- Building dist"
python setup.py bdist_wheel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment