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

Function breakpointhook

crates/vm/src/stdlib/sys.rs:873–922  ·  view source on GitHub ↗
(args: FuncArgs, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

871 #[pyfunction(name = "__breakpointhook__")]
872 #[pyfunction]
873 pub fn breakpointhook(args: FuncArgs, vm: &VirtualMachine) -> PyResult {
874 let env_var = std::env::var("PYTHONBREAKPOINT")
875 .and_then(|env_var| {
876 if env_var.is_empty() {
877 Err(VarError::NotPresent)
878 } else {
879 Ok(env_var)
880 }
881 })
882 .unwrap_or_else(|_| "pdb.set_trace".to_owned());
883
884 if env_var.eq("0") {
885 return Ok(vm.ctx.none());
886 };
887
888 let print_unimportable_module_warn = || {
889 warn(
890 vm.ctx.exceptions.runtime_warning,
891 format!("Ignoring unimportable $PYTHONBREAKPOINT: \"{env_var}\"",),
892 0,
893 vm,
894 )
895 .unwrap();
896 Ok(vm.ctx.none())
897 };
898
899 let last = match env_var.rsplit_once('.') {
900 Some((_, last)) => last,
901 None if !env_var.is_empty() => env_var.as_str(),
902 _ => return print_unimportable_module_warn(),
903 };
904
905 let (module_path, attr_name) = if last == env_var {
906 ("builtins", env_var.as_str())
907 } else {
908 (&env_var[..(env_var.len() - last.len() - 1)], last)
909 };
910
911 let module = match vm.import(&vm.ctx.new_str(module_path), 0) {
912 Ok(module) => module,
913 Err(_) => {
914 return print_unimportable_module_warn();
915 }
916 };
917
918 match vm.get_attribute_opt(module, &vm.ctx.new_str(attr_name)) {
919 Ok(Some(hook)) => hook.as_ref().call(args, vm),
920 _ => print_unimportable_module_warn(),
921 }
922 }
923
924 #[pyfunction]
925 fn exc_info(vm: &VirtualMachine) -> (PyObjectRef, PyObjectRef, PyObjectRef) {

Callers

nothing calls this directly

Calls 14

noneMethod · 0.80
get_attribute_optMethod · 0.80
warnFunction · 0.70
ErrClass · 0.50
is_emptyMethod · 0.45
to_ownedMethod · 0.45
eqMethod · 0.45
unwrapMethod · 0.45
as_strMethod · 0.45
lenMethod · 0.45
importMethod · 0.45
new_strMethod · 0.45

Tested by

no test coverage detected