MCPcopy
hub / github.com/saltstack/salt / update_lib

Method update_lib

tests/unit/test_loader.py:1218–1237  ·  view source on GitHub ↗
(self, lib_name)

Source from the content-addressed store, hash-verified

1216 return os.path.join(self.tmp_dir, self.module_name)
1217
1218 def update_lib(self, lib_name):
1219 for modname in list(sys.modules):
1220 if modname.startswith(self.module_name):
1221 del sys.modules[modname]
1222 path = os.path.join(self.lib_paths[lib_name], "__init__.py")
1223 self.lib_count[lib_name] += 1
1224 with salt.utils.files.fopen(path, "wb") as fh:
1225 fh.write(
1226 salt.utils.stringutils.to_bytes(
1227 submodule_lib_template.format(count=self.lib_count[lib_name])
1228 )
1229 )
1230 fh.flush()
1231 os.fsync(fh.fileno()) # flush to disk
1232
1233 # pyc files don't like it when we change the original quickly
1234 # since the header bytes only contain the timestamp (granularity of seconds)
1235 # TODO: don't write them? Is *much* slower on re-load (~3x)
1236 # https://docs.python.org/2/library/sys.html#sys.dont_write_bytecode
1237 remove_bytecode(path)
1238
1239 @pytest.mark.slow_test
1240 def test_basic(self):

Callers 2

setUpMethod · 0.95
test_reloadMethod · 0.95

Calls 6

remove_bytecodeFunction · 0.85
formatMethod · 0.80
listFunction · 0.50
writeMethod · 0.45
flushMethod · 0.45
filenoMethod · 0.45

Tested by

no test coverage detected