From 0661377bd6c4fb52315a2d409b6d93e2b23a245b Mon Sep 17 00:00:00 2001 From: Gretchen Miller Date: Wed, 5 Mar 2025 17:34:49 -0800 Subject: [PATCH] Makefile improvements + pre-commit hook --- .gitignore | 3 +++ Makefile | 46 +++++++++++++++++++++++++++++++++++++++++----- dev/pre-commit | 11 +++++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 dev/pre-commit diff --git a/.gitignore b/.gitignore index 174149f..631850d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ /brozzler.egg-info/ venv .idea + +# build artifacts +build/ diff --git a/Makefile b/Makefile index ae16af0..c421246 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,43 @@ +# Build constants +PYTHON_VERSION = 3.12 +VIRTUAL_ENV_DIR = .venv +BROZZLER_EGG_LINK = ./brozzler.egg-info +# Where's the Makefile running? Valid options: LOCAL, CI +ENV ?= LOCAL +# Which package manager to use? Valid options: UV, PIP +PACKAGE_MANAGER ?= UV + +$(VIRTUAL_ENV_DIR): +ifeq ($(PACKAGE_MANAGER),UV) + uv venv -p python$(PYTHON_VERSION) $@ +else ifeq ($(PACKAGE_MANAGER),PIP) + python$(PYTHON_VERSION) -m venv $@ +endif + +.PHONY: venv +venv: $(VIRTUAL_ENV_DIR) + +$(BROZZLER_EGG_LINK): $(VIRTUAL_ENV_DIR) pyproject.toml +ifeq ($(PACKAGE_MANAGER),UV) + VIRTUAL_ENV=$(shell pwd)/$(VIRTUAL_ENV_DIR) uv build +else ifeq ($(PACKAGE_MANAGER),PIP) + VIRTUAL_ENV=$(shell pwd)/$(VIRTUAL_ENV_DIR) pip wheel --no-deps --wheel-dir dist . +endif + +.PHONY: build +build: $(BROZZLER_EGG_LINK) + +.git/hooks/pre-commit: + ln -s $(realpath ./dev/pre-commit) $@ + +.PHONY: check +check: + $(VIRTUAL_ENV_DIR)/bin/ruff check --target-version py37 . + +.PHONY: check-format +check-format: + $(VIRTUAL_ENV_DIR)/bin/ruff format --check --target-version py37 . + .PHONY: format format: - venv/bin/ruff format --target-version py37 . - -.PHONY: ck-format -ck-format: - venv/bin/ruff format --check --target-version py37 . + $(VIRTUAL_ENV_DIR)/bin/ruff format --target-version py37 . diff --git a/dev/pre-commit b/dev/pre-commit new file mode 100644 index 0000000..c640966 --- /dev/null +++ b/dev/pre-commit @@ -0,0 +1,11 @@ + +#!/usr/bin/env bash + +set -euo pipefail + +# pre-commit.sh +# ------------- +# An optional script which runs checks on code before commits. + +make check +make check-format