# Generated by `forktex fsd makefile sync`
# Unit: root project
PROJECT_NAME := forktex-core
SUBPACKAGES :=
PUBLISHABLE_PACKAGES := .

format: ## Source code conforms to a consistent, auto-enforced style
	ruff format src/ tests/
	@for pkg in $(SUBPACKAGES); do \
		echo "  Formatting $$pkg..."; \
		ruff format $$pkg/src/ $$pkg/tests/ 2>/dev/null || true; \
	done

lint: ## Static analysis catches bugs, anti-patterns, and security issues
	ruff check src/ tests/
	@for pkg in $(SUBPACKAGES); do \
		echo "  Linting $$pkg..."; \
		ruff check $$pkg/src/ $$pkg/tests/ 2>/dev/null || true; \
	done

typecheck: ## Static type system verifies interface correctness
	python -m pyright src/ 2>/dev/null || python -m mypy src/

test: ## Automated tests verify behavior against real infrastructure
	@if find tests -name 'test_*.py' -print -quit | grep -q .; then pytest tests/ -q; else echo 'forktex-core: no tests yet (skipping)'; fi

audit: ## Dependencies scanned for known vulnerabilities
	pip-audit 2>/dev/null || echo "pip-audit not installed, skipping"

license-check: ## Source headers and dependency licenses verified
	@echo "TODO: implement license for $(PROJECT_NAME)"

deps: ## Project dependencies installed and locked to reproducible versions
	pip install --break-system-packages -e . 2>/dev/null || \
	pip install -e .

ci: ## Aggregate quality gate: format + lint + test + audit
	@$(MAKE) format-check lint test
	@echo "CI passed for $(PROJECT_NAME)"

start: ## Project runtime starts with one command
	@$(MAKE) deps
	@echo ""
	@echo "$(PROJECT_NAME) runtime ready."
	@echo "  Run: forktex --version"
	@echo "  Run: make test"
	@echo ""

stop: ## Project runtime stops cleanly
	@echo "$(PROJECT_NAME) has no managed long-running runtime to stop."

logs: ## Runtime logs observable through one command
	@echo "$(PROJECT_NAME) has no managed runtime logs to stream."

build: ## Software artifacts built (Docker image, bundle, binary)
	@for pkg in $(PUBLISHABLE_PACKAGES); do \
		echo "Building $$pkg..."; \
		cd $$pkg && rm -rf dist/ && python3 -m build && cd ..; \
	done
	@echo "All packages built."

publish: ## Artifacts published to registry, CDN, or store
	@for pkg in $(PUBLISHABLE_PACKAGES); do \
		echo "Publishing $$pkg..."; \
		cd $$pkg && rm -rf dist/ && python3 -m build && twine upload dist/* && cd ..; \
	done
	@echo "All packages published."

clean: ## Build artifacts and caches removable
	find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null; true
	find . -type d -name .pytest_cache -exec rm -rf {} + 2>/dev/null; true
	find . -type d -name .ruff_cache -exec rm -rf {} + 2>/dev/null; true
	find . -type d -name .mypy_cache -exec rm -rf {} + 2>/dev/null; true
	find . -type d -name dist -exec rm -rf {} + 2>/dev/null; true
	find . -type d -name build -exec rm -rf {} + 2>/dev/null; true
	find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null; true
	find . -type d -name htmlcov -exec rm -rf {} + 2>/dev/null; true
	find . -type f -name .coverage -delete 2>/dev/null; true

help: ## Available targets self-documented
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
		awk 'BEGIN {FS = ":.*?## "}; {printf "  \033[36m%-22s\033[0m %s\n", $$1, $$2}'

format-check: ## Check formatting without rewriting files
	ruff format --check src/ tests/
	@for pkg in $(SUBPACKAGES); do \
		ruff format --check $$pkg/src/ $$pkg/tests/ 2>/dev/null || true; \
	done

lint-fix: ## Lint and auto-fix where possible
	ruff check --fix src/ tests/
	@for pkg in $(SUBPACKAGES); do \
		ruff check --fix $$pkg/src/ $$pkg/tests/ 2>/dev/null || true; \
	done

test-cov: ## Run tests with coverage
	pytest tests/ --cov=src --cov-report=term-missing

deps-lock: ## Lock dependencies
	poetry lock

local: start

dev: start

local-down: stop

dev-down: stop

local-logs: logs

dev-logs: logs

install-global: ## Install the latest local forktex CLI globally in editable mode
	pip install --break-system-packages -e .

.PHONY: format lint typecheck test audit license-check deps ci start stop logs build publish clean help local dev local-down dev-down local-logs dev-logs format-check lint-fix test-cov deps-lock install-global
