Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common Makefile rules, basic direnv / asdf setup #41

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions {{cookiecutter.project_slug}}/.env.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Add any project-wide default values here. Note that they should still
# be valid values, so not examples like EMAIL=myusername@mydomain, those should
# be specied elsewhere like in user-local .env file.
3 changes: 3 additions & 0 deletions {{cookiecutter.project_slug}}/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# this if config file for https://asdf-vm.com/
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that nothing would require use of asdf, but it would provide more convenient flow for those who use it

# which can be used to install hundreds of tools at specific version
poetry 1.7.1
18 changes: 18 additions & 0 deletions {{cookiecutter.project_slug}}/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
include tools/make/*.mk
# please keep any rules idempotent if possible.
# NOTE: whenever useful, we'll use sentinel pattern with .make- prefix to avoid unnecessary work

# please keep dev-setup idempotent
dev-setup: deps

# use 'make -B deps' to force execution of rule
# `make deps` allows us to absract details of package manager without changing developer flow or github actions
deps: .make-dev-deps

# this should install all dependencies, and only those mentioned in the lock file
# Note that rule should be idempotent and return immediately if there's nothing to do, so that
# eg. test can depend on this. Strictly speaking this depends on 'pyproject.toml' too, but often those changes
# are not relevant to dependencies and user can always do `make -B <rule> to force rebuild`
.make-dev-deps: poetry.lock
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might seem unnecessarily complex to have rule for just poetry install --sync, but like with many other rules, idea is to create trivial to use abstractions, so that it is easier to change tools afterwards without other needed changes

poetry install --sync
touch $@
12 changes: 12 additions & 0 deletions {{cookiecutter.project_slug}}/sample.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Read .envrc settings in parent dirs if present
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cf before. direnv would not be required, but provided here as sample file

source_up

# See https://github.com/direnv/direnv/wiki/Python#poetry to activate Poetry automatically
layout_poetry

# first load defaults and then apply any custom env vars if present, overriding defaults
dotenv .env.defaults
dotenv_if_exists .env

# add any tools/scripts to the path
PATH_add tools
57 changes: 57 additions & 0 deletions {{cookiecutter.project_slug}}/tools/make/Common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# use sane shell by default, as well as other settings
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables --no-builtin-rules
.DEFAULT_GOAL = help

# location for source files
SRC ?= src/

# Hack to make help rule work, given that rule has suffix ' ## <help text'.
# Minor adjustments to make it work properly with included files
.PHONY: help
help: ## This help dialog
@grep -hE '^[a-zA-Z-][a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort -u -t: -k1,1 | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-22s\033[0m %s\n", $$1, $$2}'

.PHONY: grep-tech-debt
grep-tech-debt: ## Grep for lines with various types of tech debt
@echo "### ❗Checking for FIXMEs"
@git grep --line-number --ignore-case --extended-regexp '# (fixme|xxx)' $(SRC) || echo "No FIXMEs ✅"
@echo "### 🚧 Silenced issues"
@git grep --line-number --ignore-case --extended-regexp '# (noqa|type: ignore|xxx)' $(SRC) || echo "No silenced issues ✅"
@echo "### 🚧 TODOs"
@git grep --line-number --ignore-case --extended-regexp '# (todo|tbd)' $(SRC) || echo "No TODOs ✅"

######################################################################################################
# Common rules which probably should be present regardless of technologies, but implemented
# in specific files or root Makefile. Avoid modifying this file, because it would be updated by the template
#
# Note that specifying .PHONY here means actual implementation
# needs only rule body (repeating .PHONY is not needed)
######################################################################################################

.PHONY: deps
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option would be to comment these by default, so that rules that are not implemented are not visible with make help

deps: ## Set installed dependencies (including dev) to match those in the lock file

.PHONY: build
build: ## Build project and/or container image(s)

.PHONY: build-dev
build-dev: ## Build project and/or container image(s) for local development/testing

# this rule should do asdf install, setup .envrc etc, anything that helps new devs in getting started
.PHONY: dev-setup
dev-setup: ## Prepare project ready for local development

.PHONY: fmt
fmt: ## Apply all automated formatters

.PHONY: release
release: ## Create new release

.PHONY: test
test: ## Run automated tests

.PHONY: lint
lint: ## Analyze code for issues/smells