protected override void Initialize() { Debug.Assert(Language != null); base.Initialize(); Console.Output = new OutputWriter(PythonContext, false); Console.ErrorOutput = new OutputWriter(PythonContext, true); // TODO: must precede path initialization! (??? - test test_importpkg.py) int pathIndex = PythonContext.PythonOptions.SearchPaths.Count; Language.DomainManager.LoadAssembly(typeof(string).Assembly); Language.DomainManager.LoadAssembly(typeof(System.Diagnostics.Debug).Assembly); InitializePath(ref pathIndex); InitializeModules(); InitializeExtensionDLLs(); ImportSite(); // If running in console mode (including with -c), the current working directory should be // the first entry in sys.path. If running a script file, however, the CWD should not be added; // instead, the script's containg folder should be added. string fullPath = "."; // this is a valid path resolving to current working dir. Pinky-swear. if (Options.Command == null && Options.FileName != null) { if (Options.FileName == "-") { Options.FileName = "<stdin>"; } else { #if !SILVERLIGHT if (Directory.Exists(Options.FileName)) { Options.FileName = Path.Combine(Options.FileName, "__main__.py"); } if (!File.Exists(Options.FileName)) { Console.WriteLine( String.Format( System.Globalization.CultureInfo.InvariantCulture, "File {0} does not exist.", Options.FileName), Style.Error); Environment.Exit(1); } #endif fullPath = Path.GetDirectoryName( Language.DomainManager.Platform.GetFullPath(Options.FileName) ); } } PythonContext.InsertIntoPath(0, fullPath); }
protected override void Initialize() { Debug.Assert(Language != null); base.Initialize(); Console.Output = new OutputWriter(PythonContext, false); Console.ErrorOutput = new OutputWriter(PythonContext, true); // TODO: must precede path initialization! (??? - test test_importpkg.py) int pathIndex = PythonContext.PythonOptions.SearchPaths.Count; Language.DomainManager.LoadAssembly(typeof(string).Assembly); Language.DomainManager.LoadAssembly(typeof(System.Diagnostics.Debug).Assembly); InitializePath(ref pathIndex); InitializeModules(); InitializeExtensionDLLs(); ImportSite(); PythonContext.InsertIntoPath(0, "."); PythonContext.InsertIntoPath(++pathIndex, PythonContext.DomainManager.Platform.CurrentDirectory); if (Options.Command == null && Options.FileName != null) { if (Options.FileName == "-") { Options.FileName = "<stdin>"; } else { #if !SILVERLIGHT if (!File.Exists(Options.FileName)) { Console.WriteLine( String.Format( System.Globalization.CultureInfo.InvariantCulture, "File {0} does not exist.", Options.FileName), Style.Error); Environment.Exit(1); } #endif string fullPath = Language.DomainManager.Platform.GetFullPath(Options.FileName); PythonContext.InsertIntoPath(0, Path.GetDirectoryName(fullPath)); } } }
private void InitializePath(ref int pathIndex) { // paths, environment vars if (!Options.IgnoreEnvironmentVariables) { string path = Environment.GetEnvironmentVariable("IRONPYTHONPATH"); if (path != null && path.Length > 0) { string[] paths = path.Split(Path.PathSeparator); foreach (string p in paths) { PythonContext.InsertIntoPath(pathIndex++, p); } } } }
protected override void Initialize() { Debug.Assert(Language != null); base.Initialize(); Console.Output = new OutputWriter(PythonContext, false); Console.ErrorOutput = new OutputWriter(PythonContext, true); // TODO: must precede path initialization! (??? - test test_importpkg.py) int pathIndex = PythonContext.PythonOptions.SearchPaths.Count; Language.DomainManager.LoadAssembly(typeof(string).Assembly); Language.DomainManager.LoadAssembly(typeof(System.Diagnostics.Debug).Assembly); InitializePath(ref pathIndex); InitializeEnvironmentVariables(); InitializeModules(); InitializeExtensionDLLs(); // ensure the warnings module loads var warnOptions = PythonContext.GetSystemStateValue("warnoptions") as PythonList; if (warnOptions?.Count > 0) { PythonContext.GetWarningsModule(); } ImportSite(); // Equivalent to -i command line option // Check if IRONPYTHONINSPECT was set before execution string inspectLine = Environment.GetEnvironmentVariable("IRONPYTHONINSPECT"); if (inspectLine != null) { Options.Introspection = true; } // If running in console mode (including with -c), the current working directory should be // the first entry in sys.path. If running a script file, however, the CWD should not be added; // instead, the script's containg folder should be added. string fullPath = "."; // this is a valid path resolving to current working dir. Pinky-swear. if (Options.Command == null && Options.FileName != null) { if (Options.FileName == "-") { Options.FileName = "<stdin>"; } else { if (Directory.Exists(Options.FileName)) { Options.FileName = Path.Combine(Options.FileName, "__main__.py"); } if (!File.Exists(Options.FileName)) { Console.WriteLine( String.Format( System.Globalization.CultureInfo.InvariantCulture, "File {0} does not exist.", Options.FileName), Style.Error); Environment.Exit(1); } fullPath = Path.GetDirectoryName( Language.DomainManager.Platform.GetFullPath(Options.FileName) ); } } PythonContext.InsertIntoPath(0, fullPath); PythonContext.MainThread = Thread.CurrentThread; }