private List <PythonInterpreterInformation> FindCondaEnvironments(string condaPath) { var found = new List <PythonInterpreterInformation>(); var watchFolders = new HashSet <string>(); var condaInfoResult = ExecuteCondaInfo(condaPath); if (condaInfoResult != null) { foreach (var folder in condaInfoResult.EnvironmentFolders) { if (!Directory.Exists(folder)) { continue; } PythonInterpreterInformation env = CreateEnvironmentInfo(folder); if (env != null) { found.Add(env); } } } return(found); }
public void Search(RegistryKey root, InterpreterArchitecture assumedArch) { if (root == null) { return; } var companies = GetSubkeys(root); foreach (var company in companies) { if ("PyLauncher".Equals(company, StringComparison.OrdinalIgnoreCase)) { continue; } bool pythonCore = "PythonCore".Equals(company, StringComparison.OrdinalIgnoreCase); using (var companyKey = root.OpenSubKey(company)) { if (companyKey == null) { continue; } var companyDisplay = companyKey.GetValue("DisplayName") as string; var companySupportUrl = companyKey.GetValue("SupportUrl") as string; if (pythonCore) { companyDisplay = companyDisplay ?? PythonCoreCompanyDisplayName; companySupportUrl = companySupportUrl ?? PythonCoreSupportUrl; } else { companyDisplay = companyDisplay ?? company; } var tags = GetSubkeys(companyKey); foreach (var tag in tags) { using (var tagKey = companyKey.OpenSubKey(tag)) using (var installKey = tagKey?.OpenSubKey("InstallPath")) { var config = TryReadConfiguration(company, tag, tagKey, installKey, pythonCore, assumedArch); if (config == null) { continue; } if (_seenIds.Add(config.Id)) { var supportUrl = tagKey.GetValue("SupportUrl") as string ?? companySupportUrl; var info = new PythonInterpreterInformation(config, companyDisplay, companySupportUrl, supportUrl); _info.Add(info); } } } } } }
private static PythonInterpreterInformation CreateEnvironmentInfo(string prefixPath) { var name = Path.GetFileName(prefixPath); var description = name; var vendor = Strings.CondaEnvironmentDescription; var vendorUrl = string.Empty; var supportUrl = string.Empty; var interpreterPath = Path.Combine(prefixPath, CondaEnvironmentFactoryConstants.ConsoleExecutable); var windowsInterpreterPath = Path.Combine(prefixPath, CondaEnvironmentFactoryConstants.WindowsExecutable); InterpreterArchitecture arch = InterpreterArchitecture.Unknown; Version version = null; if (File.Exists(interpreterPath)) { using (var output = ProcessOutput.RunHiddenAndCapture( interpreterPath, "-c", "import sys; print('%s.%s' % (sys.version_info[0], sys.version_info[1]))" )) { output.Wait(); if (output.ExitCode == 0) { var versionName = output.StandardOutputLines.FirstOrDefault() ?? ""; if (!Version.TryParse(versionName, out version)) { version = null; } } } arch = CPythonInterpreterFactoryProvider.ArchitectureFromExe(interpreterPath); } else { return(null); } var config = new InterpreterConfiguration( CondaEnvironmentFactoryConstants.GetInterpreterId(CondaEnvironmentFactoryProvider.EnvironmentCompanyName, name), description, prefixPath, interpreterPath, windowsInterpreterPath, CondaEnvironmentFactoryConstants.PathEnvironmentVariableName, arch, version ); config.SwitchToFullDescription(); var unique = new PythonInterpreterInformation( config, vendor, vendorUrl, supportUrl ); return(unique); }
private static PythonInterpreterInformation CreateEnvironmentInfo(string interpreterPath) { if (!File.Exists(interpreterPath)) { return(null); } var prefixPath = PrefixFromSysPrefix(interpreterPath); if (prefixPath == null) { return(null); } var arch = CPythonInterpreterFactoryProvider.ArchitectureFromExe(interpreterPath); var version = CPythonInterpreterFactoryProvider.VersionFromSysVersionInfo(interpreterPath); try { version.ToLanguageVersion(); } catch (InvalidOperationException) { version = new Version(0, 0); } var name = Path.GetFileName(prefixPath); var description = name; var vendor = Strings.WorkspaceEnvironmentDescription; var vendorUrl = string.Empty; var supportUrl = string.Empty; var windowsInterpreterPath = Path.Combine(Path.GetDirectoryName(interpreterPath), WorkspaceInterpreterFactoryConstants.WindowsExecutable); if (!File.Exists(windowsInterpreterPath)) { windowsInterpreterPath = string.Empty; } var config = new VisualStudioInterpreterConfiguration( WorkspaceInterpreterFactoryConstants.GetInterpreterId(WorkspaceInterpreterFactoryConstants.EnvironmentCompanyName, name), description, prefixPath, interpreterPath, windowsInterpreterPath, WorkspaceInterpreterFactoryConstants.PathEnvironmentVariableName, arch, version, InterpreterUIMode.CannotBeDefault | InterpreterUIMode.CannotBeConfigured ); config.SwitchToFullDescription(); var unique = new PythonInterpreterInformation( config, vendor, vendorUrl, supportUrl ); return(unique); }
private IPythonInterpreterFactory CreateFactory(PythonInterpreterInformation info) { return(InterpreterFactoryCreator.CreateInterpreterFactory( info.Configuration, new InterpreterFactoryCreationOptions { WatchFileSystem = true, } )); }
private List <PythonInterpreterInformation> FindCondaEnvironments(string condaPath) { var found = new List <PythonInterpreterInformation>(); var watchFolders = new HashSet <string>(); // Find environments that were created with "conda create -n <name>" var condaInfoResult = ExecuteCondaInfo(condaPath); if (condaInfoResult != null) { foreach (var folder in condaInfoResult.EnvironmentFolders) { if (!Directory.Exists(folder)) { continue; } PythonInterpreterInformation env = CreateEnvironmentInfo(folder); if (env != null) { found.Add(env); } } } // Find environments that were created with "conda create -p <folder>" // Note that this may have a bunch of entries that no longer exist // as well as duplicates that were returned by conda info. if (File.Exists(_environmentsTxtPath)) { try { var folders = File.ReadAllLines(_environmentsTxtPath); foreach (var folder in folders) { if (!Directory.Exists(folder)) { continue; } if (found.FirstOrDefault(pii => PathUtils.IsSameDirectory(pii.Configuration.PrefixPath, folder)) != null) { continue; } PythonInterpreterInformation env = CreateEnvironmentInfo(folder); if (env != null) { found.Add(env); } } } catch (IOException) { } catch (UnauthorizedAccessException) { } } return(found); }
private IPythonInterpreterFactory CreateFactory(PythonInterpreterInformation info) { return(InterpreterFactoryCreator.CreateInterpreterFactory( info.Configuration, new InterpreterFactoryCreationOptions { PackageManager = BuiltInPackageManagers.Conda, WatchFileSystem = true, NoDatabase = ExperimentalOptions.NoDatabaseFactory, DatabasePath = ExperimentalOptions.NoDatabaseFactory ? DatabasePathSelector.CalculateVSLocalDatabasePath(_site, info.Configuration, 1) : DatabasePathSelector.CalculateGlobalDatabasePath(info.Configuration, PythonTypeDatabase.FormatVersion) } )); }
private IPythonInterpreterFactory CreateFactory(PythonInterpreterInformation info) { if (!ExperimentalOptions.NoDatabaseFactory) { return(new LegacyDB.CPythonInterpreterFactory( info.Configuration, new InterpreterFactoryCreationOptions { WatchFileSystem = true, DatabasePath = DatabasePathSelector.CalculateGlobalDatabasePath(info.Configuration, LegacyDB.PythonTypeDatabase.FormatVersion) } )); } return(new Ast.AstPythonInterpreterFactory( info.Configuration, new InterpreterFactoryCreationOptions { WatchFileSystem = true, DatabasePath = DatabasePathSelector.CalculateVSLocalDatabasePath(_site, info.Configuration, 1) } )); }
private static PythonInterpreterInformation CreateEnvironmentInfo(string prefixPath) { var name = Path.GetFileName(prefixPath); var description = name; var vendor = Strings.CondaEnvironmentDescription; var vendorUrl = string.Empty; var supportUrl = string.Empty; var interpreterPath = Path.Combine(prefixPath, CondaEnvironmentFactoryConstants.ConsoleExecutable); var windowsInterpreterPath = Path.Combine(prefixPath, CondaEnvironmentFactoryConstants.WindowsExecutable); if (!File.Exists(interpreterPath)) { return(null); } var arch = CPythonInterpreterFactoryProvider.ArchitectureFromExe(interpreterPath); var version = CPythonInterpreterFactoryProvider.VersionFromSysVersionInfo(interpreterPath); var config = new VisualStudioInterpreterConfiguration( CondaEnvironmentFactoryConstants.GetInterpreterId(CondaEnvironmentFactoryProvider.EnvironmentCompanyName, name), description, prefixPath, interpreterPath, windowsInterpreterPath, CondaEnvironmentFactoryConstants.PathEnvironmentVariableName, arch, version ); config.SwitchToFullDescription(); var unique = new PythonInterpreterInformation( config, vendor, vendorUrl, supportUrl ); return(unique); }
private IPythonInterpreterFactory CreateFactory(PythonInterpreterInformation info) { if (!ExperimentalOptions.NoDatabaseFactory) { // Use the database-backed factory var fact = new LegacyDB.CPythonInterpreterFactory( info.Configuration, new InterpreterFactoryCreationOptions { WatchFileSystem = true, DatabasePath = DatabasePathSelector.CalculateGlobalDatabasePath(info.Configuration, LegacyDB.PythonTypeDatabase.FormatVersion) } ); fact.BeginRefreshIsCurrent(); return(fact); } return(InterpreterFactoryCreator.CreateInterpreterFactory( info.Configuration, new InterpreterFactoryCreationOptions { WatchFileSystem = true, DatabasePath = DatabasePathSelector.CalculateVSLocalDatabasePath(_site, info.Configuration, 1) } )); }
public void Search(RegistryKey root, InterpreterArchitecture assumedArch) { if (root == null) { return; } var companies = GetSubkeys(root); foreach (var company in companies) { if ("PyLauncher".Equals(company, StringComparison.OrdinalIgnoreCase)) { continue; } bool pythonCore = PythonCoreCompany.Equals(company, StringComparison.OrdinalIgnoreCase); using (var companyKey = root.OpenSubKey(company)) { if (companyKey == null) { continue; } var companyDisplay = companyKey.GetValue("DisplayName") as string; var companySupportUrl = companyKey.GetValue("SupportUrl") as string; if (pythonCore) { companyDisplay = companyDisplay ?? PythonCoreCompanyDisplayName; companySupportUrl = companySupportUrl ?? PythonCoreSupportUrl; } else { companyDisplay = companyDisplay ?? company; } var tags = GetSubkeys(companyKey); foreach (var tag in tags) { using (var tagKey = companyKey.OpenSubKey(tag)) using (var installKey = tagKey?.OpenSubKey("InstallPath")) { var config = TryReadConfiguration(company, tag, tagKey, installKey, pythonCore, assumedArch); if (config == null) { continue; } if (_seenIds.Add(config.Id)) { var supportUrl = tagKey.GetValue("SupportUrl") as string ?? companySupportUrl; // We don't want to send people to http://python.org, even // if that's what is in the registry, so catch and fix it. if (!string.IsNullOrEmpty(supportUrl)) { var url = supportUrl.TrimEnd('/'); if (url.Equals("http://www.python.org", StringComparison.OrdinalIgnoreCase) || url.Equals("http://python.org", StringComparison.OrdinalIgnoreCase)) { supportUrl = PythonCoreSupportUrl; } } var info = new PythonInterpreterInformation(config, companyDisplay, companySupportUrl, supportUrl); _info.Add(info); } } } } } InterpreterConfiguration.DisambiguateDescriptions(_info.Select(i => i.Configuration).ToArray()); }
public void Search(RegistryKey root, InterpreterArchitecture assumedArch) { if (root == null) { return; } var companies = GetSubkeys(root); foreach (var company in companies) { if ("PyLauncher".Equals(company, StringComparison.OrdinalIgnoreCase)) { continue; } bool pythonCore = PythonCoreCompany.Equals(company, StringComparison.OrdinalIgnoreCase); using (var companyKey = root.OpenSubKey(company)) { if (companyKey == null) { continue; } var companyDisplay = companyKey.GetValue("DisplayName") as string; var companySupportUrl = companyKey.GetValue("SupportUrl") as string; if (pythonCore) { companyDisplay = companyDisplay ?? PythonCoreCompanyDisplayName; companySupportUrl = companySupportUrl ?? PythonCoreSupportUrl; } else { companyDisplay = companyDisplay ?? company; } var tags = GetSubkeys(companyKey); foreach (var tag in tags) { using (var tagKey = companyKey.OpenSubKey(tag)) using (var installKey = tagKey?.OpenSubKey("InstallPath")) { var config = TryReadConfiguration(company, tag, tagKey, installKey, pythonCore, assumedArch); if (config == null) { continue; } if (_seenIds.Add(config.Id)) { var supportUrl = tagKey.GetValue("SupportUrl") as string ?? companySupportUrl; var info = new PythonInterpreterInformation(config, companyDisplay, companySupportUrl, supportUrl); _info.Add(info); } } } } } }