From 77c2d518ba1ee653f2edc313849034fd59ae13b2 Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Tue, 9 Jan 2024 18:37:25 +0000 Subject: [PATCH 01/15] Remove fix command --- src/cwhy/__main__.py | 1 - src/cwhy/cwhy.py | 4 ---- src/cwhy/prompts.py | 6 +----- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/cwhy/__main__.py b/src/cwhy/__main__.py index 0b1e551..c64bc3d 100755 --- a/src/cwhy/__main__.py +++ b/src/cwhy/__main__.py @@ -94,7 +94,6 @@ def main(): subparsers = parser.add_subparsers(title="subcommands", dest="subcommand") subparsers.add_parser("explain", help="Explain the diagnostic. (default)") - subparsers.add_parser("fix", help="Propose a fix for the diagnostic.") subparsers.add_parser("diff", help="[experimental] Propose a fix in diff format.") subparsers.add_parser( "converse", help="[experimental] A back-and-forth mode with ChatGPT." diff --git a/src/cwhy/cwhy.py b/src/cwhy/cwhy.py index 5c192f6..e3c3ce3 100755 --- a/src/cwhy/cwhy.py +++ b/src/cwhy/cwhy.py @@ -97,8 +97,6 @@ def evaluate(client, args, stdin): if args.subcommand == "explain": return evaluate_text_prompt(client, args, prompts.explain_prompt(args, stdin)) - elif args.subcommand == "fix": - return evaluate_text_prompt(client, args, prompts.fix_prompt(args, stdin)) elif args.subcommand == "diff": return ( evaluate_diff(client, args, stdin) @@ -118,8 +116,6 @@ def main(args, stdin): args.llm = _DEFAULT_FALLBACK_MODELS[0] if args.subcommand == "explain": print(prompts.explain_prompt(args, stdin)) - elif args.subcommand == "fix": - print(prompts.fix_prompt(args, stdin)) elif args.subcommand == "diff": print(prompts.diff_prompt(args, stdin)) print("==================================================") diff --git a/src/cwhy/prompts.py b/src/cwhy/prompts.py index 1854ae2..b58e701 100644 --- a/src/cwhy/prompts.py +++ b/src/cwhy/prompts.py @@ -210,13 +210,9 @@ def _base_prompt(args, diagnostic): def explain_prompt(args, diagnostic): - return _base_prompt(args, diagnostic) + "What's the problem?" - - -def fix_prompt(args, diagnostic): return ( _base_prompt(args, diagnostic) - + "Suggest code to fix the problem. Surround the code in backticks (```)." + + "What's the problem? If you can, suggest code to fix the issue." ) From 6fba56e1444b39fc52f09c5d5cfed595b68769d3 Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Tue, 9 Jan 2024 18:38:20 +0000 Subject: [PATCH 02/15] Import cleanup --- src/cwhy/prompts.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cwhy/prompts.py b/src/cwhy/prompts.py index b58e701..22ff50c 100644 --- a/src/cwhy/prompts.py +++ b/src/cwhy/prompts.py @@ -1,6 +1,6 @@ import collections import re -from typing import Dict, List, Tuple +import sys from llm_utils import llm_utils @@ -114,7 +114,7 @@ def get_code(self): if not self.code_locations: return None - def format_group_code_block(group: List[str], last: int) -> str: + def format_group_code_block(group: list[str], last: int) -> str: """ Format a group of consecutive lines from a single file as a code block. Include line numbers in front of each line. @@ -143,7 +143,7 @@ def format_group_code_block(group: List[str], last: int) -> str: result += "```\n\n" return result - def format_file_locations(filename: str, lines: Dict[int, str]) -> str: + def format_file_locations(filename: str, lines: dict[int, str]) -> str: """ Format all the lines from a single file as a code block. There may be multiple groups: lines 1-10 and 100-110 for example. From 0389c39edc84475947dfb3e8dec4a2df556572de Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Tue, 9 Jan 2024 19:09:31 +0000 Subject: [PATCH 03/15] Minor prompt fix --- src/cwhy/conversation/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cwhy/conversation/__init__.py b/src/cwhy/conversation/__init__.py index 1cd00ec..0b88253 100644 --- a/src/cwhy/conversation/__init__.py +++ b/src/cwhy/conversation/__init__.py @@ -15,7 +15,7 @@ def converse(client, args, diagnostic): f""" You are an assistant debugger. The user is having an issue with their code, and you are trying to help them. A few functions exist to help with this process, namely: {", ".join(available_functions_names)}. - Once you are confident in your answer, explain the diagnostic and possibly provide a way to fix the issue. + Once you are confident in your answer, explain the diagnostic and provide a way to fix the issue if you can. """ ).strip() user_message = f"Here is my error message:\n\n```\n{fns.get_truncated_error_message()}\n```\n\nWhat's the problem?" From a38c326c3254082590d3af3be9f69fbe787c818a Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Tue, 9 Jan 2024 20:24:31 +0000 Subject: [PATCH 04/15] Rich output, typing --- pyproject.toml | 5 +- src/cwhy/__main__.py | 101 ++++++++++++++++++----------- src/cwhy/conversation/functions.py | 14 ++-- src/cwhy/prompts.py | 12 ++-- tests/regression.py | 2 +- tests/runner-diff.py | 3 +- tests/runner.py | 2 +- 7 files changed, 84 insertions(+), 55 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b6273fd..70d23a5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ authors = [ { name="Nicolas van Kempen", email="nvankemp@gmail.com" }, { name="Bryce Adelstein Lelbach", email="brycelelbach@gmail.com" } ] -dependencies = ["llm_utils==0.2.2", "openai>=1.3.6", "PyYAML>=6.0.1"] +dependencies = ["llm_utils==0.2.3", "openai>=1.3.6", "PyYAML>=6.0.1", "rich>=13.7.0"] description = "Explains and proposes fixes for compile-time errors for many programming languages." readme = "README.md" requires-python = ">=3.7" @@ -26,3 +26,6 @@ cwhy = "cwhy.__main__:main" [project.urls] "Homepage" = "https://github.com/plasma-umass/cwhy" "Bug Tracker" = "https://github.com/plasma-umass/cwhy/issues" + +[project.optional-dependencies] +dev = ["types-PyYAML>=6.0.1"] diff --git a/src/cwhy/__main__.py b/src/cwhy/__main__.py index c64bc3d..55ca7eb 100755 --- a/src/cwhy/__main__.py +++ b/src/cwhy/__main__.py @@ -6,56 +6,92 @@ import sys import tempfile import textwrap +from typing import Any, Optional import openai +from rich.console import Console from . import cwhy def wrapper(args): - return textwrap.dedent( - f""" - #! {sys.executable} - from cwhy import cwhy - cwhy.wrapper({args}) + return ( + textwrap.dedent( + f""" + #! {sys.executable} + from cwhy import cwhy + cwhy.wrapper({args}) """ - ).lstrip() + ).strip() + + "\n" + ) + + +class RichArgParser(argparse.ArgumentParser): + def __init__(self, *args: Any, **kwargs: Any): + self.console = Console(highlight=False) + super().__init__(*args, **kwargs) + + def _print_message(self, message: Optional[str], file: Any = None) -> None: + if message: + self.console.print(message) + + +class CWhyArgumentFormatter(argparse.HelpFormatter): + def _fill_text(self, text, width, indent): + return "".join(indent + line for line in text.splitlines(keepends=True)) + + def _get_help_string(self, action): + help = action.help + if "%(default)" not in action.help: + if action.default is not argparse.SUPPRESS: + defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE] + if action.option_strings or action.nargs in defaulting_nargs: + help += " (default: %(default)s)" + return help def main(): - parser = argparse.ArgumentParser( + description = textwrap.dedent( + rf""" + [b]CWhy[/b]: Explains and proposes fixes for compile-time errors for many programming languages. + [blue][link=https://github.com/plasma-umass/cwhy]https://github.com/plasma-umass/cwhy[/link][/blue] + + usage: + [b]cwhy \[OPTIONS...] --- COMMAND...[/b] + usage (GNU Make): + [b]CXX=`cwhy --wrapper \[OPTIONS...] --- c++` make[/b] + usage (CMake): + [b]cmake -DCMAKE_CXX_COMPILER=`cwhy --wrapper \[OPTIONS...] --- c++`[/b] + """ + ).strip() + + parser = RichArgParser( prog="cwhy", - description="CWhy explains and fixes compiler diagnostic errors.", - formatter_class=argparse.ArgumentDefaultsHelpFormatter, - add_help=False, + usage=argparse.SUPPRESS, + description=description, + formatter_class=CWhyArgumentFormatter, ) - parser.add_argument( - "--help", - "-h", - action="help", - default=argparse.SUPPRESS, - help="Show this help message and exit.", - ) parser.add_argument( "--version", action="version", version=f"%(prog)s v{importlib.metadata.metadata('cwhy')['Version']}", default=argparse.SUPPRESS, - help="Print the version of CWhy and exit.", + help="print the version of CWhy and exit.", ) parser.add_argument( "--llm", type=str, default="default", - help="The language model to use, e.g., 'gpt-3.5-turbo' or 'gpt-4'. The default mode tries gpt-4 and falls back to gpt-3.5-turbo.", + help="the language model to use, e.g., 'gpt-3.5-turbo' or 'gpt-4'. The default mode tries gpt-4 and falls back to gpt-3.5-turbo.", ) parser.add_argument( "--timeout", type=int, default=60, - help="The timeout for API calls in seconds.", + help="the timeout for API calls in seconds.", ) # The default maximum context length for `gpt-3.5-turbo` is 4096 tokens. # We keep 256 tokens for other parts of the prompt, and split the remainder in two @@ -64,41 +100,32 @@ def main(): "--max-error-tokens", type=int, default=1920, - help="The maximum number of tokens from the error message to send in the prompt.", + help="the maximum number of tokens from the error message to send in the prompt.", ) parser.add_argument( "--max-code-tokens", type=int, default=1920, - help="The maximum number of code locations tokens to send in the prompt.", + help="the maximum number of code locations tokens to send in the prompt.", ) parser.add_argument( "--show-prompt", action="store_true", - help="When enabled, only print prompt and exit (for debugging purposes).", + help="when enabled, only print prompt and exit (for debugging purposes).", ) parser.add_argument( "--wrapper", action="store_true", - help="Enable compiler wrapper behavior.", - ) - parser.add_argument( - "--wrapper-compiler", - metavar="COMPILER", - type=str, - default="c++", - help="The underlying compiler. Only enabled with --wrapper.", + help="generate a temporary executable used to wrap to compiler command.", ) - subparsers = parser.add_subparsers(title="subcommands", dest="subcommand") - - subparsers.add_parser("explain", help="Explain the diagnostic. (default)") - subparsers.add_parser("diff", help="[experimental] Propose a fix in diff format.") + subparsers = parser.add_subparsers(title="Subcommands", dest="subcommand") + subparsers.add_parser("explain", help="explain the diagnostic. (default)") + subparsers.add_parser("diff", help="\[experimental] propose a fix in diff format.") subparsers.add_parser( - "converse", help="[experimental] A back-and-forth mode with ChatGPT." + "converse", help="\[experimental] a conversation mode with ChatGPT." ) - parser.set_defaults(subcommand="explain") args = parser.parse_args() diff --git a/src/cwhy/conversation/functions.py b/src/cwhy/conversation/functions.py index 7a5e853..be29e76 100644 --- a/src/cwhy/conversation/functions.py +++ b/src/cwhy/conversation/functions.py @@ -1,4 +1,5 @@ import json +from typing import Optional from llm_utils import llm_utils @@ -18,7 +19,7 @@ def as_tools(self): ] ] - def dispatch(self, function_call) -> str: + def dispatch(self, function_call) -> Optional[str]: arguments = json.loads(function_call.arguments) print( f"Calling: {function_call.name}({', '.join([f'{k}={v}' for k, v in arguments.items()])})" @@ -34,7 +35,6 @@ def dispatch(self, function_call) -> str: ) except Exception as e: print(e) - pass return None def get_truncated_error_message_schema(self): @@ -47,8 +47,8 @@ def get_truncated_error_message(self) -> str: """ Alternate taking front and back lines until the maximum number of tokens. """ - front = [] - back = [] + front: list[str] = [] + back: list[str] = [] diagnostic_lines = self.diagnostic.splitlines() n = len(diagnostic_lines) @@ -69,15 +69,15 @@ def build_diagnostic_string(): break return build_diagnostic_string() - def get_compile_or_run_command_schema(): + def get_compile_or_run_command_schema(self): return { "name": "get_compile_or_run_command", "description": "Returns the command used to compile or run the code.", } - def get_compile_or_run_command() -> str: + def get_compile_or_run_command(self) -> str: # TODO. - pass + return "Not implemented." def get_code_surrounding_schema(self): return { diff --git a/src/cwhy/prompts.py b/src/cwhy/prompts.py index 22ff50c..b7c6159 100644 --- a/src/cwhy/prompts.py +++ b/src/cwhy/prompts.py @@ -83,8 +83,8 @@ def get_diagnostic(self) -> str: """ Alternate taking front and back lines until the maximum number of tokens. """ - front = [] - back = [] + front: list[str] = [] + back: list[str] = [] n = len(self.diagnostic_lines) def build_diagnostic_string(): @@ -156,12 +156,12 @@ def format_file_locations(filename: str, lines: dict[int, str]) -> str: One or more concatenated formatted code blocks. """ # Sort lines by line number. - lines = sorted(lines.items(), key=lambda x: x[0]) + sorted_lines = sorted(lines.items(), key=lambda x: x[0]) result = "" last = None group = [] - for line_number, line_content in lines: + for line_number, line_content in sorted_lines: if last is None or line_number == last + 1: group.append(line_content) last = line_number @@ -176,8 +176,8 @@ def format_file_locations(filename: str, lines: dict[int, str]) -> str: return result formatted_file_locations = [ - format_file_locations(filename, lines) - for filename, lines in self.code_locations.items() + format_file_locations(filename, sorted_lines) + for filename, sorted_lines in self.code_locations.items() ] counts = [ diff --git a/tests/regression.py b/tests/regression.py index b4a905c..92c78cc 100644 --- a/tests/regression.py +++ b/tests/regression.py @@ -5,7 +5,7 @@ import yaml -import prepare +from . import prepare ROOT = os.path.dirname(os.path.abspath(__file__)) diff --git a/tests/runner-diff.py b/tests/runner-diff.py index c5c51cd..49a667b 100755 --- a/tests/runner-diff.py +++ b/tests/runner-diff.py @@ -9,8 +9,7 @@ from cwhy import cwhy -import anonymizer -import apply_diff +from . import anonymizer, apply_diff ROOT = os.path.dirname(os.path.abspath(__file__)) diff --git a/tests/runner.py b/tests/runner.py index 2f6cbb5..8272688 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -9,7 +9,7 @@ from cwhy import cwhy -import anonymizer +from . import anonymizer ROOT = os.path.dirname(os.path.abspath(__file__)) From 120cb2ecf2c1f239df5212f4209c43db8d089abb Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Tue, 9 Jan 2024 20:46:05 +0000 Subject: [PATCH 05/15] More argparse fixes --- src/cwhy/__main__.py | 67 ++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/src/cwhy/__main__.py b/src/cwhy/__main__.py index 55ca7eb..0f2eccc 100755 --- a/src/cwhy/__main__.py +++ b/src/cwhy/__main__.py @@ -38,12 +38,19 @@ def _print_message(self, message: Optional[str], file: Any = None) -> None: class CWhyArgumentFormatter(argparse.HelpFormatter): + # RawDescriptionHelpFormatter. def _fill_text(self, text, width, indent): return "".join(indent + line for line in text.splitlines(keepends=True)) + # RawTextHelpFormatter. + def _split_lines(self, text, width): + return text.splitlines() + + # ArgumentDefaultsHelpFormatter. + # Ignore if help message is multiline. def _get_help_string(self, action): help = action.help - if "%(default)" not in action.help: + if "\n" not in help and "%(default)" not in action.help: if action.default is not argparse.SUPPRESS: defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE] if action.option_strings or action.nargs in defaulting_nargs: @@ -58,7 +65,7 @@ def main(): [blue][link=https://github.com/plasma-umass/cwhy]https://github.com/plasma-umass/cwhy[/link][/blue] usage: - [b]cwhy \[OPTIONS...] --- COMMAND...[/b] + [b]cwhy [SUBCOMMAND] \[OPTIONS...] --- COMMAND...[/b] usage (GNU Make): [b]CXX=`cwhy --wrapper \[OPTIONS...] --- c++` make[/b] usage (CMake): @@ -78,20 +85,40 @@ def main(): action="version", version=f"%(prog)s v{importlib.metadata.metadata('cwhy')['Version']}", default=argparse.SUPPRESS, - help="print the version of CWhy and exit.", + help="print the version of CWhy and exit", + ) + + parser.add_argument( + "subcommand", + nargs="?", + default="explain", + choices=["explain", "diff", "converse"], + metavar="subcommand", + help=textwrap.dedent( + """ + explain: explain the diagnostic (default) + diff: generate a diff to fix the diagnostic + converse: interactively converse with CWhy + """ + ).strip(), ) parser.add_argument( "--llm", type=str, default="default", - help="the language model to use, e.g., 'gpt-3.5-turbo' or 'gpt-4'. The default mode tries gpt-4 and falls back to gpt-3.5-turbo.", + help=textwrap.dedent( + """ + the language model to use, e.g., 'gpt-3.5-turbo' or 'gpt-4' + the default mode tries gpt-4 and falls back to gpt-3.5-turbo + """ + ).strip(), ) parser.add_argument( "--timeout", type=int, default=60, - help="the timeout for API calls in seconds.", + help="the timeout for API calls in seconds", ) # The default maximum context length for `gpt-3.5-turbo` is 4096 tokens. # We keep 256 tokens for other parts of the prompt, and split the remainder in two @@ -100,33 +127,32 @@ def main(): "--max-error-tokens", type=int, default=1920, - help="the maximum number of tokens from the error message to send in the prompt.", + help="the maximum number of tokens from the error message to send in the prompt", ) parser.add_argument( "--max-code-tokens", type=int, default=1920, - help="the maximum number of code locations tokens to send in the prompt.", + help="the maximum number of code locations tokens to send in the prompt", ) parser.add_argument( "--show-prompt", action="store_true", - help="when enabled, only print prompt and exit (for debugging purposes).", + help="when enabled, only print prompt and exit (for debugging purposes)", ) parser.add_argument( "--wrapper", action="store_true", - help="generate a temporary executable used to wrap to compiler command.", + help="generate a temporary executable used to wrap to compiler command", ) - - subparsers = parser.add_subparsers(title="Subcommands", dest="subcommand") - subparsers.add_parser("explain", help="explain the diagnostic. (default)") - subparsers.add_parser("diff", help="\[experimental] propose a fix in diff format.") - subparsers.add_parser( - "converse", help="\[experimental] a conversation mode with ChatGPT." + parser.add_argument( + "---", + dest="command", + required=True, + help=argparse.SUPPRESS, + nargs=argparse.REMAINDER, ) - parser.set_defaults(subcommand="explain") args = parser.parse_args() @@ -138,14 +164,7 @@ def main(): os.chmod(f.name, 0o755) print(f.name) else: - stdin = sys.stdin.read() - if not stdin: - return - try: - print(cwhy.main(args, stdin)) - except (openai.NotFoundError, openai.RateLimitError, openai.APITimeoutError): - # This type of exceptions should have been handled down the stack. - pass + cwhy.wrapper(args) if __name__ == "__main__": From b4d227c2669e3d42d3e96a560e6b384e9992a53e Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Tue, 9 Jan 2024 21:12:14 +0000 Subject: [PATCH 06/15] Complete wrapper behavior --- src/cwhy/__main__.py | 2 +- src/cwhy/cwhy.py | 60 +++++++++++++++++++++++--------------------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/cwhy/__main__.py b/src/cwhy/__main__.py index 0f2eccc..9fe0ecf 100755 --- a/src/cwhy/__main__.py +++ b/src/cwhy/__main__.py @@ -164,7 +164,7 @@ def main(): os.chmod(f.name, 0o755) print(f.name) else: - cwhy.wrapper(args) + cwhy.main(args) if __name__ == "__main__": diff --git a/src/cwhy/cwhy.py b/src/cwhy/cwhy.py index e3c3ce3..0bf56aa 100755 --- a/src/cwhy/cwhy.py +++ b/src/cwhy/cwhy.py @@ -109,27 +109,44 @@ def evaluate(client, args, stdin): raise Exception(f"unknown subcommand: {args.subcommand}") -def main(args, stdin): +def main(args): + process = subprocess.run( + [*args.command], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + ) + + status = process.returncode + if status == 0: + return + if args.show_prompt: print("===================== Prompt =====================") if args.llm == "default": args.llm = _DEFAULT_FALLBACK_MODELS[0] if args.subcommand == "explain": - print(prompts.explain_prompt(args, stdin)) + print(prompts.explain_prompt(args, process.stderr)) elif args.subcommand == "diff": - print(prompts.diff_prompt(args, stdin)) + print(prompts.diff_prompt(args, process.stderr)) print("==================================================") sys.exit(0) - try: - client = openai.OpenAI(timeout=args.timeout) - except openai.OpenAIError: - print("You need an OpenAI key to use this tool.") - print("You can get a key here: https://platform.openai.com/api-keys") - print("Set the environment variable OPENAI_API_KEY to your key value.") - sys.exit(1) - - return evaluate(client, args, stdin) + print(process.stdout) + print(process.stderr, file=sys.stderr) + if "CWHY_DISABLE" not in os.environ: + print("==================================================") + print("CWhy") + print("==================================================") + try: + client = openai.OpenAI(timeout=args.timeout) + except openai.OpenAIError: + print("You need an OpenAI key to use this tool.") + print("You can get a key here: https://platform.openai.com/api-keys") + print("Set the environment variable OPENAI_API_KEY to your key value.") + sys.exit(1) + print(evaluate(client, args, process.stderr)) + print("==================================================") def evaluate_text_prompt(client, args, prompt, wrap=True, **kwargs): @@ -149,20 +166,5 @@ def evaluate_text_prompt(client, args, prompt, wrap=True, **kwargs): def wrapper(args): - process = subprocess.run( - [args.wrapper_compiler, *sys.argv[1:]], - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - text=True, - ) - - status = process.returncode - if status != 0: - print(process.stdout) - if "CWHY_DISABLE" not in os.environ: - print("==================================================") - print("CWhy") - print("==================================================") - print(evaluate(args, process.stdout)) - print("==================================================") - sys.exit(status) + args.command.extend(sys.argv[1:]) + main(args) From 533c88b86bd933a58744f49011c206313febfd6b Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Tue, 9 Jan 2024 21:13:18 +0000 Subject: [PATCH 07/15] Add back experimental tags --- src/cwhy/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cwhy/__main__.py b/src/cwhy/__main__.py index 9fe0ecf..a4b9574 100755 --- a/src/cwhy/__main__.py +++ b/src/cwhy/__main__.py @@ -97,8 +97,8 @@ def main(): help=textwrap.dedent( """ explain: explain the diagnostic (default) - diff: generate a diff to fix the diagnostic - converse: interactively converse with CWhy + diff: \[experimental] generate a diff to fix the diagnostic + converse: \[experimental] interactively converse with CWhy """ ).strip(), ) From 1e552f315e155335668ca717c05ca9147ea5cdc2 Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Tue, 9 Jan 2024 21:20:01 +0000 Subject: [PATCH 08/15] Fix wrapper --- src/cwhy/__main__.py | 2 +- src/cwhy/cwhy.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cwhy/__main__.py b/src/cwhy/__main__.py index a4b9574..c18ffdb 100755 --- a/src/cwhy/__main__.py +++ b/src/cwhy/__main__.py @@ -20,7 +20,7 @@ def wrapper(args): f""" #! {sys.executable} from cwhy import cwhy - cwhy.wrapper({args}) + cwhy.wrapper({vars(args)}) """ ).strip() + "\n" diff --git a/src/cwhy/cwhy.py b/src/cwhy/cwhy.py index 0bf56aa..e67c4f0 100755 --- a/src/cwhy/cwhy.py +++ b/src/cwhy/cwhy.py @@ -1,3 +1,4 @@ +import argparse import os import subprocess import sys @@ -117,8 +118,7 @@ def main(args): text=True, ) - status = process.returncode - if status == 0: + if process.returncode == 0: return if args.show_prompt: @@ -148,6 +148,8 @@ def main(args): print(evaluate(client, args, process.stderr)) print("==================================================") + sys.exit(process.returncode) + def evaluate_text_prompt(client, args, prompt, wrap=True, **kwargs): completion = complete(client, args, prompt, **kwargs) @@ -166,5 +168,6 @@ def evaluate_text_prompt(client, args, prompt, wrap=True, **kwargs): def wrapper(args): + args = argparse.Namespace(**args) args.command.extend(sys.argv[1:]) main(args) From 086e8a93e05fd92f8ad79bd2202a463c9c82d736 Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Wed, 10 Jan 2024 14:08:58 +0000 Subject: [PATCH 09/15] Fix regression tests --- tests/regression.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/tests/regression.py b/tests/regression.py index 92c78cc..a7aacbe 100644 --- a/tests/regression.py +++ b/tests/regression.py @@ -5,32 +5,22 @@ import yaml -from . import prepare +import prepare ROOT = os.path.dirname(os.path.abspath(__file__)) -def get_diagnostic(invocation): - return subprocess.run( - invocation, - shell=True, - text=True, - stdout=subprocess.DEVNULL, - stderr=subprocess.PIPE, - cwd=ROOT, - ).stderr - - def get_cwhy_prompt(invocation): - diagnostic = get_diagnostic(invocation) - process = subprocess.Popen( - ["cwhy", "--show-prompt"], + process = subprocess.run( + f"cwhy --show-prompt --- {invocation}", text=True, + shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + cwd=ROOT, ) - stdout, stderr = process.communicate(diagnostic) + stdout, stderr = process.stdout, process.stderr if stderr.strip(): print("CWhy reported an error or warning.") print(stderr.strip()) From 9c9ffbaa1b9fae426dbed601b95d14c8970ecbdd Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Wed, 10 Jan 2024 14:15:05 +0000 Subject: [PATCH 10/15] Add typecheck to CI --- .github/workflows/sanity.yml | 6 ++++++ tests/regression.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sanity.yml b/.github/workflows/sanity.yml index 43bef67..502a084 100644 --- a/.github/workflows/sanity.yml +++ b/.github/workflows/sanity.yml @@ -16,12 +16,18 @@ jobs: - name: Update pip run: python3 -m pip install --upgrade pip + - name: Install dependencies + run: python3 -m pip install mypy + - name: Install run: python3 -m pip install . - name: Install in editable mode run: python3 -m pip install -e . + - name: Run mypy + run: python3 -m mypy src/**/*.py tests/*.py + - name: Check version through Python run: python3 -m cwhy --version diff --git a/tests/regression.py b/tests/regression.py index a7aacbe..b26d02f 100644 --- a/tests/regression.py +++ b/tests/regression.py @@ -5,7 +5,7 @@ import yaml -import prepare +from . import prepare ROOT = os.path.dirname(os.path.abspath(__file__)) From 1a6f59b66622d836f703539249270954d15fa332 Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Wed, 10 Jan 2024 14:21:02 +0000 Subject: [PATCH 11/15] Fix sanity CI --- .github/workflows/sanity.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/sanity.yml b/.github/workflows/sanity.yml index 502a084..d990fee 100644 --- a/.github/workflows/sanity.yml +++ b/.github/workflows/sanity.yml @@ -19,12 +19,12 @@ jobs: - name: Install dependencies run: python3 -m pip install mypy - - name: Install - run: python3 -m pip install . - - name: Install in editable mode run: python3 -m pip install -e . + - name: Install in development mode + run: python3 -m pip install .[dev] + - name: Run mypy run: python3 -m mypy src/**/*.py tests/*.py From 8b10629a4aa45933e7102f006981ee0d15e7f38e Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Wed, 10 Jan 2024 14:29:10 +0000 Subject: [PATCH 12/15] Fix regression CI --- .github/workflows/regression-check.yml | 6 +++--- .github/workflows/regression-generate.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/regression-check.yml b/.github/workflows/regression-check.yml index cc05ee8..d19882a 100644 --- a/.github/workflows/regression-check.yml +++ b/.github/workflows/regression-check.yml @@ -25,7 +25,7 @@ jobs: python3 -m pip install . - name: Check prompts - run: python3 tests/regression.py --platform ubuntu --check + run: python3 -m tests.regression --platform ubuntu --check check-macos: runs-on: macos-latest @@ -39,7 +39,7 @@ jobs: python3 -m pip install . - name: Check prompts - run: python3 tests/regression.py --platform macos --check + run: python3 -m tests.regression --platform macos --check check-windows: runs-on: windows-latest @@ -53,4 +53,4 @@ jobs: python3 -m pip install . - name: Check prompts - run: python3 tests/regression.py --platform windows --check + run: python3 -m tests.regression --platform windows --check diff --git a/.github/workflows/regression-generate.yml b/.github/workflows/regression-generate.yml index fbf6f1c..12307cc 100644 --- a/.github/workflows/regression-generate.yml +++ b/.github/workflows/regression-generate.yml @@ -31,7 +31,7 @@ jobs: python3 -m pip install . - name: Generate current prompts - run: python3 tests/regression.py --platform ubuntu --generate + run: python3 -m tests.regression --platform ubuntu --generate - name: Commit run: | @@ -58,7 +58,7 @@ jobs: python3 -m pip install . - name: Generate current prompts - run: python3 tests/regression.py --platform macos --generate + run: python3 -m tests.regression --platform macos --generate - name: Commit run: | @@ -85,7 +85,7 @@ jobs: python3 -m pip install . - name: Generate current prompts - run: python3 tests/regression.py --platform windows --generate + run: python3 -m tests.regression --platform windows --generate - name: Commit run: | From 2b00b5dd60ecdfcb83574c4ed9658723eb9cb216 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:34:06 -0500 Subject: [PATCH 13/15] [bot] Generate current state of CWhy prompts (#50) * [bot][macos] Generate current state of CWhy prompts * [bot][ubuntu] Generate current state of CWhy prompts --------- Co-authored-by: github-actions --- tests/.regression/macos/clang++/ctre-test.cpp | 2 +- tests/.regression/macos/clang++/missing-hash.cpp | 2 +- tests/.regression/macos/clang++/missing-ostream-operator.cpp | 2 +- tests/.regression/macos/clang++/missing-struct-semicolon.cpp | 2 +- ...rload-resolution-failure-bind-const-ref-to-non-const-ref.cpp | 2 +- .../overload-resolution-failure-transform-missing-argument.cpp | 2 +- tests/.regression/macos/clang++/push-back-pointer.cpp | 2 +- tests/.regression/macos/clang++/redeclared-function.cpp | 2 +- .../macos/clang++/redeclared-variable-deduction-order.cpp | 2 +- tests/.regression/macos/clang++/redefined-function.cpp | 2 +- tests/.regression/macos/clang++/reverse-iterator.cpp | 2 +- tests/.regression/macos/clang++/sfinae-ambiguous.cpp | 2 +- .../sfinae-trailing-return-type-conditional-noexcept.cpp | 2 +- tests/.regression/macos/clang++/sfinae-trailing-return-type.cpp | 2 +- tests/.regression/macos/clang++/template-recursion.cpp | 2 +- tests/.regression/ubuntu/clang++/ctre-test.cpp | 2 +- tests/.regression/ubuntu/clang++/missing-hash.cpp | 2 +- tests/.regression/ubuntu/clang++/missing-ostream-operator.cpp | 2 +- tests/.regression/ubuntu/clang++/missing-struct-semicolon.cpp | 2 +- ...rload-resolution-failure-bind-const-ref-to-non-const-ref.cpp | 2 +- .../overload-resolution-failure-transform-missing-argument.cpp | 2 +- tests/.regression/ubuntu/clang++/push-back-pointer.cpp | 2 +- tests/.regression/ubuntu/clang++/redeclared-function.cpp | 2 +- .../ubuntu/clang++/redeclared-variable-deduction-order.cpp | 2 +- tests/.regression/ubuntu/clang++/redefined-function.cpp | 2 +- tests/.regression/ubuntu/clang++/reverse-iterator.cpp | 2 +- tests/.regression/ubuntu/clang++/sfinae-ambiguous.cpp | 2 +- .../sfinae-trailing-return-type-conditional-noexcept.cpp | 2 +- .../.regression/ubuntu/clang++/sfinae-trailing-return-type.cpp | 2 +- tests/.regression/ubuntu/clang++/template-recursion.cpp | 2 +- tests/.regression/ubuntu/g++/ctre-test.cpp | 2 +- tests/.regression/ubuntu/g++/missing-hash.cpp | 2 +- tests/.regression/ubuntu/g++/missing-ostream-operator.cpp | 2 +- tests/.regression/ubuntu/g++/missing-struct-semicolon.cpp | 2 +- ...rload-resolution-failure-bind-const-ref-to-non-const-ref.cpp | 2 +- .../overload-resolution-failure-transform-missing-argument.cpp | 2 +- tests/.regression/ubuntu/g++/push-back-pointer.cpp | 2 +- tests/.regression/ubuntu/g++/redeclared-function.cpp | 2 +- .../ubuntu/g++/redeclared-variable-deduction-order.cpp | 2 +- tests/.regression/ubuntu/g++/redefined-function.cpp | 2 +- tests/.regression/ubuntu/g++/reverse-iterator.cpp | 2 +- tests/.regression/ubuntu/g++/sfinae-ambiguous.cpp | 2 +- .../g++/sfinae-trailing-return-type-conditional-noexcept.cpp | 2 +- tests/.regression/ubuntu/g++/sfinae-trailing-return-type.cpp | 2 +- tests/.regression/ubuntu/g++/template-recursion.cpp | 2 +- 45 files changed, 45 insertions(+), 45 deletions(-) diff --git a/tests/.regression/macos/clang++/ctre-test.cpp b/tests/.regression/macos/clang++/ctre-test.cpp index fa56cc7..54314db 100644 --- a/tests/.regression/macos/clang++/ctre-test.cpp +++ b/tests/.regression/macos/clang++/ctre-test.cpp @@ -109,5 +109,5 @@ template struct problem_at_position; // do not define! ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/macos/clang++/missing-hash.cpp b/tests/.regression/macos/clang++/missing-hash.cpp index 6000837..f37c0e9 100644 --- a/tests/.regression/macos/clang++/missing-hash.cpp +++ b/tests/.regression/macos/clang++/missing-hash.cpp @@ -202,5 +202,5 @@ In file included from /Applications/Xcode_14.2.app/Contents/Developer/Platforms/ ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/macos/clang++/missing-ostream-operator.cpp b/tests/.regression/macos/clang++/missing-ostream-operator.cpp index c3ecfef..5f72683 100644 --- a/tests/.regression/macos/clang++/missing-ostream-operator.cpp +++ b/tests/.regression/macos/clang++/missing-ostream-operator.cpp @@ -104,5 +104,5 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec) ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/macos/clang++/missing-struct-semicolon.cpp b/tests/.regression/macos/clang++/missing-struct-semicolon.cpp index 12b1cde..ef7ea71 100644 --- a/tests/.regression/macos/clang++/missing-struct-semicolon.cpp +++ b/tests/.regression/macos/clang++/missing-struct-semicolon.cpp @@ -30,5 +30,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/macos/clang++/overload-resolution-failure-bind-const-ref-to-non-const-ref.cpp b/tests/.regression/macos/clang++/overload-resolution-failure-bind-const-ref-to-non-const-ref.cpp index 208d7b6..370ad6d 100644 --- a/tests/.regression/macos/clang++/overload-resolution-failure-bind-const-ref-to-non-const-ref.cpp +++ b/tests/.regression/macos/clang++/overload-resolution-failure-bind-const-ref-to-non-const-ref.cpp @@ -39,5 +39,5 @@ void f(float&) {} ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/macos/clang++/overload-resolution-failure-transform-missing-argument.cpp b/tests/.regression/macos/clang++/overload-resolution-failure-transform-missing-argument.cpp index 72f52ec..6e5d2fd 100644 --- a/tests/.regression/macos/clang++/overload-resolution-failure-transform-missing-argument.cpp +++ b/tests/.regression/macos/clang++/overload-resolution-failure-transform-missing-argument.cpp @@ -58,5 +58,5 @@ transform(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __f ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/macos/clang++/push-back-pointer.cpp b/tests/.regression/macos/clang++/push-back-pointer.cpp index c601ea5..47e6591 100644 --- a/tests/.regression/macos/clang++/push-back-pointer.cpp +++ b/tests/.regression/macos/clang++/push-back-pointer.cpp @@ -51,5 +51,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/macos/clang++/redeclared-function.cpp b/tests/.regression/macos/clang++/redeclared-function.cpp index 0e4c454..5a125d5 100644 --- a/tests/.regression/macos/clang++/redeclared-function.cpp +++ b/tests/.regression/macos/clang++/redeclared-function.cpp @@ -31,5 +31,5 @@ int f(); ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/macos/clang++/redeclared-variable-deduction-order.cpp b/tests/.regression/macos/clang++/redeclared-variable-deduction-order.cpp index 39098c6..b161422 100644 --- a/tests/.regression/macos/clang++/redeclared-variable-deduction-order.cpp +++ b/tests/.regression/macos/clang++/redeclared-variable-deduction-order.cpp @@ -33,5 +33,5 @@ extern decltype(f(0)) g; ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/macos/clang++/redefined-function.cpp b/tests/.regression/macos/clang++/redefined-function.cpp index 1d393bd..bf138a1 100644 --- a/tests/.regression/macos/clang++/redefined-function.cpp +++ b/tests/.regression/macos/clang++/redefined-function.cpp @@ -35,5 +35,5 @@ int f(int x, int y) { ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/macos/clang++/reverse-iterator.cpp b/tests/.regression/macos/clang++/reverse-iterator.cpp index 26c812d..e38f016 100644 --- a/tests/.regression/macos/clang++/reverse-iterator.cpp +++ b/tests/.regression/macos/clang++/reverse-iterator.cpp @@ -56,5 +56,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/macos/clang++/sfinae-ambiguous.cpp b/tests/.regression/macos/clang++/sfinae-ambiguous.cpp index 7d557e8..6db89f7 100644 --- a/tests/.regression/macos/clang++/sfinae-ambiguous.cpp +++ b/tests/.regression/macos/clang++/sfinae-ambiguous.cpp @@ -32,5 +32,5 @@ auto g(T t) -> decltype(f(t)) { ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/macos/clang++/sfinae-trailing-return-type-conditional-noexcept.cpp b/tests/.regression/macos/clang++/sfinae-trailing-return-type-conditional-noexcept.cpp index 64877f6..df4902a 100644 --- a/tests/.regression/macos/clang++/sfinae-trailing-return-type-conditional-noexcept.cpp +++ b/tests/.regression/macos/clang++/sfinae-trailing-return-type-conditional-noexcept.cpp @@ -34,5 +34,5 @@ auto g(T t) noexcept(noexcept(f(t))) -> decltype(f(t)) { ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/macos/clang++/sfinae-trailing-return-type.cpp b/tests/.regression/macos/clang++/sfinae-trailing-return-type.cpp index 51b349a..f9365a3 100644 --- a/tests/.regression/macos/clang++/sfinae-trailing-return-type.cpp +++ b/tests/.regression/macos/clang++/sfinae-trailing-return-type.cpp @@ -34,5 +34,5 @@ auto g(T t) -> decltype(f(t)) { ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/macos/clang++/template-recursion.cpp b/tests/.regression/macos/clang++/template-recursion.cpp index 6647a13..d933239 100644 --- a/tests/.regression/macos/clang++/template-recursion.cpp +++ b/tests/.regression/macos/clang++/template-recursion.cpp @@ -83,5 +83,5 @@ In file included from /Users/runner/work/cwhy/cwhy/tests/c++/template-recursion. ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/clang++/ctre-test.cpp b/tests/.regression/ubuntu/clang++/ctre-test.cpp index c90f47c..95578c4 100644 --- a/tests/.regression/ubuntu/clang++/ctre-test.cpp +++ b/tests/.regression/ubuntu/clang++/ctre-test.cpp @@ -109,5 +109,5 @@ In file included from /home/runner/work/cwhy/cwhy/tests/_deps/c++/ctre-test.cpp/ ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/clang++/missing-hash.cpp b/tests/.regression/ubuntu/clang++/missing-hash.cpp index 2dd9c90..3f52bcd 100644 --- a/tests/.regression/ubuntu/clang++/missing-hash.cpp +++ b/tests/.regression/ubuntu/clang++/missing-hash.cpp @@ -180,5 +180,5 @@ In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../includ ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/clang++/missing-ostream-operator.cpp b/tests/.regression/ubuntu/clang++/missing-ostream-operator.cpp index 0f307cc..36cfaf2 100644 --- a/tests/.regression/ubuntu/clang++/missing-ostream-operator.cpp +++ b/tests/.regression/ubuntu/clang++/missing-ostream-operator.cpp @@ -124,5 +124,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/clang++/missing-struct-semicolon.cpp b/tests/.regression/ubuntu/clang++/missing-struct-semicolon.cpp index 324f81a..8465eb4 100644 --- a/tests/.regression/ubuntu/clang++/missing-struct-semicolon.cpp +++ b/tests/.regression/ubuntu/clang++/missing-struct-semicolon.cpp @@ -30,5 +30,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/clang++/overload-resolution-failure-bind-const-ref-to-non-const-ref.cpp b/tests/.regression/ubuntu/clang++/overload-resolution-failure-bind-const-ref-to-non-const-ref.cpp index c40e092..c15c90a 100644 --- a/tests/.regression/ubuntu/clang++/overload-resolution-failure-bind-const-ref-to-non-const-ref.cpp +++ b/tests/.regression/ubuntu/clang++/overload-resolution-failure-bind-const-ref-to-non-const-ref.cpp @@ -39,5 +39,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/clang++/overload-resolution-failure-transform-missing-argument.cpp b/tests/.regression/ubuntu/clang++/overload-resolution-failure-transform-missing-argument.cpp index c87e561..7ec16c2 100644 --- a/tests/.regression/ubuntu/clang++/overload-resolution-failure-transform-missing-argument.cpp +++ b/tests/.regression/ubuntu/clang++/overload-resolution-failure-transform-missing-argument.cpp @@ -99,5 +99,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/clang++/push-back-pointer.cpp b/tests/.regression/ubuntu/clang++/push-back-pointer.cpp index 9c7787c..d4f1087 100644 --- a/tests/.regression/ubuntu/clang++/push-back-pointer.cpp +++ b/tests/.regression/ubuntu/clang++/push-back-pointer.cpp @@ -62,5 +62,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/clang++/redeclared-function.cpp b/tests/.regression/ubuntu/clang++/redeclared-function.cpp index 83198b8..163875e 100644 --- a/tests/.regression/ubuntu/clang++/redeclared-function.cpp +++ b/tests/.regression/ubuntu/clang++/redeclared-function.cpp @@ -31,5 +31,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/clang++/redeclared-variable-deduction-order.cpp b/tests/.regression/ubuntu/clang++/redeclared-variable-deduction-order.cpp index 34017ac..9d1cd45 100644 --- a/tests/.regression/ubuntu/clang++/redeclared-variable-deduction-order.cpp +++ b/tests/.regression/ubuntu/clang++/redeclared-variable-deduction-order.cpp @@ -33,5 +33,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/clang++/redefined-function.cpp b/tests/.regression/ubuntu/clang++/redefined-function.cpp index f924554..64b533b 100644 --- a/tests/.regression/ubuntu/clang++/redefined-function.cpp +++ b/tests/.regression/ubuntu/clang++/redefined-function.cpp @@ -35,5 +35,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/clang++/reverse-iterator.cpp b/tests/.regression/ubuntu/clang++/reverse-iterator.cpp index 923093b..c84da24 100644 --- a/tests/.regression/ubuntu/clang++/reverse-iterator.cpp +++ b/tests/.regression/ubuntu/clang++/reverse-iterator.cpp @@ -80,5 +80,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/clang++/sfinae-ambiguous.cpp b/tests/.regression/ubuntu/clang++/sfinae-ambiguous.cpp index e61d37b..bb22d41 100644 --- a/tests/.regression/ubuntu/clang++/sfinae-ambiguous.cpp +++ b/tests/.regression/ubuntu/clang++/sfinae-ambiguous.cpp @@ -32,5 +32,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/clang++/sfinae-trailing-return-type-conditional-noexcept.cpp b/tests/.regression/ubuntu/clang++/sfinae-trailing-return-type-conditional-noexcept.cpp index 7e6a573..77fbe7e 100644 --- a/tests/.regression/ubuntu/clang++/sfinae-trailing-return-type-conditional-noexcept.cpp +++ b/tests/.regression/ubuntu/clang++/sfinae-trailing-return-type-conditional-noexcept.cpp @@ -34,5 +34,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/clang++/sfinae-trailing-return-type.cpp b/tests/.regression/ubuntu/clang++/sfinae-trailing-return-type.cpp index b9db580..2da44b5 100644 --- a/tests/.regression/ubuntu/clang++/sfinae-trailing-return-type.cpp +++ b/tests/.regression/ubuntu/clang++/sfinae-trailing-return-type.cpp @@ -34,5 +34,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/clang++/template-recursion.cpp b/tests/.regression/ubuntu/clang++/template-recursion.cpp index 40d5614..41edd00 100644 --- a/tests/.regression/ubuntu/clang++/template-recursion.cpp +++ b/tests/.regression/ubuntu/clang++/template-recursion.cpp @@ -65,5 +65,5 @@ fatal error: recursive template instantiation exceeded maximum depth of 1024 ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/g++/ctre-test.cpp b/tests/.regression/ubuntu/g++/ctre-test.cpp index ec9a5e1..293bc84 100644 --- a/tests/.regression/ubuntu/g++/ctre-test.cpp +++ b/tests/.regression/ubuntu/g++/ctre-test.cpp @@ -206,5 +206,5 @@ In file included from /usr/include/c++/12/bits/stl_pair.h:60, ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/g++/missing-hash.cpp b/tests/.regression/ubuntu/g++/missing-hash.cpp index 39a22a7..b2e8400 100644 --- a/tests/.regression/ubuntu/g++/missing-hash.cpp +++ b/tests/.regression/ubuntu/g++/missing-hash.cpp @@ -158,5 +158,5 @@ In file included from /usr/include/c++/12/unordered_map:46, ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/g++/missing-ostream-operator.cpp b/tests/.regression/ubuntu/g++/missing-ostream-operator.cpp index 8c2e13d..ffee501 100644 --- a/tests/.regression/ubuntu/g++/missing-ostream-operator.cpp +++ b/tests/.regression/ubuntu/g++/missing-ostream-operator.cpp @@ -86,5 +86,5 @@ In file included from /usr/include/c++/12/iostream:39, ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/g++/missing-struct-semicolon.cpp b/tests/.regression/ubuntu/g++/missing-struct-semicolon.cpp index 7698462..14325e0 100644 --- a/tests/.regression/ubuntu/g++/missing-struct-semicolon.cpp +++ b/tests/.regression/ubuntu/g++/missing-struct-semicolon.cpp @@ -29,5 +29,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/g++/overload-resolution-failure-bind-const-ref-to-non-const-ref.cpp b/tests/.regression/ubuntu/g++/overload-resolution-failure-bind-const-ref-to-non-const-ref.cpp index 5e05f1c..ff66d5a 100644 --- a/tests/.regression/ubuntu/g++/overload-resolution-failure-bind-const-ref-to-non-const-ref.cpp +++ b/tests/.regression/ubuntu/g++/overload-resolution-failure-bind-const-ref-to-non-const-ref.cpp @@ -34,5 +34,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/g++/overload-resolution-failure-transform-missing-argument.cpp b/tests/.regression/ubuntu/g++/overload-resolution-failure-transform-missing-argument.cpp index bf967b9..28e67b9 100644 --- a/tests/.regression/ubuntu/g++/overload-resolution-failure-transform-missing-argument.cpp +++ b/tests/.regression/ubuntu/g++/overload-resolution-failure-transform-missing-argument.cpp @@ -108,5 +108,5 @@ In file included from /usr/include/c++/12/algorithm:73: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/g++/push-back-pointer.cpp b/tests/.regression/ubuntu/g++/push-back-pointer.cpp index bfc8bd1..03b65a3 100644 --- a/tests/.regression/ubuntu/g++/push-back-pointer.cpp +++ b/tests/.regression/ubuntu/g++/push-back-pointer.cpp @@ -76,5 +76,5 @@ In file included from /usr/include/c++/12/vector:64, ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/g++/redeclared-function.cpp b/tests/.regression/ubuntu/g++/redeclared-function.cpp index 275f655..3fd37b5 100644 --- a/tests/.regression/ubuntu/g++/redeclared-function.cpp +++ b/tests/.regression/ubuntu/g++/redeclared-function.cpp @@ -30,5 +30,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/g++/redeclared-variable-deduction-order.cpp b/tests/.regression/ubuntu/g++/redeclared-variable-deduction-order.cpp index ca49079..ea6f373 100644 --- a/tests/.regression/ubuntu/g++/redeclared-variable-deduction-order.cpp +++ b/tests/.regression/ubuntu/g++/redeclared-variable-deduction-order.cpp @@ -32,5 +32,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/g++/redefined-function.cpp b/tests/.regression/ubuntu/g++/redefined-function.cpp index fba51d1..2e33e53 100644 --- a/tests/.regression/ubuntu/g++/redefined-function.cpp +++ b/tests/.regression/ubuntu/g++/redefined-function.cpp @@ -34,5 +34,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/g++/reverse-iterator.cpp b/tests/.regression/ubuntu/g++/reverse-iterator.cpp index 2e7f00a..df5d2fb 100644 --- a/tests/.regression/ubuntu/g++/reverse-iterator.cpp +++ b/tests/.regression/ubuntu/g++/reverse-iterator.cpp @@ -89,5 +89,5 @@ In file included from /usr/include/c++/12/string:53, ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/g++/sfinae-ambiguous.cpp b/tests/.regression/ubuntu/g++/sfinae-ambiguous.cpp index 2030368..df492da 100644 --- a/tests/.regression/ubuntu/g++/sfinae-ambiguous.cpp +++ b/tests/.regression/ubuntu/g++/sfinae-ambiguous.cpp @@ -44,5 +44,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/g++/sfinae-trailing-return-type-conditional-noexcept.cpp b/tests/.regression/ubuntu/g++/sfinae-trailing-return-type-conditional-noexcept.cpp index 93c28b4..1ab0e2e 100644 --- a/tests/.regression/ubuntu/g++/sfinae-trailing-return-type-conditional-noexcept.cpp +++ b/tests/.regression/ubuntu/g++/sfinae-trailing-return-type-conditional-noexcept.cpp @@ -47,5 +47,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/g++/sfinae-trailing-return-type.cpp b/tests/.regression/ubuntu/g++/sfinae-trailing-return-type.cpp index 6eda0ae..a3340dc 100644 --- a/tests/.regression/ubuntu/g++/sfinae-trailing-return-type.cpp +++ b/tests/.regression/ubuntu/g++/sfinae-trailing-return-type.cpp @@ -47,5 +47,5 @@ This is my error: ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== diff --git a/tests/.regression/ubuntu/g++/template-recursion.cpp b/tests/.regression/ubuntu/g++/template-recursion.cpp index 6a7dd7e..70da8cb 100644 --- a/tests/.regression/ubuntu/g++/template-recursion.cpp +++ b/tests/.regression/ubuntu/g++/template-recursion.cpp @@ -52,5 +52,5 @@ compilation terminated. ``` -What's the problem? +What's the problem? If you can, suggest code to fix the issue. ================================================== From 61825d292f7eb39bdcb9f902b9c60bf0d00adbbf Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Wed, 10 Jan 2024 14:57:15 +0000 Subject: [PATCH 14/15] Fix extra newlines --- src/cwhy/cwhy.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cwhy/cwhy.py b/src/cwhy/cwhy.py index e67c4f0..a5ba10a 100755 --- a/src/cwhy/cwhy.py +++ b/src/cwhy/cwhy.py @@ -132,8 +132,8 @@ def main(args): print("==================================================") sys.exit(0) - print(process.stdout) - print(process.stderr, file=sys.stderr) + print(process.stdout, end="") + print(process.stderr, file=sys.stderr, end="") if "CWHY_DISABLE" not in os.environ: print("==================================================") print("CWhy") From bc2b9cf83e270fad8ab46a337a8a791113dcd05b Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Wed, 10 Jan 2024 15:12:53 +0000 Subject: [PATCH 15/15] Update README documentation --- README.md | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 86b7f68..db92e8a 100644 --- a/README.md +++ b/README.md @@ -30,26 +30,22 @@ python3 -m pip install cwhy ## Usage -### Compiler wrapper mode - -This new mode is recommended as CWhy will then operate in the same context as the compiler, and will do a better job -finding the right source files. +The wrapper mode is now default and mandatory, with a slightly modified interface. +CWhy can either be used standalone by passing the full command after the triple dashes `---`, or as part of a build tool +by creating a short executable script wrapping the compiler command. ```bash # Invoking the compiler directly. -% `cwhy --wrapper` mycode.cpp - -# Using fix mode. -% `cwhy --wrapper fix` mycode.cpp +% cwhy --- g++ mycode.cpp -# Using cwhy with Java. -% `cwhy --wrapper --wrapper-compiler=javac` mycode.java +# Using CWhy with Java and an increased timeout. +% cwhy --timeout 180 --- javac MyCode.java -# Invoking with GNU make, using GPT-4. -% CXX=`cwhy --llm=gpt-4 --wrapper` make +# Invoking with GNU Make, using GPT-3.5. +% CXX=`cwhy --llm=gpt-3.5-turbo --wrapper --- c++` make # Invoking with CMake, using GPT-4 and clang++. -% cmake -DCMAKE_CXX_COMPILER=`cwhy --llm=gpt-4 --wrapper --wrapper-compiler=clang++` ... +% cmake -DCMAKE_CXX_COMPILER=`cwhy --llm=gpt-4 --wrapper --- clang++` ... ``` When running a configuration tool such as CMake or Autoconf, this may greatly increase configuration time, as these @@ -61,14 +57,6 @@ configuration time. % CWHY_DISABLE=1 cmake -DCMAKE_CXX_COMPILER=`cwhy --wrapper` ... ``` -### Original mode - -Just pipe your compiler's output to `cwhy`. - -```bash -% clang++ -g mycode.cpp |& cwhy -``` - ### Options These options can be displayed with `cwhy --help`. @@ -77,8 +65,6 @@ These options can be displayed with `cwhy --help`. - `--timeout`: pick a different timeout than the default for API calls. - `--show-prompt` (debug): print prompts before calling the API. -The wrapper mode specifically also has a `--wrapper-compiler` option to select the underlying compiler to use. - ## Examples ### C++