Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,28 @@ jobs:
for file in ./bundle/internal/schema/testdata/fail/*.yml; do
ajv test -s schema.json -d $file --invalid -c=./keywords.js
done

validate-python-codegen:
needs: cleanups
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Install uv
uses: astral-sh/setup-uv@0c5e2b8115b80b4c7c5ddf6ffdd634974642d182 # v5.4.1
with:
version: "0.6.5"

- name: Verify that python/codegen is up to date
working-directory: experimental/python
run: |
make codegen

if ! ( git diff --exit-code ); then
echo "Generated Python code is not up-to-date. Please run 'pushd experimental/python && make codegen' and commit the changes."

# TODO block PR if this fails once diffs are fixed
# exit 1
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the tests run on push?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a little bit of a problem, if codegen itself crashed CI job will pass now, let me fix it

11 changes: 10 additions & 1 deletion experimental/python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@ lint:
uv run pyright
uv run ruff format --diff

codegen:
find databricks -name _models | xargs rm -rf

cd codegen; uv run -m pytest codegen_tests
cd codegen; uv run -m codegen.main --output ..

uv run ruff check --fix $(sources) || true
uv run ruff format

test:
uv run python -m pytest databricks_tests --cov=databricks.bundles --cov-report html -vv

build:
rm -rf build dist
uv build .

.PHONY: fmt docs lint test build
.PHONY: fmt docs lint codegen test build
36 changes: 36 additions & 0 deletions experimental/python/codegen/codegen/code_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing_extensions import Self


class CodeBuilder:
def __init__(self):
self._code = ""

def append(self, *args: str) -> "Self":
for arg in args:
self._code += arg

return self

def indent(self):
return self.append(" ")

def newline(self) -> "Self":
return self.append("\n")

def append_list(self, args: list[str], sep: str = ",") -> "Self":
return self.append(sep.join(args))

def append_dict(self, args: dict[str, str], sep: str = ",") -> "Self":
return self.append_list([f"{k}={v}" for k, v in args.items()], sep)

def append_triple_quote(self) -> "Self":
return self.append('"""')

def append_repr(self, value) -> "Self":
return self.append(repr(value))

def build(self):
return self._code
Loading
Loading