MCPcopy Index your code
hub / github.com/RustPython/RustPython / SourceFileLoader

Class SourceFileLoader

Lib/importlib/_bootstrap_external.py:962–1004  ·  view source on GitHub ↗

Concrete implementation of SourceLoader using the file system.

Source from the content-addressed store, hash-verified

960
961
962class SourceFileLoader(FileLoader, SourceLoader):
963
964 """Concrete implementation of SourceLoader using the file system."""
965
966 def path_stats(self, path):
967 """Return the metadata for the path."""
968 st = _path_stat(path)
969 return {'mtime': st.st_mtime, 'size': st.st_size}
970
971 def _cache_bytecode(self, source_path, bytecode_path, data):
972 # Adapt between the two APIs
973 mode = _calc_mode(source_path)
974 return self.set_data(bytecode_path, data, _mode=mode)
975
976 def set_data(self, path, data, *, _mode=0o666):
977 """Write bytes data to a file."""
978 parent, filename = _path_split(path)
979 path_parts = []
980 # Figure out what directories are missing.
981 while parent and not _path_isdir(parent):
982 parent, part = _path_split(parent)
983 path_parts.append(part)
984 # Create needed directories.
985 for part in reversed(path_parts):
986 parent = _path_join(parent, part)
987 try:
988 _os.mkdir(parent)
989 except FileExistsError:
990 # Probably another Python process already created the dir.
991 continue
992 except OSError as exc:
993 # Could be a permission error, read-only filesystem: just forget
994 # about writing the data.
995 _bootstrap._verbose_message('could not create {!r}: {!r}',
996 parent, exc)
997 return
998 try:
999 _write_atomic(path, data, _mode)
1000 _bootstrap._verbose_message('created {!r}', path)
1001 except OSError as exc:
1002 # Same as above: just don't write the bytecode.
1003 _bootstrap._verbose_message('could not create {!r}: {!r}', path,
1004 exc)
1005
1006
1007class SourcelessFileLoader(FileLoader, _LoaderBasics):

Callers 1

_fix_up_moduleFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected