MCPcopy Index your code
hub / github.com/modelscope/modelscope / ensure_write

Function ensure_write

modelscope/utils/ast_utils.py:583–599  ·  view source on GitHub ↗

Write data to a given ``filepath`` with 'wb' mode. Note: ``write`` will create a directory if the directory of ``filepath`` does not exist. Args: obj (bytes): Data to be written. filepath (str or Path): Path to write data.

(obj: bytes, filepath: Union[str, Path])

Source from the content-addressed store, hash-verified

581
582
583def ensure_write(obj: bytes, filepath: Union[str, Path]) -> None:
584 """Write data to a given ``filepath`` with 'wb' mode.
585
586 Note:
587 ``write`` will create a directory if the directory of ``filepath``
588 does not exist.
589
590 Args:
591 obj (bytes): Data to be written.
592 filepath (str or Path): Path to write data.
593 """
594 dirname = os.path.dirname(filepath)
595 if dirname and not os.path.exists(dirname):
596 os.makedirs(dirname, exist_ok=True)
597
598 with open(filepath, 'wb') as f:
599 f.write(obj)
600
601
602def _save_index(index, file_path, file_list=None, with_template=False):

Callers 1

_save_indexFunction · 0.85

Calls 2

existsMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…