本文整理汇总了C#中IPythonInterpreterFactory类的典型用法代码示例。如果您正苦于以下问题:C# IPythonInterpreterFactory类的具体用法?C# IPythonInterpreterFactory怎么用?C# IPythonInterpreterFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IPythonInterpreterFactory类属于命名空间,在下文中一共展示了IPythonInterpreterFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ContinueRun
private static async Task<int> ContinueRun(
IPythonInterpreterFactory factory,
Redirector output,
bool elevate,
params string[] cmd
) {
bool isScript;
var easyInstallPath = GetEasyInstallPath(factory, out isScript);
if (easyInstallPath == null) {
throw new FileNotFoundException("Cannot find setuptools ('easy_install.exe')");
}
var args = cmd.ToList();
args.Insert(0, "--always-copy");
args.Insert(0, "--always-unzip");
if (isScript) {
args.Insert(0, ProcessOutput.QuoteSingleArgument(easyInstallPath));
easyInstallPath = factory.Configuration.InterpreterPath;
}
using (var proc = ProcessOutput.Run(
easyInstallPath,
args,
factory.Configuration.PrefixPath,
UnbufferedEnv,
false,
output,
false,
elevate
)) {
return await proc;
}
}
示例2: EnsureReplWindow
internal static IVsInteractiveWindow/*!*/ EnsureReplWindow(IServiceProvider serviceProvider, IPythonInterpreterFactory factory, PythonProjectNode project) {
var compModel = serviceProvider.GetComponentModel();
var provider = compModel.GetService<InteractiveWindowProvider>();
string replId = PythonReplEvaluatorProvider.GetReplId(factory, project);
var window = provider.FindReplWindow(replId);
if (window == null) {
window = provider.CreateInteractiveWindow(
serviceProvider.GetPythonContentType(),
factory.Description + " Interactive",
typeof(PythonLanguageInfo).GUID,
replId
);
var toolWindow = window as ToolWindowPane;
if (toolWindow != null) {
toolWindow.BitmapImageMoniker = KnownMonikers.PYInteractiveWindow;
}
var pyService = serviceProvider.GetPythonToolsService();
window.InteractiveWindow.SetSmartUpDown(pyService.GetInteractiveOptions(factory).ReplSmartHistory);
}
if (project != null && project.Interpreters.IsProjectSpecific(factory)) {
project.AddActionOnClose(window, BasePythonReplEvaluator.CloseReplWindow);
}
return window;
}
示例3: AddFactory
public void AddFactory(IPythonInterpreterFactory factory) {
_factories.Add(factory);
var evt = InterpreterFactoriesChanged;
if (evt != null) {
evt(this, EventArgs.Empty);
}
}
示例4: AddVirtualEnvironmentView
public AddVirtualEnvironmentView(
PythonProjectNode project,
IInterpreterRegistryService interpreterService,
IPythonInterpreterFactory selectInterpreter
) {
_interpreterService = interpreterService;
_project = project;
VirtualEnvBasePath = _projectHome = project.ProjectHome;
Interpreters = new ObservableCollection<InterpreterView>(InterpreterView.GetInterpreters(project.Site, project));
var selection = Interpreters.FirstOrDefault(v => v.Interpreter == selectInterpreter);
if (selection == null) {
selection = Interpreters.FirstOrDefault(v => v.Interpreter == project.GetInterpreterFactory())
?? Interpreters.LastOrDefault();
}
BaseInterpreter = selection;
_project.InterpreterFactoriesChanged += OnInterpretersChanged;
var venvName = "env";
for (int i = 1; Directory.Exists(Path.Combine(_projectHome, venvName)); ++i) {
venvName = "env" + i.ToString();
}
VirtualEnvName = venvName;
CanInstallRequirementsTxt = File.Exists(PathUtils.GetAbsoluteFilePath(_projectHome, "requirements.txt"));
WillInstallRequirementsTxt = CanInstallRequirementsTxt;
}
示例5: IronPythonAnalysis
public IronPythonAnalysis(
IPythonInterpreterFactory factory,
IPythonInterpreter interpreter = null,
string builtinName = null
) : base(factory, interpreter, builtinName) {
((IronPythonInterpreter)Analyzer.Interpreter).Remote.AddAssembly(new ObjectHandle(typeof(IronPythonAnalysisTest).Assembly));
}
示例6: IsRealInterpreter
private bool IsRealInterpreter(IPythonInterpreterFactory factory) {
if (factory == null) {
return false;
}
var interpreterService = _serviceProvider.GetComponentModel().GetService<IInterpreterOptionsService>();
return interpreterService != null && interpreterService.NoInterpretersValue != factory;
}
示例7: Save
public void Save(IPythonInterpreterFactory interpreter) {
base.Save();
_pyService.SaveString(_id + InterpreterOptionsSetting, _category, InterpreterOptions ?? "");
_pyService.SaveBool(_id + EnableAttachSetting, _category, EnableAttach);
_pyService.SaveString(_id + ExecutionModeSetting, _category, ExecutionMode ?? "");
_pyService.SaveString(_id + StartupScriptSetting, _category, StartupScript ?? "");
var replProvider = _serviceProvider.GetComponentModel().GetService<IReplWindowProvider>();
if (replProvider != null) {
// propagate changed settings to existing REPL windows
foreach (var replWindow in replProvider.GetReplWindows()) {
PythonReplEvaluator pyEval = replWindow.Evaluator as PythonReplEvaluator;
if (EvaluatorUsesThisInterpreter(pyEval, interpreter)) {
if (UseInterpreterPrompts) {
replWindow.UseInterpreterPrompts();
} else {
replWindow.SetPrompts(PrimaryPrompt, SecondaryPrompt);
}
#if !DEV14_OR_LATER
replWindow.SetOptionValue(ReplOptions.DisplayPromptInMargin, !InlinePrompts);
#endif
replWindow.SetSmartUpDown(ReplSmartHistory);
}
}
}
}
示例8: List
public static async Task<HashSet<string>> List(IPythonInterpreterFactory factory) {
using (var proc = Run(factory, null, false, "list")) {
if (await proc == 0) {
return new HashSet<string>(proc.StandardOutputLines
.Select(line => Regex.Match(line, "(?<name>.+?) \\((?<version>.+?)\\)"))
.Where(match => match.Success)
.Select(match => string.Format("{0}=={1}",
match.Groups["name"].Value,
match.Groups["version"].Value
))
);
}
}
// Pip failed, so return a directory listing
var packagesPath = Path.Combine(factory.Configuration.LibraryPath, "site-packages");
HashSet<string> result = null;
if (Directory.Exists(packagesPath)) {
result = await Task.Run(() => new HashSet<string>(Directory.EnumerateDirectories(packagesPath)
.Select(path => Path.GetFileName(path))
.Select(name => PackageNameRegex.Match(name))
.Where(match => match.Success)
.Select(match => match.Groups["name"].Value)
))
.SilenceException<IOException, HashSet<string>>()
.SilenceException<UnauthorizedAccessException, HashSet<string>>()
.HandleAllExceptions(SR.ProductName, typeof(Pip));
}
return result ?? new HashSet<string>();
}
示例9: Run
private static ProcessOutput Run(
IPythonInterpreterFactory factory,
Redirector output,
bool elevate,
params string[] cmd
) {
factory.ThrowIfNotRunnable("factory");
IEnumerable<string> args;
if (factory.Configuration.Version >= SupportsDashMPip) {
args = new[] { "-m", "pip" }.Concat(cmd);
} else {
// Manually quote the code, since we are passing false to
// quoteArgs below.
args = new[] { "-c", "\"import pip; pip.main()\"" }.Concat(cmd);
}
return ProcessOutput.Run(
factory.Configuration.InterpreterPath,
args,
factory.Configuration.PrefixPath,
UnbufferedEnv,
false,
output,
quoteArgs: false,
elevate: elevate
);
}
示例10: SetDefault
public void SetDefault(IPythonInterpreterFactory factory) {
Assert.IsNotNull(factory, "Cannot set default to null");
var interpreterService = _model.GetService<IInterpreterOptionsService>();
Assert.IsNotNull(interpreterService);
CurrentDefault = factory;
interpreterService.DefaultInterpreter = factory;
}
示例11: PythonReplEvaluator
public PythonReplEvaluator(IPythonInterpreterFactory interpreter, IServiceProvider serviceProvider, PythonReplEvaluatorOptions options, IInterpreterOptionsService interpreterService = null)
: base(serviceProvider, serviceProvider.GetPythonToolsService(), options) {
_interpreter = interpreter;
_interpreterService = interpreterService;
if (_interpreterService != null) {
_interpreterService.InterpretersChanged += InterpretersChanged;
}
}
示例12: TryGetCondaFactoryAsync
private static async Task<IPythonInterpreterFactory> TryGetCondaFactoryAsync(
IPythonInterpreterFactory target,
IInterpreterOptionsService service
) {
var condaMetaPath = CommonUtils.GetAbsoluteDirectoryPath(
target.Configuration.PrefixPath,
"conda-meta"
);
if (!Directory.Exists(condaMetaPath)) {
return null;
}
string metaFile;
try {
metaFile = Directory.EnumerateFiles(condaMetaPath, "*.json").FirstOrDefault();
} catch (Exception ex) {
if (ex.IsCriticalException()) {
throw;
}
return null;
}
if (!string.IsNullOrEmpty(metaFile)) {
string text = string.Empty;
try {
text = File.ReadAllText(metaFile);
} catch (Exception ex) {
if (ex.IsCriticalException()) {
throw;
}
}
var m = Regex.Match(text, @"\{[^{]+link.+?\{.+?""source""\s*:\s*""(.+?)""", RegexOptions.Singleline);
if (m.Success) {
var pkg = m.Groups[1].Value;
if (!Directory.Exists(pkg)) {
return null;
}
var prefix = Path.GetDirectoryName(Path.GetDirectoryName(pkg));
var factory = service.Interpreters.FirstOrDefault(
f => CommonUtils.IsSameDirectory(f.Configuration.PrefixPath, prefix)
);
if (factory != null && !(await factory.FindModulesAsync("conda")).Any()) {
factory = null;
}
return factory;
}
}
if ((await target.FindModulesAsync("conda")).Any()) {
return target;
}
return null;
}
示例13: RemoveFactory
public bool RemoveFactory(IPythonInterpreterFactory factory) {
if (_factories.Remove(factory)) {
var evt = InterpreterFactoriesChanged;
if (evt != null) {
evt(this, EventArgs.Empty);
}
return true;
}
return false;
}
示例14: DefaultInterpreterSetter
public DefaultInterpreterSetter(IPythonInterpreterFactory factory) {
var props = VsIdeTestHostContext.Dte.get_Properties("Python Tools", "Interpreters");
Assert.IsNotNull(props);
OriginalInterpreter = props.Item("DefaultInterpreter").Value;
OriginalVersion = props.Item("DefaultInterpreterVersion").Value;
props.Item("DefaultInterpreter").Value = factory.Id;
props.Item("DefaultInterpreterVersion").Value = string.Format("{0}.{1}", factory.Configuration.Version.Major, factory.Configuration.Version.Minor);
}
示例15: IsEqual
/// <summary>
/// Determines whether two interpreter factories are equivalent.
/// </summary>
public static bool IsEqual(this IPythonInterpreterFactory x, IPythonInterpreterFactory y) {
if (x == null || y == null) {
return x == null && y == null;
}
if (x.GetType() != y.GetType()) {
return false;
}
return x.Configuration.Equals(y.Configuration);
}