(
content: Union[str, bytes],
extension: str,
extra: str = "",
hash_type: str = "code",
specified_dir: str = "",
)
| 355 | |
| 356 | |
| 357 | def write( |
| 358 | content: Union[str, bytes], |
| 359 | extension: str, |
| 360 | extra: str = "", |
| 361 | hash_type: str = "code", |
| 362 | specified_dir: str = "", |
| 363 | ) -> Tuple[str, str]: |
| 364 | # use striped content to compute hash so we don't end up with different |
| 365 | # hashes just because the content begins/ends with differnet number of |
| 366 | # spaces. |
| 367 | key: str = get_hash(content.strip(), extra, hash_type) |
| 368 | basename, subdir, path = get_path(key, extension, specified_dir) |
| 369 | if not os.path.exists(subdir): |
| 370 | os.makedirs(subdir, exist_ok=True) |
| 371 | if not os.path.exists(path): |
| 372 | write_atomic(path, content) |
| 373 | return basename, path |
| 374 | |
| 375 | |
| 376 | def write_atomic(path: str, content: Union[str, bytes]) -> None: |
no test coverage detected
searching dependent graphs…