Skip to content

Commit 6a3c130

Browse files
committed
fix: add docstrings to all Python files and remove ruff.toml
Remove root-level ruff.toml; pass lint rules via prek.toml args instead. Add proper docstrings to vmm-cli.py, ct_monitor.py, add-spdx-attribution.py, and app.py to comply with pydocstyle rules.
1 parent 194b6d9 commit 6a3c130

6 files changed

Lines changed: 68 additions & 67 deletions

File tree

prek.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pass_filenames = false
3939
repo = "https://github.com/astral-sh/ruff-pre-commit"
4040
rev = "v0.11.4"
4141
hooks = [
42-
{ id = "ruff", args = ["--fix"] },
42+
{ id = "ruff", args = ["--fix", "--select", "E,F,I,D", "--ignore", "D203,D213,E501"] },
4343
{ id = "ruff-format" },
4444
]
4545

python/ct_monitor/ct_monitor.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-FileCopyrightText: © 2024 Phala Network <dstack@phala.network>
22
#
33
# SPDX-License-Identifier: Apache-2.0
4+
"""Monitor certificate transparency logs for a given domain."""
45

56
import argparse
67
import sys
@@ -15,22 +16,29 @@
1516

1617

1718
class PoisonedLog(Exception):
19+
"""Indicate a poisoned certificate transparency log entry."""
20+
1821
pass
1922

2023

2124
class Monitor:
25+
"""Monitor certificate transparency logs for a domain."""
26+
2227
def __init__(self, domain: str):
28+
"""Initialize the monitor with a validated domain."""
2329
if not self.validate_domain(domain):
2430
raise ValueError("Invalid domain name")
2531
self.domain = domain
2632
self.last_checked = None
2733

2834
def get_logs(self, count: int = 100):
35+
"""Fetch recent certificate transparency log entries."""
2936
url = f"{BASE_URL}/?q={self.domain}&output=json&limit={count}"
3037
response = requests.get(url)
3138
return response.json()
3239

3340
def check_one_log(self, log: object):
41+
"""Fetch and inspect a single certificate log entry."""
3442
log_id = log["id"]
3543
cert_url = f"{BASE_URL}/?d={log_id}"
3644
cert_data = requests.get(cert_url).text
@@ -68,6 +76,7 @@ def check_one_log(self, log: object):
6876
print("No valid certificate found in the response.")
6977

7078
def check_new_logs(self):
79+
"""Check for new log entries since the last check."""
7180
logs = self.get_logs(count=10000)
7281
print("num logs", len(logs))
7382
for log in logs:
@@ -80,6 +89,7 @@ def check_new_logs(self):
8089
self.last_checked = logs[0]["id"]
8190

8291
def run(self):
92+
"""Run the monitor loop indefinitely."""
8393
print(f"Monitoring {self.domain}...")
8494
while True:
8595
try:
@@ -93,7 +103,7 @@ def run(self):
93103

94104
@staticmethod
95105
def validate_domain(domain: str):
96-
# ensure domain is a valid DNS domain
106+
"""Validate that the given string is a well-formed DNS domain name."""
97107
import re
98108

99109
# Regular expression for validating domain names
@@ -108,6 +118,7 @@ def validate_domain(domain: str):
108118

109119

110120
def main():
121+
"""Parse arguments and start the certificate transparency monitor."""
111122
parser = argparse.ArgumentParser(
112123
description="Monitor certificate transparency logs"
113124
)

ruff.toml

Lines changed: 0 additions & 19 deletions
This file was deleted.

scripts/add-spdx-attribution.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
# SPDX-FileCopyrightText: © 2025 Phala Network <dstack@phala.network>
33
#
44
# SPDX-License-Identifier: Apache-2.0
5-
"""
6-
SPDX Header Attribution Script
5+
"""SPDX header attribution script.
76
8-
This script automatically analyzes git blame data to determine contributors
9-
and adds appropriate SPDX-FileCopyrightText headers using the REUSE tool.
7+
Analyze git blame data to determine contributors and add appropriate
8+
SPDX-FileCopyrightText headers using the REUSE tool.
109
1110
Features:
1211
- Excludes third-party code based on .spdx-exclude patterns
@@ -27,7 +26,10 @@
2726

2827

2928
class SPDXAttributor:
29+
"""Add SPDX attribution headers to source files based on git blame."""
30+
3031
def __init__(self, repo_root: str, dry_run: bool = False):
32+
"""Initialize the attributor with a repository root and options."""
3133
self.repo_root = Path(repo_root).resolve()
3234
self.dry_run = dry_run
3335
self.exclude_patterns = self._load_exclude_patterns()
@@ -491,6 +493,7 @@ def find_source_files(self) -> List[Path]:
491493

492494

493495
def main():
496+
"""Parse arguments and run SPDX attribution on source files."""
494497
parser = argparse.ArgumentParser(
495498
description="Add SPDX attribution headers to source files"
496499
)

tools/mock-cf-dns-api/app.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#
44
# SPDX-License-Identifier: Apache-2.0
55

6-
"""
7-
Mock Cloudflare DNS API Server
6+
"""Mock Cloudflare DNS API server.
87
98
A mock server that simulates Cloudflare's DNS API for testing purposes.
109
Supports the following endpoints used by certbot:
@@ -66,7 +65,7 @@ def get_current_time():
6665

6766

6867
def verify_auth(f):
69-
"""Decorator to verify Bearer token authentication."""
68+
"""Verify Bearer token authentication."""
7069

7170
@wraps(f)
7271
def decorated(*args, **kwargs):

0 commit comments

Comments
 (0)