Skip to content

ruff format #5845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2025
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
33 changes: 26 additions & 7 deletions scripts/find_eq.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,29 @@
# --cpython: Path to cpython source code
# --print-diff: Print the diff between the files
# --color: Output color
# --files: Optional globbing pattern to match files in cpython source code
# --files: Optional globbing pattern to match files in cpython source code
# --checklist: output as checklist

import argparse
import difflib
import pathlib

parser = argparse.ArgumentParser(description="Find equivalent files in cpython and rustpython")
parser.add_argument("--cpython", type=pathlib.Path, required=True, help="Path to cpython source code")
parser.add_argument("--print-diff", action="store_true", help="Print the diff between the files")
parser = argparse.ArgumentParser(
description="Find equivalent files in cpython and rustpython"
)
parser.add_argument(
"--cpython", type=pathlib.Path, required=True, help="Path to cpython source code"
)
parser.add_argument(
"--print-diff", action="store_true", help="Print the diff between the files"
)
parser.add_argument("--color", action="store_true", help="Output color")
parser.add_argument("--files", type=str, default="*.py", help="Optional globbing pattern to match files in cpython source code")
parser.add_argument(
"--files",
type=str,
default="*.py",
help="Optional globbing pattern to match files in cpython source code",
)

args = parser.parse_args()

Expand All @@ -27,7 +38,9 @@

cpython_lib = args.cpython / "Lib"
rustpython_lib = pathlib.Path(__file__).parent.parent / "Lib"
assert rustpython_lib.exists(), "RustPython lib directory does not exist, ensure the find_eq.py script is located in the right place"
assert rustpython_lib.exists(), (
"RustPython lib directory does not exist, ensure the find_eq.py script is located in the right place"
)

# walk through the cpython lib directory
cpython_files = []
Expand All @@ -48,7 +61,13 @@
with open(rustpython_lib / path, "r") as rustpython_file:
rustpython_code = rustpython_file.read()
# compare the files
diff = difflib.unified_diff(cpython_code.splitlines(), rustpython_code.splitlines(), lineterm="", fromfile=str(path), tofile=str(path))
diff = difflib.unified_diff(
cpython_code.splitlines(),
rustpython_code.splitlines(),
lineterm="",
fromfile=str(path),
tofile=str(path),
)
# print the diff if there are differences
diff = list(diff)
if len(diff) > 0:
Expand Down
78 changes: 59 additions & 19 deletions scripts/generate_checklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@
import requests
from jinja2 import Environment, FileSystemLoader

parser = argparse.ArgumentParser(description="Find equivalent files in cpython and rustpython")
parser.add_argument("--cpython", type=pathlib.Path, required=True, help="Path to cpython source code")
parser.add_argument("--notes", type=pathlib.Path, required=False, help="Path to notes file")
parser = argparse.ArgumentParser(
description="Find equivalent files in cpython and rustpython"
)
parser.add_argument(
"--cpython", type=pathlib.Path, required=True, help="Path to cpython source code"
)
parser.add_argument(
"--notes", type=pathlib.Path, required=False, help="Path to notes file"
)

args = parser.parse_args()


def check_pr(pr_id: str) -> bool:
if pr_id.startswith("#"):
pr_id = pr_id[1:]
Expand All @@ -27,11 +34,13 @@ def check_pr(pr_id: str) -> bool:
response = requests.get(req).json()
return response["merged_at"] is not None


@dataclasses.dataclass
class LibUpdate:
pr: Optional[str] = None
done: bool = True


def parse_updated_lib_issue(issue_body: str) -> dict[str, LibUpdate]:
lines = issue_body.splitlines()
updated_libs = {}
Expand All @@ -47,12 +56,14 @@ def parse_updated_lib_issue(issue_body: str) -> dict[str, LibUpdate]:
updated_libs[out[0]] = LibUpdate(out[1], check_pr(out[1]))
return updated_libs


def get_updated_libs() -> dict[str, LibUpdate]:
issue_id = "5736"
req = f"https://api.github.com/repos/RustPython/RustPython/issues/{issue_id}"
response = requests.get(req).json()
return parse_updated_lib_issue(response["body"])


updated_libs = get_updated_libs()

if not args.cpython.exists():
Expand Down Expand Up @@ -86,12 +97,11 @@ def get_updated_libs() -> dict[str, LibUpdate]:

cpython_lib = args.cpython / "Lib"
rustpython_lib = pathlib.Path(__file__).parent.parent / "Lib"
assert rustpython_lib.exists(), "RustPython lib directory does not exist, ensure the find_eq.py script is located in the right place"
assert rustpython_lib.exists(), (
"RustPython lib directory does not exist, ensure the find_eq.py script is located in the right place"
)

