fix(common): import type for function in util

This commit is contained in:
Anthony Berg 2025-07-23 12:11:20 +02:00
parent 0d9d47136d
commit 320daff96d

View File

@ -1,9 +1,9 @@
from pathlib import Path
def get_project_root() -> Path:
"""
Gets the root directory of the project.
"""
from pathlib import Path
return Path(__file__).parent.parent.parent
@ -26,3 +26,24 @@ def get_includes(file: str, local: bool = False) -> list[str]:
pattern = '^\\W*#include\\s+"(.+?)"\\W*$'
return re.findall(pattern, file, re.M)
def unique_file(filename: str) -> str:
"""
Finds a unique name for a filename. Will append a padded 4-digit number to the
tail of the stem of the file name.
Args:
filename: The filename to find a unique name.
Returns:
A unique filename.
"""
import os
i = 0
stem, ext = os.path.splitext(filename)
while os.path.isfile(filename):
filename = f"{stem}_{str(i).zfill(4)}{ext}"
i = i + 1
return filename