Skip to content

Commit

Permalink
PoC
Browse files Browse the repository at this point in the history
  • Loading branch information
erlend-aasland committed Jan 17, 2024
1 parent e749f07 commit 853e777
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 7 additions & 4 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2495,6 +2495,7 @@ def parse_file(
limited_capi: bool,
output: str | None = None,
verify: bool = True,
force: bool = False,
) -> None:
if not output:
output = filename
Expand Down Expand Up @@ -2527,10 +2528,10 @@ def parse_file(
generated, cooked = clinic.parse(raw)

changes = [libclinic.file_changed(f, data) for f, data in generated]
if any(changes) or libclinic.file_changed(output, cooked):
if any(changes) or libclinic.file_changed(output, cooked) or force:
libclinic.write_file(output, cooked)
for (output, cooked), changed in zip(generated, changes):
if changed:
if changed or force:
libclinic.write_file(output, cooked)


Expand Down Expand Up @@ -6302,7 +6303,8 @@ def run_clinic(parser: argparse.ArgumentParser, ns: argparse.Namespace) -> None:
if ns.verbose:
print(path)
parse_file(path,
verify=not ns.force, limited_capi=ns.limited_capi)
verify=not ns.force, limited_capi=ns.limited_capi,
force=ns.force)
return

if not ns.filename:
Expand All @@ -6315,7 +6317,8 @@ def run_clinic(parser: argparse.ArgumentParser, ns: argparse.Namespace) -> None:
if ns.verbose:
print(filename)
parse_file(filename, output=ns.output,
verify=not ns.force, limited_capi=ns.limited_capi)
verify=not ns.force, limited_capi=ns.limited_capi,
force=ns.force)


def main(argv: list[str] | None = None) -> NoReturn:
Expand Down
1 change: 0 additions & 1 deletion Tools/clinic/libclinic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def file_changed(filename: str, new_contents: str) -> bool:
def write_file(filename: str, new_contents: str) -> None:
# Atomic write using a temporary file and os.replace()
filename_new = f"{filename}.new"
print("write to", filename)
with open(filename_new, "w", encoding="utf-8") as fp:
fp.write(new_contents)
try:
Expand Down

0 comments on commit 853e777

Please sign in to comment.