forked from IronLanguages/ironpython3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonOptions.cs
More file actions
163 lines (134 loc) · 6.41 KB
/
PythonOptions.cs
File metadata and controls
163 lines (134 loc) · 6.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
using Microsoft.Scripting;
namespace IronPython.Runtime {
[Serializable, CLSCompliant(true)]
public sealed class PythonOptions : LanguageOptions {
/// <summary>
/// Gets the collection of command line arguments.
/// </summary>
public ReadOnlyCollection<string>/*!*/ Arguments { get; }
/// <summary>
/// Should we strip out all doc strings (the -O command line option).
/// </summary>
public bool Optimize { get; }
/// <summary>
/// Should we strip out all doc strings (the -OO command line option).
/// </summary>
public bool StripDocStrings { get; }
/// <summary>
/// List of -W (warning filter) options collected from the command line.
/// </summary>
public ReadOnlyCollection<string>/*!*/ WarningFilters { get; }
public bool BytesWarning { get; }
/// <summary>
/// Enables debugging support. When enabled a .NET debugger can be attached
/// to the process to step through Python code.
/// </summary>
public bool Debug { get; }
/// <summary>
/// Enables inspect mode. After running the main module the REPL will be started
/// within that modules context.
/// </summary>
public bool Inspect { get; }
/// <summary>
/// Suppresses addition of the user site directory. This is ignored by IronPython
/// except for updating sys.flags.
/// </summary>
public bool NoUserSite { get; }
/// <summary>
/// Disables import site on startup.
/// </summary>
public bool NoSite { get; }
/// <summary>
/// Ignore environment variables that configure the IronPython context.
/// </summary>
public bool IgnoreEnvironment { get; }
/// <summary>
/// Enables the verbose option which traces import statements. This is ignored by IronPython
/// except for setting sys.flags.
/// </summary>
public bool Verbose { get; }
/// <summary>
/// Sets the maximum recursion depth. Setting to Int32.MaxValue will disable recursion
/// enforcement.
/// </summary>
public int RecursionLimit { get; }
/// <summary>
/// Makes available sys._getframe. Local variables will not be available in frames unless the
/// function calls locals(), dir(), vars(), etc... For ensuring locals are always available use
/// the FullFrames option.
/// </summary>
public bool Frames { get; }
/// <summary>
/// Makes available sys._getframe. All locals variables will live on the heap (for a considerable
/// performance cost) enabling introspection of all code.
/// </summary>
public bool FullFrames { get; }
/// <summary>
/// Tracing is always available. Without this option tracing is only enabled when sys.settrace
/// is called. This means code that was already running before sys.settrace will not be debuggable.
///
/// With this option pdb.set_trace and pdb.post_mortem will always work properly.
/// </summary>
public bool Tracing { get; }
/// <summary>
/// Severity of a warning that indentation is formatted inconsistently.
/// </summary>
public Severity IndentationInconsistencySeverity { get; }
/// <summary>
/// Forces all code to be compiled in a mode in which the code can be reliably collected by the CLR.
/// </summary>
public bool LightweightScopes { get; }
/// <summary>
/// Enable profiling code
/// </summary>
public bool EnableProfiler { get; set; }
public int? GCStress { get; }
/// <summary>
/// Returns a regular expression of Python files which should not be emitted in debug mode.
/// </summary>
public Regex NoDebug { get; }
public bool Quiet { get; }
public PythonOptions()
: this(null) {
}
public PythonOptions(IDictionary<string, object> options)
: base(EnsureSearchPaths(options)) {
Arguments = GetStringCollectionOption(options, "Arguments") ?? EmptyStringCollection;
WarningFilters = GetStringCollectionOption(options, "WarningFilters", ';', ',') ?? EmptyStringCollection;
BytesWarning = GetOption(options, "BytesWarning", false);
Debug = GetOption(options, "Debug", false);
Inspect = GetOption(options, "Inspect", false);
NoUserSite = GetOption(options, "NoUserSite", false);
NoSite = GetOption(options, "NoSite", false);
IgnoreEnvironment = GetOption(options, "IgnoreEnvironment", false);
Verbose = GetOption(options, "Verbose", false);
Optimize = GetOption(options, "Optimize", false);
StripDocStrings = GetOption(options, "StripDocStrings", false);
RecursionLimit = GetOption(options, "RecursionLimit", Int32.MaxValue);
IndentationInconsistencySeverity = GetOption(options, "IndentationInconsistencySeverity", Severity.Ignore);
EnableProfiler = GetOption(options, "EnableProfiler", false);
LightweightScopes = GetOption(options, "LightweightScopes", false);
FullFrames = GetOption(options, "FullFrames", false);
Frames = FullFrames || GetOption(options, "Frames", true);
GCStress = GetOption<int?>(options, "GCStress", null);
Tracing = GetOption(options, "Tracing", false);
NoDebug = GetOption(options, "NoDebug", (Regex)null);
Quiet = GetOption(options, "Quiet", false);
}
private static IDictionary<string, object> EnsureSearchPaths(IDictionary<string, object> options) {
if (options == null) {
return new Dictionary<string, object>() { { "SearchPaths", new[] { "." } } };
} else if (!options.ContainsKey("SearchPaths")) {
options["SearchPaths"] = new [] { "." };
}
return options;
}
}
}