Skip to content

Commit 17e1725

Browse files
author
Shane Borden
committed
update make process
1 parent 253cf18 commit 17e1725

File tree

4 files changed

+158
-19
lines changed

4 files changed

+158
-19
lines changed

Makefile

Lines changed: 89 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
1+
SHELL := /bin/bash
2+
3+
# -----------------------------------------------------------------------------
4+
# Display Formatting and Colors
5+
# -----------------------------------------------------------------------------
6+
BLUE := $(shell printf "\033[1;34m")
7+
GREEN := $(shell printf "\033[1;32m")
8+
RED := $(shell printf "\033[1;31m")
9+
YELLOW := $(shell printf "\033[1;33m")
10+
NC := $(shell printf "\033[0m")
11+
INFO := $(shell printf "$(BLUE)$(NC)")
12+
OK := $(shell printf "$(GREEN)$(NC)")
13+
WARN := $(shell printf "$(YELLOW)$(NC)")
14+
ERROR := $(shell printf "$(RED)$(NC)")
15+
16+
# =============================================================================
17+
# Configuration and Environment Variables
18+
# =============================================================================
119
.DEFAULT_GOAL:=help
220
.ONESHELL:
3-
VENV_EXISTS=$(shell python3 -c "if __import__('pathlib').Path('.venv/bin/activate').exists(): print('yes')")
4-
VERSION := $(shell grep -m 1 current_version .bumpversion.cfg | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3)
5-
BUILD_DIR=dist
6-
COLLECTOR_PACKAGE=sql-scripts
7-
BASE_DIR=$(shell pwd)
8-
21+
.EXPORT_ALL_VARIABLES:
22+
MAKEFLAGS += --no-print-directory
23+
24+
USING_NPM = $(shell python3 -c "if __import__('pathlib').Path('package-lock.json').exists(): print('yes')")
25+
ENV_PREFIX =.venv/bin/
26+
VENV_EXISTS = $(shell python3 -c "if __import__('pathlib').Path('.venv/bin/activate').exists(): print('yes')")
27+
NODE_MODULES_EXISTS = $(shell python3 -c "if __import__('pathlib').Path('node_modules').exists(): print('yes')")
28+
BUILD_DIR =dist
29+
COLLECTOR_PACKAGE =sql-scripts
30+
BASE_DIR =$(shell pwd)
31+
932
.EXPORT_ALL_VARIABLES:
1033

1134
ifndef VERBOSE
@@ -15,15 +38,46 @@ endif
1538
REPO_INFO ?= $(shell git config --get remote.origin.url)
1639
COMMIT_SHA ?= git-$(shell git rev-parse --short HEAD)
1740

41+
# =============================================================================
42+
# Help and Documentation
43+
# =============================================================================
44+
1845
help: ## Display this help
1946
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
2047

21-
.PHONY: install
48+
# =============================================================================
49+
# Developer Utils
50+
# =============================================================================
51+
install-pipx: ## Install pipx
52+
@python3 -m pip install --upgrade --user pipx
53+
54+
install-hatch: ## Install Hatch, UV, and Ruff
55+
@sh ./tools/install-hatch.sh
56+
57+
configure-hatch: ## Configure Hatch defaults
58+
@hatch config set dirs.env.virtual .direnv
59+
@hatch config set dirs.env.pip-compile .direnv
60+
61+
upgrade-hatch: ## Update Hatch, UV, and Ruff
62+
@hatch self update
63+
2264
install: ## Install the project in dev mode.
23-
@if [ "$(VENV_EXISTS)" ]; then source .venv/bin/activate; fi
24-
@if [ ! "$(VENV_EXISTS)" ]; then python3 -m venv .venv && source .venv/bin/activate; fi
25-
.venv/bin/pip install -U wheel setuptools cython pip mypy sqlfluff && .venv/bin/pip install -U -r requirements.txt -r requirements-docs.txt
26-
@echo "=> Build environment installed successfully. ** If you want to re-install or update, 'make install'"
65+
@if [ "$(VENV_EXISTS)" ]; then echo "=> Removing existing virtual environment"; $(MAKE) destroy-venv; fi
66+
@$(MAKE) clean
67+
@if ! hatch --version > /dev/null; then echo '=> Installing `hatch`'; $(MAKE) install-hatch ; fi
68+
@echo "=> Creating Python environments..."
69+
@$(MAKE) configure-hatch
70+
@hatch env create local
71+
@echo "=> Install complete! Note: If you want to re-install re-run 'make install'"
72+
# .venv/bin/pip install -U wheel setuptools cython pip mypy sqlfluff && .venv/bin/pip install -U -r requirements.txt -r requirements-docs.txt
73+
74+
.PHONY: upgrade
75+
upgrade: ## Upgrade all dependencies to the latest stable versions
76+
@echo "=> Updating all dependencies"
77+
@echo "=> Python Dependencies Updated"
78+
@hatch run lint:pre-commit autoupdate
79+
@echo "=> Updated Pre-commit"
80+
@$(MAKE) install
2781

