Skip to content

Commit aaccfbf

Browse files
committed
Use git hash as pyc magic number
1 parent 8376cdd commit aaccfbf

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

vm/src/import.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::bytecode::CodeObject;
66
use crate::frame::Scope;
77
use crate::obj::{objcode, objsequence, objstr, objtype};
88
use crate::pyobject::{ItemProtocol, PyObjectRef, PyResult, PyValue};
9+
use crate::version::get_git_revision;
910
use crate::vm::VirtualMachine;
1011
#[cfg(feature = "rustpython-compiler")]
1112
use rustpython_compiler::compile;
@@ -23,6 +24,12 @@ pub fn init_importlib(vm: &VirtualMachine, external: bool) -> PyResult {
2324
let install_external =
2425
vm.get_attribute(importlib.clone(), "_install_external_importers")?;
2526
vm.invoke(install_external, vec![])?;
27+
// Set pyc magic number to commit hash. Should be changed when bytecode will be more stable.
28+
let sys_modules = vm.get_attribute(vm.sys_module.clone(), "modules")?;
29+
let importlib_external = sys_modules.get_item("_frozen_importlib_external", vm)?;
30+
let mut magic = get_git_revision().into_bytes();
31+
magic.truncate(4);
32+
vm.set_attr(&importlib_external, "MAGIC_NUMBER", vm.ctx.new_bytes(magic))?;
2633
}
2734
Ok(vm.get_none())
2835
}

0 commit comments

Comments
 (0)