public string ApplyConfiguration(ConfigurationEnvironmentView view)
        {
            if (!_alwaysCreateNew)
            {
                var factory = view.EnvironmentView.Factory;
                if (view.Description != factory.Configuration.Description)
                {
                    // We're renaming the interpreter, remove the old one...
                    _interpreterOptions.RemoveConfigurableInterpreter(factory.Configuration.Id);
                }
            }

            Version version;

            if (!Version.TryParse(view.VersionName, out version))
            {
                version = null;
            }

            return(_interpreterOptions.AddConfigurableInterpreter(
                       view.Description,
                       new InterpreterConfiguration(
                           "",
                           view.Description,
                           view.PrefixPath,
                           view.InterpreterPath,
                           view.WindowsInterpreterPath,
                           view.PathEnvironmentVariable,
                           InterpreterArchitecture.TryParse(view.ArchitectureName ?? ""),
                           version
                           )
                       ));
        }
Exemple #2
0
        public void ApplyConfiguration(ConfigurationEnvironmentView view)
        {
            var factory = view.EnvironmentView.Factory;

            if (view.Description != factory.Configuration.Description)
            {
                // We're renaming the interpreter, remove the old one...
                _interpreterOptions.RemoveConfigurableInterpreter(factory.Configuration.Id);
            }

            var newInterp = _interpreterOptions.AddConfigurableInterpreter(
                view.Description,
                new InterpreterConfiguration(
                    "",
                    view.Description,
                    view.PrefixPath,
                    view.InterpreterPath,
                    view.WindowsInterpreterPath,
                    view.LibraryPath,
                    view.PathEnvironmentVariable,
                    view.ArchitectureName == "64-bit" ? ProcessorArchitecture.Amd64 : ProcessorArchitecture.X86,
                    Version.Parse(view.VersionName)
                    )
                );
        }
Exemple #3
0
        internal void SaveInterpreterOptions()
        {
            _interpreterRegistry.BeginSuppressInterpretersChangedEvent();
            try {
                _interpreterOptionsService.DefaultInterpreterId = GlobalInterpreterOptions.DefaultInterpreter;
                // Remove any items
                foreach (var option in InterpreterOptions.Select(kv => kv.Value).Where(o => o.Removed).ToList())
                {
                    _interpreterOptionsService.RemoveConfigurableInterpreter(option._config.Id);
                    RemoveInterpreterOptions(option._config.Id);
                }

                // Add or update any items that weren't removed
                foreach (var option in InterpreterOptions.Select(x => x.Value))
                {
                    if (option.Added)
                    {
                        if (String.IsNullOrWhiteSpace(option.Id))
                        {
                            option.Id = Guid.NewGuid().ToString();
                        }
                        option.Added = false;
                    }

                    if (option.IsConfigurable)
                    {
                        // save configurable interpreter options
                        var actualFactory = _interpreterOptionsService.AddConfigurableInterpreter(
                            option.Description,
                            new InterpreterConfiguration(
                                option.Id,
                                option.Description,
                                !String.IsNullOrWhiteSpace(option.InterpreterPath) ? PathUtils.GetParent(option.InterpreterPath) : "",
                                option.InterpreterPath ?? "",
                                option.WindowsInterpreterPath ?? "",
                                option.PathEnvironmentVariable ?? "",
                                InterpreterArchitecture.TryParse(option.Architecture),
                                Version.Parse(option.Version) ?? new Version(2, 7)
                                )
                            );
                    }
                }


                foreach (var factory in InterpreterOptions.Where(x => x.Value.Id.StartsWith("Placeholder;")).ToArray())
                {
                    RemoveInterpreterOptions(factory.Value.Id);
                }
            } finally {
                _interpreterRegistry.EndSuppressInterpretersChangedEvent();
            }
        }
Exemple #4
0
        private async void AddCustomEnvironment_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (_service == null)
            {
                return;
            }

            const string baseName = "New Environment";
            string       name     = baseName;
            int          count    = 2;

            while (_interpreters.FindConfiguration(CPythonInterpreterFactoryConstants.GetInterpreterId("VisualStudio", name)) != null)
            {
                name = baseName + " " + count++;
            }

            var factory = _service.AddConfigurableInterpreter(
                name,
                new InterpreterConfiguration(
                    "",
                    name,
                    "",
                    "python\\python.exe",
                    arch: InterpreterArchitecture.x86
                    )
                );

            UpdateEnvironments(factory);

            await Dispatcher.InvokeAsync(() => {
                var coll = TryFindResource("SortedExtensions") as CollectionViewSource;
                if (coll != null)
                {
                    var select = coll.View.OfType <ConfigurationExtensionProvider>().FirstOrDefault();
                    if (select != null)
                    {
                        coll.View.MoveCurrentTo(select);
                    }
                }
            }, DispatcherPriority.Normal);
        }
Exemple #5
0
        public static async Task <IPythonInterpreterFactory> CreateCustomEnv(
            IInterpreterRegistryService registryService,
            IInterpreterOptionsService optionsService,
            string prefixPath,
            string interpreterPath,
            string windowsInterpreterPath,
            string pathEnvironmentVariable,
            InterpreterArchitecture architecture,
            Version version,
            string description
            )
        {
            if (registryService == null)
            {
                throw new ArgumentNullException(nameof(registryService));
            }

            if (optionsService == null)
            {
                throw new ArgumentNullException(nameof(optionsService));
            }

            var id = optionsService.AddConfigurableInterpreter(
                description,
                new InterpreterConfiguration(
                    "", // ignored - id is generated and returned by AddConfigurableInterpreter
                    description,
                    prefixPath,
                    interpreterPath,
                    windowsInterpreterPath,
                    pathEnvironmentVariable,
                    architecture,
                    version
                    )
                );

            return(registryService.FindInterpreter(id));
        }