2882
.PHONY: clean
2983
clean: ## Cleanup temporary build artifacts
@@ -38,6 +92,21 @@ clean: ## Cleanup temporary build a
3892
@find . -name '.ipynb_checkpoints' -exec rm -rf {} + >/dev/null 2>&1
3993
@echo "${OK} Working directory cleaned"
4094

95+
deep-clean: clean destroy-venv destroy-node_modules ## Clean everything up
96+
@hatch python remove all
97+
@echo "=> Hatch environments pruned and python installations trimmed"
98+
@uv cache clean
99+
@echo "=> UV Cache cleaned successfully"
100+
101+
destroy-venv: ## Destroy the virtual environment
102+
@hatch env prune
103+
@hatch env remove lint
104+
@rm -Rf .venv
105+
@rm -Rf .direnv
106+
107+
destroy-node_modules: ## Destroy the node environment
108+
@rm -rf node_modules .astro
109+
41110
.PHONY: clean-sqlscripts
42111
clean-sqlscripts:
43112
@echo "=> Cleaning previous build artifacts for sql scripts..."
@@ -94,6 +163,14 @@ package-sqlscripts:
94163
.PHONY: build
95164
build: build-sqlscripts ## Build and package the collectors
96165

166+
.PHONY: pre-release
167+
pre-release: ## bump the version and create the release tag
168+
make docs
169+
make clean
170+
hatch run local:bump2version $(increment)
171+
head .bumpversion.cfg | grep ^current_version
172+
make build
173+
97174

98175
###############
99176
# docs #
@@ -123,10 +200,4 @@ docs: ## generate HTML documentation and serve it to the browser
123200
./.venv/bin/mkdocs build
124201
./.venv/bin/mkdocs serve
125202

126-
.PHONY: pre-release
127-
pre-release: ## bump the version and create the release tag
128-
make gen-docs
129-
make clean
130-
.venv/bin/bump2version $(increment)
131-
head .bumpversion.cfg | grep ^current_version
132-
make build
203+

site/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,5 @@ <h4 class="modal-title" id="keyboardModalLabel">Keyboard Shortcuts</h4>
206206

207207
<!--
208208
MkDocs version : 1.6.1
209-
Build Date UTC : 2025-04-25 19:16:19.425824+00:00
209+
Build Date UTC : 2025-09-18 15:17:47.666795+00:00
210210
-->

site/sitemap.xml.gz

0 Bytes
Binary file not shown.

tools/install-hatch.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2025 shane-borden
3+
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# --- Constants ---
16+
BASE_URL="https://github.com/pypa/hatch/releases/latest/download"
17+
EXTRACT_CMD="tar -xzf"
18+
19+
# --- Handle Optional Installation Directory ---
20+
INSTALL_DIR="$1" # Default: current directory
21+
if [ -n "$INSTALL_DIR" ]; then
22+
if [ ! -d "$INSTALL_DIR" ]; then # Check if directory exists
23+
INSTALL_DIR="$HOME/.local/bin"
24+
echo "Error: Invalid install directory '$INSTALL_DIR'"
25+
exit 1
26+
fi
27+
INSTALL_DIR=$(realpath "$INSTALL_DIR") # Get absolute path
28+
fi
29+
30+
# --- Determine Platform ---
31+
PLATFORM=$(uname -s)
32+
MACHINE=$(uname -m)
33+
FILE_EXT="tar.gz"
34+
35+
if [ "$PLATFORM" = "Darwin" ]; then
36+
PLATFORM_NAME="apple-darwin"
37+
elif [ "$PLATFORM" = "Linux" ]; then
38+
PLATFORM_NAME="unknown-linux-gnu"
39+
if [ "$MACHINE" = "aarch64" ]; then
40+
MACHINE="aarch64"
41+
fi
42+
elif [ "$PLATFORM" = "Windows" ]; then
43+
PLATFORM_NAME="pc-windows-msvc"
44+
FILE_EXT="zip"
45+
EXTRACT_CMD="unzip"
46+
else
47+
echo "Unsupported platform: $PLATFORM"
48+
exit 1
49+
fi
50+
51+
# --- Construct File Name and URL ---
52+
FILENAME="hatch-$MACHINE-$PLATFORM_NAME.$FILE_EXT"
53+
URL="$BASE_URL/$FILENAME"
54+
55+
# --- Download and Extract ---
56+
echo "Downloading Hatch binary: $FILENAME"
57+
curl -L -o "$FILENAME" "$URL"
58+
59+
echo "Extracting to '$INSTALL_DIR'..."
60+
$EXTRACT_CMD "$FILENAME" -C "$INSTALL_DIR" # Extract to install directory
61+
rm "$FILENAME" # Remove archive
62+
63+
HATCH_BINARY="$INSTALL_DIR/hatch" # Path to the extracted binary
64+
if [ -x "$HATCH_BINARY" ]; then
65+
echo "Hatch binary successfully installed at '$HATCH_BINARY'"
66+
else
67+
echo "Error: Hatch binary not found or not executable."
68+
fi

0 commit comments

Comments
 (0)