Exemplo n.º 1
0
        /// <summary>
        /// Checks whether a given package is installed and satisfies the
        /// version specification.
        /// </summary>
        /// <param name="package">
        /// Name, and optionally the version of the package to install, in
        /// setuptools format.
        /// </param>
        /// <remarks>
        /// This method requires setuptools to be installed to correctly detect
        /// packages and verify their versions. If setuptools is not available,
        /// the method will always return <c>false</c> for any package name.
        /// </remarks>
        public static async Task <bool> IsInstalled(IPythonInterpreterFactory factory, string package)
        {
            if (!factory.IsRunnable())
            {
                return(false);
            }

            var code = string.Format("import pkg_resources; pkg_resources.require('{0}')", package);

            using (var proc = ProcessOutput.Run(
                       factory.Configuration.InterpreterPath,
                       new[] { "-c", code },
                       factory.Configuration.PrefixPath,
                       UnbufferedEnv,
                       visible: false,
                       redirector: null,
                       quoteArgs: true)
                   ) {
                try {
                    return(await proc == 0);
                } catch (NoInterpretersException) {
                    return(false);
                }
            }
        }
Exemplo n.º 2
0
        public static bool CanInstall(
            IPythonInterpreterFactory factory,
            IInterpreterOptionsService service
            )
        {
            if (!factory.IsRunnable())
            {
                return(false);
            }

            return(TryGetCondaFactoryAsync(factory, service).WaitAndUnwrapExceptions() != null);
        }
Exemplo n.º 3
0
        public static bool CanInstall(
            IPythonInterpreterFactory factory,
            IInterpreterOptionsService service
            )
        {
            if (!factory.IsRunnable())
            {
                return(false);
            }

            IPythonInterpreterFactory dummy;

            return(TryGetCondaFactory(factory, service, out dummy));
        }
Exemplo n.º 4
0
        public static bool CanInstall(
            IPythonInterpreterFactory factory,
            IInterpreterOptionsService service
        ) {
            if (!factory.IsRunnable()) {
                return false;
            }

            return TryGetCondaFactoryAsync(factory, service).WaitAndUnwrapExceptions() != null;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Disable Copy/Cut/Paste commands on interpreter node.
        /// </summary>
        internal override int QueryStatusOnNode(Guid cmdGroup, uint cmd, IntPtr pCmdText, ref QueryStatusResult result)
        {
            if (cmdGroup == VsMenus.guidStandardCommandSet2K)
            {
                switch ((VsCommands2K)cmd)
                {
                case CommonConstants.OpenFolderInExplorerCmdId:
                    result = QueryStatusResult.SUPPORTED;
                    if (_factory != null && Directory.Exists(_factory.Configuration.GetPrefixPath()))
                    {
                        result |= QueryStatusResult.ENABLED;
                    }
                    return(VSConstants.S_OK);
                }
            }

            if (cmdGroup == GuidList.guidPythonToolsCmdSet)
            {
                switch (cmd)
                {
                case PythonConstants.ActivateEnvironment:
                    result |= QueryStatusResult.SUPPORTED;
                    if (_factory != null && _factory.Configuration.IsAvailable() &&
                        ProjectMgr.ActiveInterpreter != _factory &&
                        Directory.Exists(_factory.Configuration.GetPrefixPath())
                        )
                    {
                        result |= QueryStatusResult.ENABLED;
                    }
                    return(VSConstants.S_OK);

                case PythonConstants.InstallPythonPackage:
                    result |= QueryStatusResult.SUPPORTED;
                    if (_factory != null && _factory.Configuration.IsAvailable() &&
                        Directory.Exists(_factory.Configuration.GetPrefixPath())
                        )
                    {
                        result |= QueryStatusResult.ENABLED;
                    }
                    return(VSConstants.S_OK);

                case PythonConstants.InstallRequirementsTxt:
                    result |= QueryStatusResult.SUPPORTED;
                    if (_factory != null && _factory.IsRunnable() &&
                        File.Exists(PathUtils.GetAbsoluteFilePath(ProjectMgr.ProjectHome, "requirements.txt")))
                    {
                        result |= QueryStatusResult.ENABLED;
                    }
                    return(VSConstants.S_OK);

                case PythonConstants.GenerateRequirementsTxt:
                    result |= QueryStatusResult.SUPPORTED;
                    if (_factory != null && _factory.Configuration.IsAvailable())
                    {
                        result |= QueryStatusResult.ENABLED;
                    }
                    return(VSConstants.S_OK);

                case PythonConstants.OpenInteractiveForEnvironment:
                    result |= QueryStatusResult.SUPPORTED;
                    if (_factory != null && _factory.Configuration.IsAvailable() &&
                        File.Exists(_factory.Configuration.InterpreterPath)
                        )
                    {
                        result |= QueryStatusResult.ENABLED;
                    }
                    return(VSConstants.S_OK);
                }
            }

            if (cmdGroup == ProjectMgr.SharedCommandGuid)
            {
                switch ((SharedCommands)cmd)
                {
                case SharedCommands.OpenCommandPromptHere:
                    result |= QueryStatusResult.SUPPORTED;
                    if (_factory != null && _factory.Configuration.IsAvailable() &&
                        Directory.Exists(_factory.Configuration.GetPrefixPath()) &&
                        File.Exists(_factory.Configuration.InterpreterPath))
                    {
                        result |= QueryStatusResult.ENABLED;
                    }
                    return(VSConstants.S_OK);

                case SharedCommands.CopyFullPath:
                    result |= QueryStatusResult.SUPPORTED;
                    if (_factory != null && _factory.Configuration.IsAvailable() &&
                        Directory.Exists(_factory.Configuration.GetPrefixPath()) &&
                        File.Exists(_factory.Configuration.InterpreterPath))
                    {
                        result |= QueryStatusResult.ENABLED;
                    }
                    return(VSConstants.S_OK);
                }
            }

            return(base.QueryStatusOnNode(cmdGroup, cmd, pCmdText, ref result));
        }
Exemplo n.º 6
0
Arquivo: Pip.cs Projeto: omnimark/PTVS
        /// <summary>
        /// Checks whether a given package is installed and satisfies the
        /// version specification.
        /// </summary>
        /// <param name="package">
        /// Name, and optionally the version of the package to install, in
        /// setuptools format.
        /// </param>
        /// <remarks>
        /// This method requires setuptools to be installed to correctly detect
        /// packages and verify their versions. If setuptools is not available,
        /// the method will always return <c>false</c> for any package name.
        /// </remarks>
        public static async Task<bool> IsInstalled(IPythonInterpreterFactory factory, string package) {
            if (!factory.IsRunnable()) {
                return false;
            }

            var code = string.Format("import pkg_resources; pkg_resources.require('{0}')", package);
            using (var proc = ProcessOutput.Run(
                factory.Configuration.InterpreterPath,
                new[] { "-c", code  },
                factory.Configuration.PrefixPath,
                UnbufferedEnv,
                visible: false,
                redirector: null,
                quoteArgs: true)
            ) {
                return await proc == 0;
            }
        }