Skip to content

Commit 2da2d76

Browse files
authored
Fix formatting in the default template (#3950)
## Changes Fix formatting in the default template. Previously, there was a diff: ```diff --- test_20251119/src/test_20251119/main.py +++ test_20251119/src/test_20251119/main.py @@ -5,7 +5,9 @@ def main(): # Process command-line arguments - parser = argparse.ArgumentParser(description="Databricks job with catalog and schema parameters") + parser = argparse.ArgumentParser( + description="Databricks job with catalog and schema parameters" + ) parser.add_argument("--catalog", required=True) parser.add_argument("--schema", required=True) args = parser.parse_args() ``` The problem is in the default template and not specific to PyDABs. ## Why The template should be pre-formatted so that after the project is initialized, it's already in its final state. ## Tests Updated acceptance tests to check formatting for all files that template produces
1 parent daef3df commit 2da2d76

File tree

5 files changed

+26
-8
lines changed
  • acceptance/bundle/templates
    • default-python
      • classic/output/my_default_python/src/my_default_python
      • serverless/output/my_default_python/src/my_default_python
    • pydabs/check-formatting
  • libs/template/templates/default/template/{{.project_name}}/src/{{.project_name}}

5 files changed

+26
-8
lines changed

acceptance/bundle/templates/default-python/classic/output/my_default_python/src/my_default_python/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
def main():
77
# Process command-line arguments
8-
parser = argparse.ArgumentParser(description="Databricks job with catalog and schema parameters")
8+
parser = argparse.ArgumentParser(
9+
description="Databricks job with catalog and schema parameters",
10+
)
911
parser.add_argument("--catalog", required=True)
1012
parser.add_argument("--schema", required=True)
1113
args = parser.parse_args()

acceptance/bundle/templates/default-python/serverless/output/my_default_python/src/my_default_python/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
def main():
77
# Process command-line arguments
8-
parser = argparse.ArgumentParser(description="Databricks job with catalog and schema parameters")
8+
parser = argparse.ArgumentParser(
9+
description="Databricks job with catalog and schema parameters",
10+
)
911
parser.add_argument("--catalog", required=True)
1012
parser.add_argument("--schema", required=True)
1113
args = parser.parse_args()

acceptance/bundle/templates/pydabs/check-formatting/output.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ Note that [DATABRICKS_URL] is used for initialization.
1111
✨ Your new project has been created in the 'my_pydabs' directory!
1212

1313
To get started, refer to the project README.md file and the documentation at https://docs.databricks.com/dev-tools/bundles/python/index.html.
14+
Checking code formatting with ruff format --line-length 88
1415

15-
>>> find my_pydabs -mindepth 1 ! -name pyproject.toml ! -regex .*/resources.* -delete
16+
>>> ruff format --isolated --line-length 88 --quiet --diff --check my_pydabs
17+
Checking code formatting with ruff format --line-length 120
1618

17-
>>> ruff format --quiet --diff --check my_pydabs
19+
>>> ruff format --isolated --line-length 120 --quiet --diff --check my_pydabs
1820

1921
>>> yamlcheck.py

acceptance/bundle/templates/pydabs/check-formatting/script

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@ envsubst < input.json.tmpl > input.json
22

33
trace $CLI bundle init pydabs --config-file ./input.json
44

5-
# only keep relevant files for snapshots
6-
trace find my_pydabs -mindepth 1 ! -name 'pyproject.toml' ! -regex '.*/resources.*' -delete
5+
# Use --isolated not to inherit ruff.toml in the repo root.
6+
#
7+
# Format both with line-length 88 to cover default formatter settings
8+
# and 120 to cover default formatter settings in Workspace editor.
9+
#
10+
# You can use trailing comma to force line breaks to make formatting consistent
11+
# with different line-length settings.
12+
13+
echo "Checking code formatting with ruff format --line-length 88"
14+
trace ruff format --isolated --line-length 88 --quiet --diff --check my_pydabs
15+
16+
echo "Checking code formatting with ruff format --line-length 120"
17+
trace ruff format --isolated --line-length 120 --quiet --diff --check my_pydabs
718

8-
trace ruff format --quiet --diff --check my_pydabs
919
trace yamlcheck.py
1020

1121
rm -rf my_pydabs input.json

libs/template/templates/default/template/{{.project_name}}/src/{{.project_name}}/main.py.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ from {{.project_name}} import taxis
55

66
def main():
77
# Process command-line arguments
8-
parser = argparse.ArgumentParser(description="Databricks job with catalog and schema parameters")
8+
parser = argparse.ArgumentParser(
9+
description="Databricks job with catalog and schema parameters",
10+
)
911
parser.add_argument("--catalog", required=True)
1012
parser.add_argument("--schema", required=True)
1113
args = parser.parse_args()

0 commit comments

Comments
 (0)