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

Method compile_single

crates/derive-impl/src/compile_bytecode.rs:95–123  ·  view source on GitHub ↗
(
        &self,
        mode: Mode,
        module_name: String,
        compiler: &dyn Compiler,
    )

Source from the content-addressed store, hash-verified

93 }
94
95 fn compile_single(
96 &self,
97 mode: Mode,
98 module_name: String,
99 compiler: &dyn Compiler,
100 ) -> Result<CodeObject, Diagnostic> {
101 match &self.kind {
102 CompilationSourceKind::File { base, rel_path } => {
103 let path = base.join(rel_path);
104 let source = fs::read_to_string(&path).map_err(|err| {
105 Diagnostic::spans_error(
106 self.span,
107 format!("Error reading file {path:?}: {err}"),
108 )
109 })?;
110 self.compile_string(&source, mode, module_name, compiler, || rel_path.display())
111 }
112 CompilationSourceKind::SourceCode(code) => self.compile_string(
113 &textwrap::dedent(code),
114 mode,
115 module_name,
116 compiler,
117 || "string literal",
118 ),
119 CompilationSourceKind::Dir { .. } => {
120 unreachable!("Can't use compile_single with directory source")
121 }
122 }
123 }
124
125 fn compile_dir(
126 &self,

Callers 1

impl_py_compileFunction · 0.45

Calls 4

compile_stringMethod · 0.80
dedentFunction · 0.50
joinMethod · 0.45
displayMethod · 0.45

Tested by

no test coverage detected