-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
84 lines (70 loc) · 3.19 KB
/
Copy pathMakefile
File metadata and controls
84 lines (70 loc) · 3.19 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
.PHONY: lint test snapshots check-snapshots refresh-snapshot-schema
# Each tests/snapshots/*/ holds a queries.graphql and the client generated from
# it, checked in. The pair is a regression guard: a change to codegen that alters
# generated output shows up as a reviewable diff instead of silently.
SNAPSHOT_DIRS := $(sort $(dir $(wildcard tests/snapshots/*/queries.graphql)))
SNAPSHOT_PACKAGE := sdk
# Pinned so a snapshot is a function of checked-in inputs alone. Generating
# against the live schema made every PR fail whenever the API changed. Kept
# outside the fixture directories, which codegen scans for operations.
SNAPSHOT_SCHEMA := tests/snapshots/schema.graphql
install:
poetry install --with dev
lint: sort_order style typecheck
sort_order:
poetry run isort fragment/ tests/
style:
poetry run black fragment/ tests/
# tests/ is checked too: tests/type_checks/ asserts what a caller sees when
# calling the generated client, which no runtime test can cover.
typecheck:
poetry run mypy -p fragment
poetry run mypy tests/
# Everything that needs no credentials and no network.
unit:
poetry run pytest -m "not integration"
# Integration tests. Requires CLIENT_ID, CLIENT_SECRET, SCOPE, AUTH_URL and
# API_URL in the environment; the tests fail if any are missing.
test:
poetry run pytest
# Overwrite the checked-in snapshots with freshly generated clients. Run this
# deliberately after an intended codegen change, then review the diff before
# committing it.
snapshots:
@for dir in $(SNAPSHOT_DIRS); do \
echo "Regenerating $$dir$(SNAPSHOT_PACKAGE)"; \
rm -rf "$$dir$(SNAPSHOT_PACKAGE)"; \
poetry run fragment-python-client-codegen \
--input-dir="$$dir" \
--schema-path=$(SNAPSHOT_SCHEMA) \
--target-package-name=$(SNAPSHOT_PACKAGE) \
--output-dir="$$dir" || exit 1; \
done
poetry run isort tests/snapshots/
poetry run black tests/snapshots/
# Regenerate in place and fail if anything changed. Used in CI so generated
# output cannot drift from the committed snapshots.
check-snapshots: snapshots
@untracked="$$(git ls-files --others --exclude-standard -- tests/snapshots)"; \
if ! git diff --quiet -- tests/snapshots || [ -n "$$untracked" ]; then \
echo ""; \
echo "Generated client differs from the committed snapshots."; \
echo "If the change is intended, run 'make snapshots' and commit the result."; \
echo ""; \
git --no-pager diff --stat -- tests/snapshots; \
[ -n "$$untracked" ] && printf 'untracked:\n%s\n' "$$untracked"; \
exit 1; \
fi
@echo "Snapshots up to date."
# Repin the snapshot schema to the current API. Run deliberately; the diff shows
# what changed upstream.
refresh-snapshot-schema:
poetry run python -c "import httpx; from fragment.codegen.main import GRAPHQL_SCHEMA_API_URL as u; open('$(SNAPSHOT_SCHEMA)','w').write(httpx.get(u).text)"
$(MAKE) snapshots
build: install
poetry run fragment-python-client-codegen --input-dir=queries/ --target-package-name=sdk --output-dir fragment/
poetry run fragment-python-client-codegen --input-dir=queries/ --target-package-name=sync_sdk --output-dir fragment/ --sync
docker-build:
docker build -t fragment-python-sdk-dev .
docker-run: docker-build
docker run -v ${CURDIR}:/app -w /app -it fragment-python-sdk-dev /bin/bash