ignored_objs = [
"__pycache__",
"test"
]
ignored_objs = ["__pycache__", "test"]
# loop through the top-level directories in the cpython lib directory
libs = []
for path in cpython_lib.iterdir():
Expand All @@ -105,15 +115,25 @@ def get_updated_libs() -> dict[str, LibUpdate]:
tests = []
cpython_lib_test = cpython_lib / "test"
for path in cpython_lib_test.iterdir():
if path.is_dir() and path.name not in ignored_objs and path.name.startswith("test_"):
if (
path.is_dir()
and path.name not in ignored_objs
and path.name.startswith("test_")
):
# add the directory name to the list of libraries
tests.append(path.name)
elif path.is_file() and path.name.endswith(".py") and path.name not in ignored_objs and path.name.startswith("test_"):
elif (
path.is_file()
and path.name.endswith(".py")
and path.name not in ignored_objs
and path.name.startswith("test_")
):
# add the file name to the list of libraries
file_name = path.name.replace("test_", "")
if file_name not in libs and file_name.replace(".py", "") not in libs:
tests.append(path.name)


def check_diff(file1, file2):
try:
with open(file1, "r") as f1, open(file2, "r") as f2:
Expand All @@ -125,12 +145,14 @@ def check_diff(file1, file2):
except UnicodeDecodeError:
return False


def check_completion_pr(display_name):
for lib in updated_libs:
if lib == str(display_name):
return updated_libs[lib].done, updated_libs[lib].pr
return False, None


def check_test_completion(rustpython_path, cpython_path):
if rustpython_path.exists() and rustpython_path.is_file():
if cpython_path.exists() and cpython_path.is_file():
Expand All @@ -141,18 +163,22 @@ def check_test_completion(rustpython_path, cpython_path):
return True
return False


def check_lib_completion(rustpython_path, cpython_path):
test_name = "test_" + rustpython_path.name
rustpython_test_path = rustpython_lib / "test" / test_name
cpython_test_path = cpython_lib / "test" / test_name
if cpython_test_path.exists() and not check_test_completion(rustpython_test_path, cpython_test_path):
if cpython_test_path.exists() and not check_test_completion(
rustpython_test_path, cpython_test_path
):
return False
if rustpython_path.exists() and rustpython_path.is_file():
if check_diff(rustpython_path, cpython_path) > 0:
return False
return True
return False


def handle_notes(display_path) -> list[str]:
if str(display_path) in notes:
res = notes[str(display_path)]
Expand All @@ -161,13 +187,15 @@ def handle_notes(display_path) -> list[str]:
return res
return []


@dataclasses.dataclass
class Output:
name: str
pr: Optional[str]
completed: Optional[bool]
notes: list[str]


update_libs_output = []
add_libs_output = []
for path in libs:
Expand All @@ -183,12 +211,18 @@ class Output:
# check if the file exists in the rustpython lib directory
if rustpython_path.exists() and rustpython_path.is_file():
completed = check_lib_completion(rustpython_path, cpython_path)
update_libs_output.append(Output(str(display_path), pr, completed, handle_notes(display_path)))
update_libs_output.append(
Output(str(display_path), pr, completed, handle_notes(display_path))
)
else:
if pr is not None and completed:
update_libs_output.append(Output(str(display_path), pr, None, handle_notes(display_path)))
update_libs_output.append(
Output(str(display_path), pr, None, handle_notes(display_path))
)
else:
add_libs_output.append(Output(str(display_path), pr, None, handle_notes(display_path)))
add_libs_output.append(
Output(str(display_path), pr, None, handle_notes(display_path))
)

update_tests_output = []
add_tests_output = []
Expand All @@ -205,24 +239,30 @@ class Output:
# check if the file exists in the rustpython lib directory
if rustpython_path.exists() and rustpython_path.is_file():
completed = check_lib_completion(rustpython_path, cpython_path)
update_tests_output.append(Output(str(display_path), pr, completed, handle_notes(display_path)))
update_tests_output.append(
Output(str(display_path), pr, completed, handle_notes(display_path))
)
else:
if pr is not None and completed:
update_tests_output.append(Output(str(display_path), pr, None, handle_notes(display_path)))
update_tests_output.append(
Output(str(display_path), pr, None, handle_notes(display_path))
)
else:
add_tests_output.append(Output(str(display_path), pr, None, handle_notes(display_path)))
add_tests_output.append(
Output(str(display_path), pr, None, handle_notes(display_path))
)

for note in notes:
# add a warning for each note that is not attached to a file
for n in notes[note]:
warnings.warn(f"Unattached Note: {note} - {n}")

env = Environment(loader=FileSystemLoader('.'))
env = Environment(loader=FileSystemLoader("."))
template = env.get_template("checklist_template.md")
output = template.render(
update_libs=update_libs_output,
add_libs=add_libs_output,
update_tests=update_tests_output,
add_tests=add_tests_output
add_tests=add_tests_output,
)
print(output)
Loading