private int RunCommandWorker(string command) { ScriptCode compiledCode; ModuleOptions trueDiv = (PythonContext.PythonOptions.DivisionOptions == PythonDivisionOptions.New) ? ModuleOptions.TrueDivision : ModuleOptions.None; ModuleOptions modOpt = ModuleOptions.Optimized | ModuleOptions.ModuleBuiltins | trueDiv; ; if (Options.SkipFirstSourceLine) { modOpt |= ModuleOptions.SkipFirstLine; } PythonModule module = PythonContext.CompileModule( "", // there is no file, it will be set to <module> "__main__", PythonContext.CreateSnippet(command, "-c", SourceCodeKind.File), modOpt, out compiledCode); PythonContext.PublishModule("__main__", module); Scope = module.Scope; try { compiledCode.Run(Scope); } catch (SystemExitException pythonSystemExit) { // disable introspection when exited: Options.Introspection = false; return(GetEffectiveExitCode(pythonSystemExit)); } return(0); }
private int RunFileWorker(string /*!*/ fileName) { ScriptCode compiledCode; ModuleOptions modOpt = ModuleOptions.Optimized | ModuleOptions.ModuleBuiltins; if (Options.SkipFirstSourceLine) { modOpt |= ModuleOptions.SkipFirstLine; } PythonModule module = PythonContext.CompileModule( fileName, "__main__", PythonContext.CreateFileUnit(String.IsNullOrEmpty(fileName) ? null : fileName, PythonContext.DefaultEncoding), modOpt, out compiledCode); PythonContext.PublishModule("__main__", module); Scope = module.Scope; try { compiledCode.Run(Scope); } catch (SystemExitException pythonSystemExit) { // disable introspection when exited: Options.Introspection = false; return(GetEffectiveExitCode(pythonSystemExit)); } return(0); }
public ScriptScope /*!*/ CreateModule(string name, string filename, string docString) { var module = new PythonModule(); _context.PublishModule(name, module); module.__init__(name, docString); module.__dict__["__file__"] = filename; return(HostingHelpers.CreateScriptScope(_engine, module.Scope)); }
protected override Scope /*!*/ CreateScope() { var modCtx = new ModuleContext(new PythonDictionary(), PythonContext); modCtx.Features = ModuleOptions.None; modCtx.InitializeBuiltins(true); PythonContext.PublishModule("__main__", modCtx.Module); modCtx.Globals["__doc__"] = null; modCtx.Globals["__name__"] = "__main__"; return(modCtx.GlobalScope); }
protected override Scope /*!*/ CreateScope() { ModuleOptions trueDiv = (PythonContext_PythonOptions.DivisionOptions == PythonDivisionOptions.New) ? ModuleOptions.TrueDivision : ModuleOptions.None; var modCtx = new ModuleContext(new PythonDictionary(), PythonContext); modCtx.Features = trueDiv; modCtx_InitializeBuiltins(modCtx, true); PythonContext.PublishModule("__main__", modCtx.Module); modCtx.Globals["__doc__"] = null; modCtx.Globals["__name__"] = "__main__"; return(modCtx.GlobalScope); }
private int RunFileWorker(string /*!*/ fileName) { try { // There is no PEP for this case, only http://bugs.python.org/issue1739468 object importer; if (Importer.TryImportMainFromZip(DefaultContext.Default, fileName, out importer)) { return(0); } if (importer != null && importer.GetType() != typeof(PythonImport.NullImporter)) { Console.WriteLine(String.Format("can't find '__main__' module in '{0}'", fileName), Style.Error); return(0); } } catch (SystemExitException pythonSystemExit) { // disable introspection when exited: Options.Introspection = false; return(GetEffectiveExitCode(pythonSystemExit)); } // classic file ScriptCode compiledCode; ModuleOptions modOpt = ModuleOptions.Optimized | ModuleOptions.ModuleBuiltins; if (Options.SkipFirstSourceLine) { modOpt |= ModuleOptions.SkipFirstLine; } PythonModule module = PythonContext.CompileModule( fileName, "__main__", PythonContext.CreateFileUnit(String.IsNullOrEmpty(fileName) ? null : fileName, PythonContext.DefaultEncoding), modOpt, out compiledCode); PythonContext.PublishModule("__main__", module); Scope = module.Scope; try { compiledCode.Run(Scope); } catch (SystemExitException pythonSystemExit) { // disable introspection when exited: Options.Introspection = false; return(GetEffectiveExitCode(pythonSystemExit)); } return(0); }