-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathMakefile
More file actions
176 lines (149 loc) · 5.2 KB
/
Makefile
File metadata and controls
176 lines (149 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
# Function Stream API - Industrial Build System
# ==============================================================================
# --- 1. Configuration & Variables ---
# Project Metadata
PROJECT_NAME := functionstream-api
PACKAGE_NAME := fs_api
# Shell setup
SHELL := /bin/bash
.SHELLFLAGS := -eu -o pipefail -c
# Directory paths
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
current_dir := $(dir $(mkfile_path))
# [Standard Monorepo Roots]
# SCRIPT_DIR: Current directory (.../python/functionstream-api)
SCRIPT_DIR := $(current_dir)
# MONOREPO_ROOT: Grandparent directory (.../function-stream)
MONOREPO_ROOT := $(abspath $(current_dir)/../..)
# Output paths
DIST_DIR := $(SCRIPT_DIR)/dist
BUILD_DIR := $(SCRIPT_DIR)/build
# Virtual Environment (Shared)
VENV_DIR := $(MONOREPO_ROOT)/.venv
VENV_BIN := $(VENV_DIR)/bin
PYTHON := $(VENV_BIN)/python
PIP := $(VENV_BIN)/pip
TWINE := $(VENV_BIN)/twine
PYTEST := $(VENV_BIN)/pytest
# --- 2. Colors & Logging ---
ifneq ($(shell test -t 0; echo $$?),0)
color_reset :=
color_green :=
color_blue :=
color_red :=
color_yellow:=
else
color_reset := $(shell tput sgr0)
color_green := $(shell tput setaf 2)
color_blue := $(shell tput setaf 4)
color_red := $(shell tput setaf 1)
color_yellow:= $(shell tput setaf 3)
endif
define log_info
@echo "$(color_blue)[INFO]$(color_reset) $1"
endef
define log_success
@echo "$(color_green)[SUCCESS]$(color_reset) $1"
endef
define log_warn
@echo "$(color_yellow)[WARN]$(color_reset) $1"
endef
# --- 3. Targets ---
.PHONY: all help venv install-deps install install-dev build clean test publish info uninstall
# Default target
all: build
# Ensure venv exists (Check root)
$(PYTHON):
$(call log_warn, Virtual environment not found at $(VENV_DIR))
$(call log_info, Please run 'python3 -m venv .venv' in the Monorepo root first.)
@exit 1
venv: $(PYTHON)
# [FIX] Explicitly install build tools (Idempotent)
install-deps: venv
$(call log_info, Installing build dependencies...)
@$(PIP) install --upgrade pip setuptools wheel build twine pytest
@$(call log_success, Build dependencies installed.)
# Install package (Release simulation)
install: install-deps
$(call log_info, Installing $(PROJECT_NAME)...)
@$(PIP) install .
$(call log_success, Installation complete.)
# Install in editable mode (Development)
install-dev: install-deps
$(call log_info, Installing $(PROJECT_NAME) in editable mode...)
@$(PIP) install -e ".[dev]" || $(PIP) install -e .
$(call log_success, Editable installation complete.)
# Build Source and Wheel distribution
# [FIX] Added install-deps as a prerequisite
build: install-deps clean
$(call log_info, Building distribution artifacts...)
@$(PYTHON) -m build
$(call log_info, Checking artifacts with Twine...)
@$(TWINE) check dist/*
$(call log_success, Build complete. Artifacts in 'dist/'.)
# Publish to PyPI
publish: build
$(call log_warn, You are about to upload to PyPI.)
@$(TWINE) upload dist/*
# Run tests
test: install-deps
$(call log_info, Running tests...)
@if [ -d "tests" ]; then \
$(PYTEST) tests/ -v; \
else \
$(call log_warn, No 'tests' directory found. Skipping.); \
fi
# Deep clean
clean:
$(call log_info, Cleaning build artifacts...)
@rm -rf $(DIST_DIR) $(BUILD_DIR)
@rm -rf *.egg-info .eggs
@find . -type d -name "__pycache__" -exec rm -rf {} +
@find . -type d -name "*.egg-info" -exec rm -rf {} +
@find . -type d -name ".pytest_cache" -exec rm -rf {} +
@find . -type d -name ".coverage" -exec rm -rf {} +
@find . -type f -name "*.pyc" -delete
@find . -type f -name "*.pyo" -delete
$(call log_success, Clean complete.)
# Uninstall
uninstall:
$(call log_info, Uninstalling $(PROJECT_NAME)...)
@$(PIP) uninstall -y $(PROJECT_NAME) || true
$(call log_success, Uninstallation complete.)
# Info
info: venv
@echo "$(color_blue)Project Info:$(color_reset)"
@echo " Name: $(PROJECT_NAME)"
@echo " Package: $(PACKAGE_NAME)"
@echo " Venv: $(VENV_DIR)"
@echo " Python: $(shell $(PYTHON) --version)"
@echo ""
@echo "$(color_blue)Installed Packages:$(color_reset)"
@$(PIP) list | grep -E "build|wheel|twine|$(PROJECT_NAME)"
# Help
help:
@echo "$(color_blue)$(PROJECT_NAME) Build System$(color_reset)"
@echo "Usage: make <target>"
@echo ""
@echo "Targets:"
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^# (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf " $(color_green)%-15s$(color_reset) %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)