public async Task Run()
        {
            var service = _project.Site.GetComponentModel().GetService <IInterpreterRegistryService>();

            IPythonInterpreterFactory factory;

            try {
                var baseInterp = service.FindInterpreter(_baseInterpreter);

                factory = await _project.CreateOrAddVirtualEnvironment(
                    service,
                    _create,
                    _virtualEnvPath,
                    baseInterp,
                    _useVEnv
                    );
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                WriteError(ex.Message);
                factory = null;
            }

            if (factory == null)
            {
                return;
            }

            var txt = PathUtils.GetAbsoluteFilePath(_project.ProjectHome, "requirements.txt");

            if (!_installRequirements || !File.Exists(txt))
            {
                return;
            }

            if (factory.PackageManager == null)
            {
                WriteError(
                    Strings.PackageManagementNotSupported_Package.FormatUI(PathUtils.GetFileOrDirectoryName(txt))
                    );
                return;
            }

            WriteOutput(Strings.RequirementsTxtInstalling.FormatUI(txt));
            if (await factory.PackageManager.InstallAsync(
                    PackageSpec.FromArguments("-r " + ProcessOutput.QuoteSingleArgument(txt)),
                    new VsPackageManagerUI(_project.Site),
                    CancellationToken.None
                    ))
            {
                WriteOutput(Strings.PackageInstallSucceeded.FormatUI(Path.GetFileName(txt)));
            }
            else
            {
                WriteOutput(Strings.PackageInstallFailed.FormatUI(Path.GetFileName(txt)));
            }
        }
        public async Task Run()
        {
            var service = _project.Site.GetComponentModel().GetService <IInterpreterRegistryService>();

            IPythonInterpreterFactory factory;

            try {
                factory = await _project.CreateOrAddVirtualEnvironment(
                    service,
                    _create,
                    _virtualEnvPath,
                    _baseInterpreter,
                    _useVEnv
                    );
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                WriteError(ex.Message);
                factory = null;
            }

            if (factory == null)
            {
                return;
            }

            var txt = PathUtils.GetAbsoluteFilePath(_project.ProjectHome, "requirements.txt");

            if (!_installRequirements || !File.Exists(txt))
            {
                return;
            }

            WriteOutput(Strings.RequirementsTxtInstalling.FormatUI(txt));
            if (await Pip.Install(
                    _project.Site,
                    factory,
                    "-r " + ProcessOutput.QuoteSingleArgument(txt),
                    false, // never elevate for a virtual environment
                    _output
                    ))
            {
                WriteOutput(Strings.PackageInstallSucceeded.FormatUI(Path.GetFileName(txt)));
            }
            else
            {
                WriteOutput(Strings.PackageInstallFailed.FormatUI(Path.GetFileName(txt)));
            }
        }
        public async Task Run()
        {
            var service = _project.Site.GetComponentModel().GetService <IInterpreterOptionsService>();

            var factory = await _project.CreateOrAddVirtualEnvironment(
                service,
                _create,
                _virtualEnvPath,
                _baseInterpreter,
                _useVEnv
                );

            if (factory == null)
            {
                return;
            }

            var txt = CommonUtils.GetAbsoluteFilePath(_project.ProjectHome, "requirements.txt");

            if (!_installRequirements || !File.Exists(txt))
            {
                return;
            }

            WriteOutput(SR.RequirementsTxtInstalling, txt);
            if (await Pip.Install(
                    _project.Site,
                    factory,
                    "-r " + ProcessOutput.QuoteSingleArgument(txt),
                    false, // never elevate for a virtual environment
                    _output
                    ))
            {
                WriteOutput(SR.PackageInstallSucceeded, Path.GetFileName(txt));
            }
            else
            {
                WriteOutput(SR.PackageInstallFailed, Path.GetFileName(txt));
            }
        }
Exemplo n.º 4
0
        public async Task Run()
        {
            var service = _project.Site.GetComponentModel().GetService <IInterpreterRegistryService>();

            IPythonInterpreterFactory factory;

            try {
                var baseInterp = service.FindInterpreter(_baseInterpreter);

                factory = await _project.CreateOrAddVirtualEnvironment(
                    service,
                    _create,
                    _virtualEnvPath,
                    baseInterp,
                    _useVEnv
                    );
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                WriteError(ex.Message);
                factory = null;
            }

            if (factory == null)
            {
                return;
            }

            var txt = _requirementsPath;

            if (!_installRequirements || !File.Exists(txt))
            {
                return;
            }

            var interpreterOpts = _project.Site.GetComponentModel().GetService <IInterpreterOptionsService>();
            var pm = interpreterOpts?.GetPackageManagers(factory).FirstOrDefault(p => p.UniqueKey == "pip");

            if (pm == null)
            {
                WriteError(
                    Strings.PackageManagementNotSupported_Package.FormatUI(PathUtils.GetFileOrDirectoryName(txt))
                    );
                return;
            }

            WriteOutput(Strings.RequirementsTxtInstalling.FormatUI(txt));
            bool success = false;

            try {
                var ui = new VsPackageManagerUI(_project.Site);
                if (!pm.IsReady)
                {
                    await pm.PrepareAsync(ui, CancellationToken.None);
                }
                success = await pm.InstallAsync(
                    PackageSpec.FromArguments("-r " + ProcessOutput.QuoteSingleArgument(txt)),
                    ui,
                    CancellationToken.None
                    );
            } catch (InvalidOperationException ex) {
                WriteOutput(ex.Message);
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                WriteOutput(ex.Message);
                Debug.Fail(ex.ToUnhandledExceptionMessage(GetType()));
            }

            if (success)
            {
                WriteOutput(Strings.PackageInstallSucceeded.FormatUI(Path.GetFileName(txt)));
            }
            else
            {
                WriteOutput(Strings.PackageInstallFailed.FormatUI(Path.GetFileName(txt)));
            }
        }