Skip to content

Commit 06b6550

Browse files
authored
Add ruff lint #10
2 parents b4d9d1f + 749423d commit 06b6550

File tree

6 files changed

+170
-136
lines changed

6 files changed

+170
-136
lines changed

.github/workflows/ci_checks.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI Checks
2+
on:
3+
push:
4+
pull_request:
5+
6+
jobs:
7+
lint:
8+
name: Lint
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
with:
13+
submodules: true
14+
- name: Set up Python
15+
uses: actions/setup-python@v4
16+
with:
17+
python-version: "3.13"
18+
- name: Set up uv
19+
uses: astral-sh/setup-uv@v1
20+
- name: Install dependencies
21+
run: |
22+
uv sync
23+
- name: Ensure Proto Files changes are committed
24+
run: |
25+
uv run python scripts/generate_proto.py
26+
if [ -n "$(git status --porcelain 2>&1)" ]; then
27+
echo "There are file changes after generating proto files."
28+
echo "Please run this command and commit the changes:"
29+
echo "\tuv run python scripts/generate_proto.py"
30+
git status --porcelain
31+
git --no-pager diff
32+
exit 1
33+
fi
34+
- name: Run Ruff linter
35+
run: |
36+
uv tool run ruff check

cadence/sample/grpc_usage_example.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"""
66

77
import grpc
8-
from google.protobuf import duration_pb2
9-
from cadence.api.v1 import service_workflow_grpc, service_workflow, workflow, common, tasklist
8+
from cadence.api.v1 import service_workflow_grpc, service_workflow, common
109

1110

1211
def create_grpc_channel(server_address: str = "localhost:7833", use_ssl: bool = False) -> grpc.Channel:

cadence/sample/simple_usage_example.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def example_workflow_execution():
2323
wf_exec.workflow_id = "my-workflow-123"
2424
wf_exec.run_id = "run-456"
2525

26-
print(f"Created workflow execution:")
26+
print("Created workflow execution:")
2727
print(f" - Workflow ID: {wf_exec.workflow_id}")
2828
print(f" - Run ID: {wf_exec.run_id}")
2929

@@ -34,7 +34,7 @@ def example_workflow_execution():
3434
wf_info.start_time.seconds = 1234567890
3535
wf_info.close_time.seconds = 1234567990
3636

37-
print(f"Created workflow execution info:")
37+
print("Created workflow execution info:")
3838
print(f" - Type: {wf_info.type.name}")
3939
print(f" - Start Time: {wf_info.start_time.seconds}")
4040
print(f" - Close Time: {wf_info.close_time.seconds}")
@@ -54,7 +54,7 @@ def example_domain_operations():
5454
domain_obj.status = domain.DOMAIN_STATUS_REGISTERED
5555
domain_obj.description = "My test domain"
5656

57-
print(f"Created domain:")
57+
print("Created domain:")
5858
print(f" - Name: {domain_obj.name}")
5959
print(f" - Status: {domain_obj.status}")
6060
print(f" - Description: {domain_obj.description}")
@@ -94,7 +94,7 @@ def example_serialization():
9494
"""Example of serializing and deserializing protobuf objects."""
9595
print("\n=== Serialization Example ===")
9696

97-
from cadence.api.v1 import common, workflow
97+
from cadence.api.v1 import common
9898

9999
# Create a workflow execution
100100
wf_exec = common.WorkflowExecution()
@@ -109,7 +109,7 @@ def example_serialization():
109109
new_wf_exec = common.WorkflowExecution()
110110
new_wf_exec.ParseFromString(serialized)
111111

112-
print(f"Deserialized workflow execution:")
112+
print("Deserialized workflow execution:")
113113
print(f" - Workflow ID: {new_wf_exec.workflow_id}")
114114
print(f" - Run ID: {new_wf_exec.run_id}")
115115

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,9 @@ exclude_lines = [
156156
"if __name__ == .__main__.:",
157157
"class .*\\bProtocol\\):",
158158
"@(abc.)?abstractmethod",
159-
]
159+
]
160+
161+
[tool.ruff]
162+
exclude = [
163+
"cadence/api", # generated proto files
164+
]

scripts/dev.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def run_command(cmd, description):
1414
"""Run a command and handle errors."""
1515
print(f"Running: {description}")
1616
try:
17-
result = subprocess.run(cmd, shell=True, check=True)
17+
subprocess.run(cmd, shell=True, check=True)
1818
print(f"✓ {description} completed successfully")
1919
return True
2020
except subprocess.CalledProcessError as e:
@@ -50,12 +50,12 @@ def lint():
5050
("uv run flake8 .", "Running flake8 linting"),
5151
("uv run mypy .", "Running mypy type checking"),
5252
]
53-
53+
5454
success = True
5555
for cmd, desc in commands:
5656
if not run_command(cmd, desc):
5757
success = False
58-
58+
5959
return success
6060

6161

@@ -65,12 +65,12 @@ def format():
6565
("uv run black .", "Formatting code with black"),
6666
("uv run isort .", "Sorting imports with isort"),
6767
]
68-
68+
6969
success = True
7070
for cmd, desc in commands:
7171
if not run_command(cmd, desc):
7272
success = False
73-
73+
7474
return success
7575

7676

@@ -85,22 +85,17 @@ def clean():
8585
"htmlcov/",
8686
".mypy_cache/",
8787
]
88-
89-
files_to_remove = [
90-
"*.pyc",
91-
"__pycache__",
92-
]
93-
88+
9489
print("Cleaning build artifacts...")
95-
90+
9691
# Remove directories
9792
for dir_pattern in dirs_to_remove:
9893
run_command(f"rm -rf {dir_pattern}", f"Removing {dir_pattern}")
99-
94+
10095
# Remove Python cache files
10196
run_command("find . -type d -name __pycache__ -delete", "Removing __pycache__ directories")
10297
run_command("find . -type f -name '*.pyc' -delete", "Removing .pyc files")
103-
98+
10499
print("✓ Clean completed")
105100

106101

@@ -135,12 +130,12 @@ def main():
135130
"""Main function."""
136131
parser = argparse.ArgumentParser(description="Development script for Cadence Python client")
137132
parser.add_argument("command", choices=[
138-
"install", "install-dev", "test", "test-cov", "lint", "format",
133+
"install", "install-dev", "test", "test-cov", "lint", "format",
139134
"clean", "build", "protobuf", "docs", "check"
140135
], help="Command to run")
141-
136+
142137
args = parser.parse_args()
143-
138+
144139
# Map commands to functions
145140
commands = {
146141
"install": install,
@@ -155,13 +150,13 @@ def main():
155150
"docs": docs,
156151
"check": check,
157152
}
158-
153+
159154
# Run the command
160155
success = commands[args.command]()
161-
156+
162157
if not success:
163158
sys.exit(1)
164159

165160

166161
if __name__ == "__main__":
167-
main()
162+
main()

0 commit comments

Comments
 (0)