Skip to content

Commit 20b87ec

Browse files
committed
[Python] Add codegen
1 parent 89a3b52 commit 20b87ec

19 files changed

+1681
-1
lines changed

.github/workflows/push.yml

+17
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,20 @@ jobs:
159159
for file in ./bundle/internal/schema/testdata/fail/*.yml; do
160160
ajv test -s schema.json -d $file --invalid -c=./keywords.js
161161
done
162+
163+
validate-python-codegen:
164+
needs: cleanups
165+
runs-on: ubuntu-latest
166+
167+
steps:
168+
169+
- name: Checkout
170+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
171+
172+
- name: Verify that python/codegen is up to date
173+
workdir: experimental/python
174+
run: |
175+
if ! ( make codegen && git diff --exit-code ); then
176+
echo "Generated Python code is not up-to-date. Please run 'pushd experimental/python && make codegen' and commit the changes."
177+
exit 1
178+
fi

experimental/python/Makefile

+10-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,20 @@ lint:
1616
uv run pyright
1717
uv run ruff format --diff
1818

19+
codegen:
20+
find databricks -name _models | xargs rm -rf
21+
22+
cd codegen; uv run -m pytest codegen_tests
23+
cd codegen; uv run -m codegen.main --output ..
24+
25+
uv run ruff check --fix $(sources) || true
26+
uv run ruff format
27+
1928
test:
2029
uv run python -m pytest databricks_tests --cov=databricks.bundles --cov-report html -vv
2130

2231
build:
2332
rm -rf build dist
2433
uv build .
2534

26-
.PHONY: fmt docs lint test build
35+
.PHONY: fmt docs lint codegen test build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from typing import TYPE_CHECKING
2+
3+
if TYPE_CHECKING:
4+
from typing_extensions import Self
5+
6+
7+
class CodeBuilder:
8+
def __init__(self):
9+
self._code = ""
10+
11+
def append(self, *args: str) -> "Self":
12+
for arg in args:
13+
self._code += arg
14+
15+
return self
16+
17+
def indent(self):
18+
return self.append(" ")
19+
20+
def newline(self) -> "Self":
21+
return self.append("\n")
22+
23+
def append_list(self, args: list[str], sep: str = ",") -> "Self":
24+
return self.append(sep.join(args))
25+
26+
def append_dict(self, args: dict[str, str], sep: str = ",") -> "Self":
27+
return self.append_list([f"{k}={v}" for k, v in args.items()], sep)
28+
29+
def append_triple_quote(self) -> "Self":
30+
return self.append('"""')
31+
32+
def append_repr(self, value) -> "Self":
33+
return self.append(repr(value))
34+
35+
def build(self):
36+
return self._code

0 commit comments

Comments
 (0)