Skip to content

Commit

Permalink
Format Python code with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
pietern committed Jan 16, 2025
1 parent 2e70558 commit 14bc890
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ jobs:
- name: Install uv
uses: astral-sh/setup-uv@887a942a15af3a7626099df99e897a18d9e5ab3a # v5.1.0

- name: Install ruff
uses: astral-sh/ruff-action@31a518504640beb4897d0b9f9e50a2a9196e75ba # v3.0.1
with:
version: "0.9.1"

- name: Set go env
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ __pycache__
.vscode/tasks.json

.databricks
.ruff_cache
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ lintcheck:
# formatting/goimports will not be applied by 'make lint'. However, it will be applied by 'make fmt'.
# If you need to ensure that formatting & imports are always fixed, do "make fmt lint"
fmt:
ruff format
golangci-lint run --enable-only="gofmt,gofumpt,goimports" --fix ./...

test:
Expand Down Expand Up @@ -44,7 +45,7 @@ snapshot:

vendor:
go mod vendor

schema:
go run ./bundle/internal/schema ./bundle/internal/schema ./bundle/schema/jsonschema.json

Expand Down
5 changes: 3 additions & 2 deletions acceptance/bin/sort_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
This is to workaround non-determinism in the output.
"""

import sys

blocks = []

for line in sys.stdin:
if not line.strip():
if blocks and blocks[-1]:
blocks.append('')
blocks.append("")
continue
if not blocks:
blocks.append('')
blocks.append("")
blocks[-1] += line

blocks.sort()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

def main():
# This method will print the provided arguments
print('Hello from my func')
print('Got arguments:')
print("Hello from my func")
print("Got arguments:")
print(sys.argv)


if __name__ == '__main__':
if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

def main():
# This method will print the provided arguments
print('Hello from my func')
print('Got arguments:')
print("Hello from my func")
print("Got arguments:")
print(sys.argv)


if __name__ == '__main__':
if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

def main():
# This method will print the provided arguments
print('Hello from my func')
print('Got arguments:')
print("Hello from my func")
print("Got arguments:")
print(sys.argv)


if __name__ == '__main__':
if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

def main():
# This method will print the provided arguments
print('Hello from my func')
print('Got arguments:')
print("Hello from my func")
print("Got arguments:")
print(sys.argv)


if __name__ == '__main__':
if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

def main():
# This method will print the provided arguments
print('Hello from my func')
print('Got arguments:')
print("Hello from my func")
print("Got arguments:")
print(sys.argv)


if __name__ == '__main__':
if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -1 +1 @@
print(f'setting up important infrastructure')
print(f"setting up important infrastructure")

Check failure on line 1 in cmd/labs/project/testdata/installed-in-home/.databricks/labs/blueprint/lib/install.py

View workflow job for this annotation

GitHub Actions / tests (macos-latest)

Ruff (F541)

cmd/labs/project/testdata/installed-in-home/.databricks/labs/blueprint/lib/install.py:1:7: F541 f-string without any placeholders

Check failure on line 1 in cmd/labs/project/testdata/installed-in-home/.databricks/labs/blueprint/lib/install.py

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest)

Ruff (F541)

cmd/labs/project/testdata/installed-in-home/.databricks/labs/blueprint/lib/install.py:1:7: F541 f-string without any placeholders

Check failure on line 1 in cmd/labs/project/testdata/installed-in-home/.databricks/labs/blueprint/lib/install.py

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

Ruff (F541)

cmd\labs\project\testdata\installed-in-home\.databricks\labs\blueprint\lib\install.py:1:7: F541 f-string without any placeholders
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,34 @@

payload = json.loads(sys.argv[1])

if 'echo' == payload['command']:
json.dump({
'command': payload['command'],
'flags': payload['flags'],
'env': {k:v for k,v in os.environ.items()}
}, sys.stdout)
if "echo" == payload["command"]:
json.dump(
{
"command": payload["command"],
"flags": payload["flags"],
"env": {k: v for k, v in os.environ.items()},
},
sys.stdout,
)
sys.exit(0)

if 'table' == payload['command']:
if "table" == payload["command"]:
sys.stderr.write("some intermediate info\n")
json.dump({'records': [
{'key': 'First', 'value': 'Second'},
{'key': 'Third', 'value': 'Fourth'},
]}, sys.stdout)
json.dump(
{
"records": [
{"key": "First", "value": "Second"},
{"key": "Third", "value": "Fourth"},
]
},
sys.stdout,
)
sys.exit(0)

print(f'host is {os.environ["DATABRICKS_HOST"]}')
print(f"host is {os.environ['DATABRICKS_HOST']}")

print(f'[{payload["command"]}] command flags are {payload["flags"]}')
print(f"[{payload['command']}] command flags are {payload['flags']}")

answer = input('What is your name? ')
answer = input("What is your name? ")

print(f'Hello, {answer}!')
print(f"Hello, {answer}!")
2 changes: 2 additions & 0 deletions libs/notebook/testdata/.ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[format]
exclude = ["*.ipynb"]
2 changes: 2 additions & 0 deletions libs/sync/testdata/.ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[format]
exclude = ["*.ipynb"]

0 comments on commit 14bc890

Please sign in to comment.