private static IEnumerable <string> EnumerateAllFiles( string source, string filters, List <string> virtualEnvPaths ) { var files = new HashSet <string>(StringComparer.OrdinalIgnoreCase); var patterns = filters.Split(';').Concat(new[] { "*.py" }).Select(p => p.Trim()).ToArray(); var directories = new List <string>() { source }; var skipDirectories = new HashSet <string>(StringComparer.OrdinalIgnoreCase); try { directories.AddRange(Directory.EnumerateDirectories(source, "*", SearchOption.AllDirectories)); } catch (UnauthorizedAccessException) { } foreach (var dir in directories) { if (UnwindDirectory(dir).Any(skipDirectories.Contains)) { continue; } try { if (virtualEnvPaths != null) { var origPrefix = DerivedInterpreterFactory.GetOrigPrefixPath(dir); if (!string.IsNullOrEmpty(origPrefix)) { virtualEnvPaths.Add(dir); skipDirectories.Add(PathUtils.TrimEndSeparator(dir)); continue; } } foreach (var filter in patterns) { files.UnionWith(Directory.EnumerateFiles(dir, filter)); } } catch (UnauthorizedAccessException) { } } return(files .Where(path => path.StartsWith(source)) .Select(path => path.Substring(source.Length).TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)) .Distinct(StringComparer.OrdinalIgnoreCase)); }
public static InterpreterConfiguration FindInterpreterConfiguration( string id, string prefixPath, IInterpreterRegistryService service, IPythonInterpreterFactory baseInterpreter = null ) { var libPath = DerivedInterpreterFactory.FindLibPath(prefixPath); if (baseInterpreter == null) { baseInterpreter = DerivedInterpreterFactory.FindBaseInterpreterFromVirtualEnv( prefixPath, libPath, service ); if (baseInterpreter == null) { return(null); } } // The interpreter name should be the same as the base interpreter. string interpExe = Path.GetFileName(baseInterpreter.Configuration.InterpreterPath); string winterpExe = Path.GetFileName(baseInterpreter.Configuration.WindowsInterpreterPath); var scripts = new[] { "Scripts", "bin" }; interpExe = PathUtils.FindFile(prefixPath, interpExe, firstCheck: scripts); winterpExe = PathUtils.FindFile(prefixPath, winterpExe, firstCheck: scripts); string pathVar = baseInterpreter.Configuration.PathEnvironmentVariable; string description = string.Format( "{0} ({1})", PathUtils.GetFileOrDirectoryName(prefixPath), baseInterpreter.Configuration.Description ); return(new InterpreterConfiguration( id ?? baseInterpreter.Configuration.Id, description, prefixPath, interpExe, winterpExe, libPath, pathVar, baseInterpreter.Configuration.Architecture, baseInterpreter.Configuration.Version, InterpreterUIMode.CannotBeDefault | InterpreterUIMode.CannotBeConfigured | InterpreterUIMode.SupportsDatabase )); }
public static async Task ShowDialog( PythonProjectNode project, IInterpreterOptionsService service, bool browseForExisting = false ) { using (var view = new AddVirtualEnvironmentView(project, service, project.Interpreters.ActiveInterpreter)) { var wnd = new AddVirtualEnvironment(view); if (browseForExisting) { var path = project.Site.BrowseForDirectory(IntPtr.Zero, project.ProjectHome); if (string.IsNullOrEmpty(path)) { throw new OperationCanceledException(); } view.VirtualEnvName = path; view.WillInstallRequirementsTxt = false; await view.WaitForReady(); if (view.WillAddVirtualEnv) { await view.Create(); return; } view.ShowBrowsePathError = true; view.BrowseOrigPrefix = DerivedInterpreterFactory.GetOrigPrefixPath(path); } wnd.VirtualEnvPathTextBox.ScrollToEnd(); wnd.VirtualEnvPathTextBox.SelectAll(); wnd.VirtualEnvPathTextBox.Focus(); wnd.ShowModal(); var op = wnd._currentOperation; if (op != null) { await op; } } }
public static InterpreterFactoryCreationOptions FindInterpreterOptions( string prefixPath, IInterpreterOptionsService service, IPythonInterpreterFactory baseInterpreter = null ) { var result = new InterpreterFactoryCreationOptions(); var libPath = DerivedInterpreterFactory.FindLibPath(prefixPath); result.PrefixPath = prefixPath; result.LibraryPath = libPath; if (baseInterpreter == null) { baseInterpreter = DerivedInterpreterFactory.FindBaseInterpreterFromVirtualEnv( prefixPath, libPath, service ); } string interpExe, winterpExe; if (baseInterpreter != null) { // The interpreter name should be the same as the base interpreter. interpExe = Path.GetFileName(baseInterpreter.Configuration.InterpreterPath); winterpExe = Path.GetFileName(baseInterpreter.Configuration.WindowsInterpreterPath); var scripts = new[] { "Scripts", "bin" }; result.InterpreterPath = CommonUtils.FindFile(prefixPath, interpExe, firstCheck: scripts); result.WindowInterpreterPath = CommonUtils.FindFile(prefixPath, winterpExe, firstCheck: scripts); result.PathEnvironmentVariableName = baseInterpreter.Configuration.PathEnvironmentVariable; } else { result.InterpreterPath = string.Empty; result.WindowInterpreterPath = string.Empty; result.PathEnvironmentVariableName = string.Empty; } if (baseInterpreter != null) { result.Description = string.Format( "{0} ({1})", CommonUtils.GetFileOrDirectoryName(prefixPath), baseInterpreter.Description ); result.Id = baseInterpreter.Id; result.LanguageVersion = baseInterpreter.Configuration.Version; result.Architecture = baseInterpreter.Configuration.Architecture; result.WatchLibraryForNewModules = true; } else { result.Description = CommonUtils.GetFileOrDirectoryName(prefixPath); result.Id = Guid.Empty; result.LanguageVersion = new Version(0, 0); result.Architecture = ProcessorArchitecture.None; result.WatchLibraryForNewModules = false; } return(result); }