-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
138 lines (120 loc) · 5.04 KB
/
Copy pathMakefile
File metadata and controls
138 lines (120 loc) · 5.04 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
# Makefile for BambooHR API Python SDK
# Default OpenAPI spec path - defaults to the committed spec; override with OPENAPI_SPEC_PATH=...
OPENAPI_SPEC_PATH ?= specs/public.yaml
# OpenAPI Generator Docker image
OPENAPI_GENERATOR_IMAGE ?= openapitools/openapi-generator-cli:v7.16.0
# Python interpreter
PYTHON ?= python3
# Package information
PACKAGE_NAME = bamboohr_sdk
PACKAGE_VERSION = 1.0.0
PROJECT_NAME = bamboohr-sdk
PACKAGE_URL = https://www.bamboohr.com/
DEVELOPER_URL = https://github.com/BambooHR/bhr-api-python
DEVELOPER = BambooHR
LICENSE_NAME = MIT
.PHONY: help generate clean cleanup-obsolete generate-error-docs test lint typecheck format classify-semver smoke-test sync-accessors check-accessors
help:
@echo "BambooHR API Python SDK - Available commands:"
@echo " make generate - Generate SDK code from OpenAPI spec"
@echo " make generate OPENAPI_SPEC_PATH=/path/to/spec.yaml - Generate using a custom spec path"
@echo " make clean - Remove generated files"
@echo " make cleanup-obsolete - Manually run cleanup of obsolete files"
@echo " make test - Run tests"
@echo " make lint - Run ruff linter"
@echo " make format - Run ruff formatter"
@echo " make typecheck - Run mypy type checker"
@echo " make sync-accessors - Regenerate client accessors from generated APIs"
@echo " make check-accessors - Verify client accessors are in sync (CI)"
@echo " make classify-semver OLD=old.yaml NEW=new.yaml [APPLY=true] - Classify semver bump"
generate:
@echo "Generating Python SDK from OpenAPI spec at $(OPENAPI_SPEC_PATH)..."
@if [ ! -f "$(OPENAPI_SPEC_PATH)" ]; then \
echo "Error: OpenAPI spec file not found at $(OPENAPI_SPEC_PATH)"; \
echo "Please specify the correct path with OPENAPI_SPEC_PATH=/path/to/spec.yaml"; \
exit 1; \
fi
@# Backup the current FILES manifest for cleanup comparison
@if [ -f ".openapi-generator/FILES" ]; then \
cp .openapi-generator/FILES .openapi-generator/FILES.old; \
fi
@# Resolve spec path for Docker mount (absolute path)
$(eval SPEC_ABS := $(shell realpath $(OPENAPI_SPEC_PATH)))
docker run --rm \
--user "$(shell id -u):$(shell id -g)" \
-v "$(PWD):/local" \
-v "$(SPEC_ABS):/tmp/spec.yaml:ro" \
$(OPENAPI_GENERATOR_IMAGE) generate \
-i /tmp/spec.yaml \
-g python \
-t /local/templates-python \
-o /local \
--global-property modelTests=false \
--additional-properties=packageName=$(PACKAGE_NAME),packageVersion=$(PACKAGE_VERSION),projectName=$(PROJECT_NAME),packageUrl=$(PACKAGE_URL),developerOrganization=$(DEVELOPER),developerOrganizationUrl=$(DEVELOPER_URL),licenseName=$(LICENSE_NAME)
$(PYTHON) scripts/post_generate.py
@echo "SDK generation complete!"
cleanup-obsolete:
@echo "Running cleanup of obsolete files..."
$(PYTHON) scripts/cleanup_obsolete_files.py
@echo "Cleanup complete!"
generate-error-docs:
@echo "Updating exception classes and documentation..."
$(PYTHON) scripts/update_error_docs.py
@echo "Error docs update complete!"
clean:
@echo "Cleaning generated files..."
@# Preserve hand-written API files before wiping the directory
@mkdir -p /tmp/bhr-sdk-preserve
@if [ -f bamboohr_sdk/api/manual_api.py ]; then \
cp bamboohr_sdk/api/manual_api.py /tmp/bhr-sdk-preserve/; \
fi
rm -rf bamboohr_sdk/api bamboohr_sdk/models docs test .openapi-generator
@# Recreate empty directories with __init__.py
mkdir -p bamboohr_sdk/api bamboohr_sdk/models
echo '"""Auto-generated API classes from OpenAPI specification."""' > bamboohr_sdk/api/__init__.py
echo '"""Auto-generated data models from OpenAPI specification."""' > bamboohr_sdk/models/__init__.py
@# Restore hand-written API files
@if [ -f /tmp/bhr-sdk-preserve/manual_api.py ]; then \
cp /tmp/bhr-sdk-preserve/manual_api.py bamboohr_sdk/api/; \
rm -rf /tmp/bhr-sdk-preserve; \
fi
@echo "Clean complete!"
test:
@echo "Running tests..."
$(PYTHON) -m pytest
@echo "Running classify_semver.sh unit tests..."
@bash scripts/tests/test_classify_semver.sh
@echo "Tests complete!"
lint:
@echo "Running ruff linter..."
$(PYTHON) -m ruff check bamboohr_sdk/ tests/
@echo "Lint complete!"
format:
@echo "Running ruff formatter..."
$(PYTHON) -m ruff format bamboohr_sdk/ tests/
$(PYTHON) -m ruff check --fix bamboohr_sdk/ tests/
@echo "Format complete!"
sync-accessors:
@echo "Syncing client API accessors with generated APIs..."
$(PYTHON) scripts/sync_accessors.py
@echo "Accessor sync complete!"
check-accessors:
@echo "Checking client API accessors are in sync..."
$(PYTHON) scripts/sync_accessors.py --check
@echo "Accessor check complete!"
typecheck:
@echo "Running mypy type checker..."
$(PYTHON) -m mypy bamboohr_sdk/
@echo "Type check complete!"
classify-semver:
@if [ -z "$(OLD)" ] || [ -z "$(NEW)" ]; then \
echo "Usage: make classify-semver OLD=old.yaml NEW=new.yaml [APPLY=true]"; \
exit 1; \
fi
@APPLY_FLAG=""; \
if [ "$(APPLY)" = "true" ]; then APPLY_FLAG="--apply"; fi; \
bash scripts/classify_semver.sh $$APPLY_FLAG $(OLD) $(NEW)
smoke-test:
@echo "Running import smoke test..."
$(PYTHON) scripts/smoke_test.py
@echo "Smoke test complete!"