Skip to content

Commit 0f5269a

Browse files
author
Colin Leong
committed
Requested change to use yield
1 parent 893fecf commit 0f5269a

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

src/find_bare_citations.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,17 @@ def find_bare_citations(markdown_file_path:Path, citation_keys:list)->list:
3333

3434
content = markdown_code_block_pattern.sub('', content)
3535

36-
37-
38-
39-
issues = []
40-
41-
4236
for citation_key in citation_keys:
4337

4438
# magical regex from ChatGPT: captures the whole line that has a bare citation.
4539
pattern = re.compile(r'^.*(?<!@)(?:' + re.escape(citation_key) + r').*$', re.MULTILINE)
4640

4741
# Find all matching lines
48-
matches = pattern.findall(content)
49-
50-
# Print the matches
51-
# for match in matches:
52-
# print(match)
53-
54-
if matches:
42+
if pattern.search(content) is not None:
43+
matches = pattern.finditer(content)
5544
issue_tuple = citation_key, matches
56-
issues.append(issue_tuple)
57-
58-
return issues
45+
yield issue_tuple
46+
5947

6048
if __name__ == "__main__":
6149

@@ -75,14 +63,13 @@ def find_bare_citations(markdown_file_path:Path, citation_keys:list)->list:
7563

7664
citation_keys = extract_citation_keys(args.bib_file_path)
7765

66+
# for i in range(50):
67+
# citation_keys.extend([str(uuid.uuid4) for _ in range(100)])
68+
7869
print(f"Bibliography had {len(citation_keys)} citations, checking for bare citations:")
7970

8071
start_time = timeit.default_timer()
8172
issues = find_bare_citations(args.markdown_file_path, citation_keys)
82-
elapsed_time = timeit.default_timer() - start_time
83-
84-
print(f"Bare-citation check complete after ~{elapsed_time:.2f} seconds")
85-
8673

8774
if issues:
8875
print("Found the following lines with bare citations:")
@@ -92,8 +79,11 @@ def find_bare_citations(markdown_file_path:Path, citation_keys:list)->list:
9279
print(f"Citation key: {citation_key}")
9380

9481
for match in matches:
95-
print(f"* {match}")
82+
print(f"* {match.group(0)}")
9683
print()
84+
elapsed_time = timeit.default_timer() - start_time
85+
print(f"Bare-citation check complete after ~{elapsed_time:.2f} seconds")
86+
if issues:
9787
sys.exit(1) # exit with an error
9888

9989

0 commit comments

Comments
 (0)