Skip to content

Commit 63411f6

Browse files
committed
Modify --debug flag and get.sh script
- `--debug` now doesn't capture exceptions, allowing for easier debugging - `get.sh` provides a single-command interface to parse problems
1 parent 2430706 commit 63411f6

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

get.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
if [[ $1 == "--debug" ]]; then
2+
shift
3+
python main.py --debug get -l cpp -l python -p contest $@
4+
else
5+
python main.py get -l cpp -l python -p contest $@
6+
fi

lchelper/codegen/base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,15 @@ def format_statement(self, problem: Problem) -> List[str]:
165165
statement.extend(comments)
166166
return statement
167167

168-
def create_project(self, project_path: str, problems: List[Problem], site: str) -> None:
168+
def create_project(self, project_path: str, problems: List[Problem], site: str, debug: bool = False) -> None:
169169
r"""Create the folder for the project and generate code and supporting files.
170170
171171
:param project_path: Path to the project folder.
172172
:param problems: List of problem descriptions to generate code for.
173173
:param site: The LeetCode site where problems are crawled. Different sites may have slightly different syntax
174174
(or language-dependent markings).
175+
:param debug: If ``True``, exceptions will not be caught. This is probably only useful when the ``--debug``
176+
flag is set, in which case the Python debugger is hooked to handle exceptions.
175177
"""
176178
if not os.path.exists(project_path):
177179
os.makedirs(project_path)
@@ -194,7 +196,9 @@ def create_project(self, project_path: str, problems: List[Problem], site: str)
194196
problem_code = self.replace_section(problem_code, {"STATEMENT": statement}, ignore_errors=True)
195197
code_path = os.path.join(project_path, self.get_problem_file_name(idx, problem))
196198
self.write_and_backup(code_path, "\n".join(problem_code) + "\n")
197-
except Exception as e:
199+
except Exception:
200+
if debug:
201+
raise
198202
traceback.print_exc()
199203
log(f"Exception occurred while processing \"{problem.name}\"", "error")
200204

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def main():
125125
for lang in args.lang:
126126
codegen = lchelper.create_codegen(lang)
127127
project_path = os.path.join(args.output, f"{(args.prefix or contest_name)}_{lang}")
128-
codegen.create_project(project_path, problems, site)
128+
codegen.create_project(project_path, problems, site, debug=args.debug)
129129
lchelper.log(f"Project in language '{lang}' stored at: {project_path}", "success")
130130

131131

0 commit comments

Comments
 (0)