Exemple #1
0
        private static ProjectItemElement AddVirtualEnvironment(
            ProjectRootElement project,
            string sourcePath,
            string id,
            InterpreterConfiguration config
            )
        {
            var prefixPath      = config.GetPrefixPath() ?? string.Empty;
            var interpreterPath = string.IsNullOrEmpty(config.InterpreterPath) ?
                                  string.Empty :
                                  PathUtils.GetRelativeFilePath(prefixPath, config.InterpreterPath);
            var windowInterpreterPath = string.IsNullOrEmpty(config.GetWindowsInterpreterPath()) ?
                                        string.Empty :
                                        PathUtils.GetRelativeFilePath(prefixPath, config.GetWindowsInterpreterPath());

            prefixPath = PathUtils.GetRelativeDirectoryPath(sourcePath, prefixPath);

            return(project.AddItem(
                       MSBuildConstants.InterpreterItem,
                       prefixPath,
                       new Dictionary <string, string> {
                { MSBuildConstants.IdKey, id },
                { MSBuildConstants.DescriptionKey, config.Description },
                { MSBuildConstants.InterpreterPathKey, interpreterPath },
                { MSBuildConstants.WindowsPathKey, windowInterpreterPath },
                { MSBuildConstants.VersionKey, config.Version.ToString() },
                { MSBuildConstants.ArchitectureKey, config.Architecture.ToString("X") },
                { MSBuildConstants.PathEnvVarKey, config.PathEnvironmentVariable }
            }
                       ));
        }
Exemple #2
0
        public static bool ShouldElevate(IServiceProvider site, InterpreterConfiguration config, string operation)
        {
            var opts = site.GetPythonToolsService().GeneralOptions;

            if (opts.ElevatePip)
            {
                return(true);
            }

            try {
                // Create a test file and delete it immediately to ensure we can do it.
                // If this fails, prompt the user to see whether they want to elevate.
                var testFile = PathUtils.GetAvailableFilename(config.GetPrefixPath(), "access-test", ".txt");
                using (new FileStream(testFile, FileMode.CreateNew, FileAccess.Write, FileShare.Delete, 4096, FileOptions.DeleteOnClose)) { }
                return(false);
            } catch (IOException) {
            } catch (UnauthorizedAccessException) {
            }

            var td = new TaskDialog(site)
            {
                Title             = Strings.ProductTitle,
                MainInstruction   = Strings.ElevateForInstallPackage_MainInstruction,
                AllowCancellation = true,
            };
            var elevate = new TaskDialogButton(Strings.ElevateForInstallPackage_Elevate, Strings.ElevateForInstallPackage_Elevate_Note)
            {
                ElevationRequired = true
            };
            var noElevate     = new TaskDialogButton(Strings.ElevateForInstallPackage_DoNotElevate, Strings.ElevateForInstallPackage_DoNotElevate_Note);
            var elevateAlways = new TaskDialogButton(Strings.ElevateForInstallPackage_ElevateAlways, Strings.ElevateForInstallPackage_ElevateAlways_Note)
            {
                ElevationRequired = true
            };

            td.Buttons.Add(elevate);
            td.Buttons.Add(noElevate);
            td.Buttons.Add(elevateAlways);
            td.Buttons.Add(TaskDialogButton.Cancel);
            var sel = td.ShowModal();

            if (sel == TaskDialogButton.Cancel)
            {
                throw new OperationCanceledException();
            }

            if (sel == noElevate)
            {
                return(false);
            }

            if (sel == elevateAlways)
            {
                opts.ElevatePip = true;
                opts.Save();
            }

            return(true);
        }
Exemple #3
0
 private void UpdateResultFromConfiguration(InterpreterConfiguration config, string projectHome)
 {
     PrefixPath = PathUtils.EnsureEndSeparator(config.GetPrefixPath());
     if (PathUtils.IsSubpathOf(projectHome, PrefixPath))
     {
         ProjectRelativePrefixPath = PathUtils.GetRelativeDirectoryPath(projectHome, PrefixPath);
     }
     else
     {
         ProjectRelativePrefixPath = string.Empty;
     }
     InterpreterPath         = config.InterpreterPath;
     WindowsInterpreterPath  = config.GetWindowsInterpreterPath();
     Architecture            = config.Architecture.ToString("X");
     PathEnvironmentVariable = config.PathEnvironmentVariable;
     Description             = config.Description;
     MajorVersion            = config.Version.Major.ToString();
     MinorVersion            = config.Version.Minor.ToString();
 }
Exemple #4
0
        private static bool HasPrefixName(InterpreterConfiguration config, string name)
        {
            var current = PathUtils.GetFileOrDirectoryName(config.GetPrefixPath());

            return(string.CompareOrdinal(current, name) == 0);
        }
Exemple #5
0
        internal static bool ExcludeInterpreter(InterpreterConfiguration config, InterpreterFilter excludeInterpreters = InterpreterFilter.None)
        {
            if (excludeInterpreters == InterpreterFilter.None)
            {
                return(false);
            }

            if (excludeInterpreters.HasFlag(InterpreterFilter.ExcludeVirtualEnv) && VirtualEnv.IsPythonVirtualEnv(config.GetPrefixPath()))
            {
                return(true);
            }

            if (excludeInterpreters.HasFlag(InterpreterFilter.ExcludeCondaEnv) && CondaUtils.IsCondaEnvironment(config.GetPrefixPath()))
            {
                return(true);
            }

            if (excludeInterpreters.HasFlag(InterpreterFilter.ExcludeIronpython) && config.IsIronPython())
            {
                return(true);
            }

            return(false);
        }