Skip to content
This repository was archived by the owner on May 11, 2023. It is now read-only.

Commit f53c686

Browse files
committed
Add __origname__ to frozenlibs to fix importlib
1 parent cfc2e3e commit f53c686

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

vm/build.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ use itertools::Itertools;
22
use std::{env, io::prelude::*, path::PathBuf, process::Command};
33

44
fn main() {
5-
#[cfg(feature = "freeze-stdlib")]
6-
for entry in glob::glob("Lib/*/*.py").expect("Lib/ exists?").flatten() {
5+
let frozen_libs = if cfg!(feature = "freeze-stdlib") {
6+
"Lib/*/*.py"
7+
} else {
8+
"Lib/python_builtins/*.py"
9+
};
10+
for entry in glob::glob(frozen_libs).expect("Lib/ exists?").flatten() {
711
let display = entry.display();
812
println!("cargo:rerun-if-changed={display}");
913
}
14+
println!("cargo:rerun-if-changed=../Lib/importlib/_bootstrap.py");
1015

1116
println!("cargo:rustc-env=RUSTPYTHON_GIT_HASH={}", git_hash());
1217
println!(

vm/src/import.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ pub(crate) fn init_importlib_base(vm: &mut VirtualMachine) -> PyResult<PyObjectR
2121
import_builtin(vm, "_weakref")?;
2222

2323
let importlib = thread::enter_vm(vm, || {
24-
let importlib = import_frozen(vm, "_frozen_importlib")?;
25-
let impmod = import_builtin(vm, "_imp")?;
26-
let install = importlib.get_attr("_install", vm)?;
27-
vm.invoke(&install, (vm.sys_module.clone(), impmod))?;
28-
Ok(importlib)
24+
let bootstrap = import_frozen(vm, "_frozen_importlib")?;
25+
let install = bootstrap.get_attr("_install", vm)?;
26+
let imp = import_builtin(vm, "_imp")?;
27+
let exc = vm.invoke(&install, (vm.sys_module.clone(), imp))?;
28+
Ok(bootstrap)
2929
})?;
3030
vm.import_func = importlib.get_attr(identifier!(vm, __import__).to_owned(), vm)?;
3131
Ok(importlib)
@@ -81,7 +81,12 @@ pub fn make_frozen(vm: &VirtualMachine, name: &str) -> PyResult<PyRef<PyCode>> {
8181
}
8282

8383
pub fn import_frozen(vm: &VirtualMachine, module_name: &str) -> PyResult {
84-
make_frozen(vm, module_name).and_then(|frozen| import_codeobj(vm, module_name, frozen, false))
84+
make_frozen(vm, module_name).and_then(|frozen| {
85+
let module = import_codeobj(vm, module_name, frozen, false)?;
86+
// TODO: give a correct origname here
87+
module.set_attr("__origname__", vm.ctx.new_str(module_name.to_owned()), vm)?;
88+
Ok(module)
89+
})
8590
}
8691

8792
pub fn import_builtin(vm: &VirtualMachine, module_name: &str) -> PyResult {

0 commit comments

Comments
 (0)