-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathMakefile
More file actions
138 lines (109 loc) · 4.36 KB
/
Copy pathMakefile
File metadata and controls
138 lines (109 loc) · 4.36 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
.PHONY: install install-dev install-devc install-devc-release install-pre-commit bench bench-parse bench-transpile bench-optimize test test-fast test-branch unit testc unitc leakcheck style check docs docs-serve hidec showc clean resolve-integration-conflicts update-fixtures
ifdef UV
PIP := uv pip
else
PIP := pip
endif
SO_BACKUP := /tmp/sqlglot_so_backup
FIND_SO := find sqlglot -name "*.so"
NPROC := $(shell python -c "import os; print(os.cpu_count() or 1)")
hidec:
rm -rf $(SO_BACKUP) && $(FIND_SO) | tar cf $(SO_BACKUP) -T - 2>/dev/null && $(FIND_SO) -delete; true
showc:
tar xf $(SO_BACKUP) 2>/dev/null; rm -f $(SO_BACKUP); true
clean:
rm -rf build sqlglotc/build sqlglotc/dist sqlglotc/*.egg-info sqlglotc/sqlglot
$(FIND_SO) -delete 2>/dev/null; true
install:
$(PIP) install -e .
install-dev:
git submodule update --init 2>/dev/null || true
@if [ -f sqlglot-integration-tests/Makefile ]; then \
$(MAKE) -C sqlglot-integration-tests install; \
fi
$(PIP) install -e ".[dev]"
$(PIP) uninstall -y sqlglotc 2>/dev/null || true
@if ! command -v gh >/dev/null 2>&1; then \
echo ""; \
echo "gh (GitHub CLI) is not installed. It is needed to auto-create PRs for integration tests."; \
printf "Install it via brew? [y/N] "; \
read answer; \
if [ "$$answer" = "y" ] || [ "$$answer" = "Y" ]; then \
brew install gh; \
else \
echo "Skipping. You can install it later: https://cli.github.com/"; \
fi; \
fi
# sqlglotc requires Python 3.10+ (sqlglot-mypy 1.20+ dropped 3.9). On 3.9
# we skip the C build; tests fall back to pure-Python sqlglot.
PY_GE_310 := $(shell python -c "import sys; print(int(sys.version_info >= (3, 10)))")
install-devc:
@if [ "$(PY_GE_310)" = "1" ]; then \
cd sqlglotc && MYPYC_OPT=0 python setup.py build_ext --inplace -j $(NPROC); \
else \
echo "Skipping sqlglotc build: requires Python 3.10+"; \
fi
install-devc-release: clean
@if [ "$(PY_GE_310)" = "1" ]; then \
cd sqlglotc && python setup.py build_ext --inplace -j $(NPROC); \
else \
echo "Skipping sqlglotc build: requires Python 3.10+"; \
fi
install-pre-commit:
pre-commit install
pre-commit install --hook-type post-checkout
pre-commit install --hook-type pre-push
pre-commit install --hook-type post-merge
@printf '#!/bin/bash\n.github/scripts/integration_tests_sync.sh post-commit\n' > .git/hooks/post-commit
@chmod +x .git/hooks/post-commit
bench: bench-parse bench-transpile bench-optimize
bench-parse:
python -m benchmarks.parse
bench-transpile:
python -m benchmarks.parse --mode transpile
bench-optimize:
python -m benchmarks.optimize
test: hidec
trap '$(MAKE) showc' EXIT; python -m unittest
test-fast:
python -m unittest --failfast
BRANCH_BASE ?= main
test-branch:
@changed_main=$$({ git diff origin/$(BRANCH_BASE)...HEAD --name-only 2>/dev/null; git diff HEAD --name-only; git diff --cached --name-only; } \
| sort -u | grep '^tests/.*\.py$$' | grep -v '__init__' | sed 's/\.py$$//' | tr '/' '.'); \
changed_int=$$({ git -C sqlglot-integration-tests log --name-only --format='' origin/HEAD..HEAD 2>/dev/null; git -C sqlglot-integration-tests diff HEAD --name-only 2>/dev/null; } \
| sort -u | grep '^tests/sqlglot/.*\.py$$' | grep -v '__init__'); \
if [ -z "$$changed_main" ] && [ -z "$$changed_int" ]; then \
echo "No test files changed vs $(BRANCH_BASE)"; exit 0; \
fi; \
if [ -n "$$changed_main" ]; then \
echo "Main tests:"; echo "$$changed_main" | tr ' ' '\n' | sed 's/^/ /'; \
python -m unittest $$changed_main || exit 1; \
fi; \
if [ -n "$$changed_int" ]; then \
echo "Integration tests:"; echo "$$changed_int" | tr ' ' '\n' | sed 's/^/ /'; \
cd sqlglot-integration-tests && PYTHONPATH=. pytest $$changed_int; \
fi
unit: hidec
trap '$(MAKE) showc' EXIT; SKIP_INTEGRATION=1 python -m unittest
testc: install-devc
python -m unittest
unitc: install-devc
SKIP_INTEGRATION=1 python -m unittest
leakcheck: install-devc
python -m tests.leakcheck
style:
pre-commit run --all-files
@if [ -f sqlglot-integration-tests/Makefile ]; then \
MYPYPATH=$(abspath .) $(MAKE) -C sqlglot-integration-tests style && \
$(MAKE) -C sqlglot-integration-tests check-submodule; \
fi
check: style test testc
docs:
python pdoc/cli.py -o docs
docs-serve:
python pdoc/cli.py --port 8002
resolve-integration-conflicts:
cd sqlglot-integration-tests && git pull --rebase --autostash
update-fixtures:
python sqlglot-integration-tests/scripts/update_dbt_fixtures.py