mirror of
https://github.com/cp2k/cp2k.git
synced 2026-07-28 22:25:32 -04:00
Manula: Add precommit check for biblio refs
This commit is contained in:
parent
42e37addd9
commit
4bf43545bd
4 changed files with 34 additions and 27 deletions
|
|
@ -133,6 +133,13 @@ def get_flags_src() -> str:
|
|||
return match.group(1)
|
||||
|
||||
|
||||
@lru_cache(maxsize=None)
|
||||
def get_bibliography_dois() -> list[str]:
|
||||
bib = CP2K_DIR.joinpath("src/common/bibliography.F").read_text()
|
||||
matches = re.findall(r'DOI="([^"]+)"', bib, flags=re.IGNORECASE)
|
||||
return [doi for doi in matches if "/" in doi] # filter invalid DOIs.
|
||||
|
||||
|
||||
def check_file(path: pathlib.Path) -> List[str]:
|
||||
"""
|
||||
Check the given source file for convention violations, like:
|
||||
|
|
@ -240,6 +247,13 @@ def check_file(path: pathlib.Path) -> List[str]:
|
|||
if flag not in get_flags_src():
|
||||
warnings += [f"{path}: Flag '{flag}' not mentioned in cp2k_flags()"]
|
||||
|
||||
# Check for DOIs that could be a bibliography reference.
|
||||
if re.match(r"docs/[^/]+/.*\.md", str(path)) and "docs/CP2K_INPUT" not in str(path):
|
||||
for line in content.splitlines():
|
||||
for doi in get_bibliography_dois():
|
||||
if doi.lower() in line:
|
||||
warnings += [f"{path}: Please replace doi:{doi} with biblio ref."]
|
||||
|
||||
return warnings
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue