Skip to content

Commit 78cdb1a

Browse files
authored
Set isolated when run with -I (#1426)
1 parent 3fce165 commit 78cdb1a

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

Src/IronPython/Hosting/PythonCommandLine.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ protected override void Initialize() {
193193
}
194194
}
195195

196-
PythonContext.InsertIntoPath(0, fullPath);
196+
if (!PythonContext.PythonOptions.Isolated) {
197+
PythonContext.InsertIntoPath(0, fullPath);
198+
}
197199
PythonContext.MainThread = Thread.CurrentThread;
198200
}
199201

Src/IronPython/Hosting/PythonOptionsParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ private ReadOnlySpan<char> HandleOptions(ReadOnlySpan<char> options) {
7979
LanguageSetup.Options["Verbose"] = ScriptingRuntimeHelpers.True;
8080
break;
8181

82-
case 'I': // both -E and -s
82+
case 'I': // also implies both -E and -s
8383
ConsoleOptions.IgnoreEnvironmentVariables = true;
8484
LanguageSetup.Options["IgnoreEnvironment"] = ScriptingRuntimeHelpers.True;
8585
LanguageSetup.Options["NoUserSite"] = ScriptingRuntimeHelpers.True;
86+
LanguageSetup.Options["Isolated"] = ScriptingRuntimeHelpers.True;
8687
break;
8788

8889
case 'S':

Src/IronPython/Runtime/PythonContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ private void InitializeSysFlags() {
728728
_ => (int)PythonOptions.BytesWarning
729729
};
730730
flags.quiet = PythonOptions.Quiet ? 1 : 0;
731+
flags.isolated = PythonOptions.Isolated ? 1 : 0;
731732
}
732733

733734
internal bool ShouldInterpret(PythonCompilerOptions options, SourceUnit source) {

Src/IronPython/Runtime/PythonOptions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public sealed class PythonOptions : LanguageOptions {
6363
/// </summary>
6464
public bool IgnoreEnvironment { get; }
6565

66+
/// <summary>
67+
/// Run in isolated mode.
68+
/// </summary>
69+
public bool Isolated { get; }
70+
6671
/// <summary>
6772
/// Enables the verbose option which traces import statements. This is ignored by IronPython
6873
/// except for setting sys.flags.
@@ -146,6 +151,7 @@ public PythonOptions(IDictionary<string, object> options)
146151
NoDebug = GetOption(options, "NoDebug", (Regex)null);
147152
Quiet = GetOption(options, "Quiet", false);
148153
NoImportLib = GetOption(options, "NoImportLib", false);
154+
Isolated = GetOption(options, "Isolated", false);
149155
}
150156

151157
private static IDictionary<string, object> EnsureSearchPaths(IDictionary<string, object> options) {

0 commit comments

Comments
 (0)