Esempio n. 1
0
        public AddInterpreterView(
            IServiceProvider serviceProvider,
            IInterpreterOptionsService interpreterService,
            IEnumerable<IPythonInterpreterFactory> selected
        ) {
            _interpreterService = interpreterService;
            Interpreters = new ObservableCollection<InterpreterView>(InterpreterView.GetInterpreters(serviceProvider, interpreterService));
            
            var map = new Dictionary<IPythonInterpreterFactory, InterpreterView>();
            foreach (var view in Interpreters) {
                map[view.Interpreter] = view;
                view.IsSelected = false;
            }

            foreach (var interp in selected) {
                InterpreterView view;
                if (map.TryGetValue(interp, out view)) {
                    view.IsSelected = true;
                } else {
                    view = new InterpreterView(interp, interp.Description, false);
                    view.IsSelected = true;
                    Interpreters.Add(view);
                }
            }

            _interpreterService.InterpretersChanged += OnInterpretersChanged;
        }
Esempio n. 2
0
        internal EnvironmentView(
            IInterpreterOptionsService service,
            IInterpreterRegistryService registry,
            IPythonInterpreterFactory factory,
            Redirector redirector
            )
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }
            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }
            if (factory.Configuration == null)
            {
                throw new ArgumentException("factory must include a configuration");
            }

            _service                 = service;
            _registry                = registry;
            Factory                  = factory;
            Configuration            = Factory.Configuration;
            LocalizedDisplayName     = Configuration.Description;
            IsBroken                 = !Configuration.IsRunnable();
            LocalizedAutomationName  = !IsBroken ? LocalizedDisplayName : String.Format(Resources.BrokenEnvironmentAutomationNameFormat, LocalizedDisplayName);
            BrokenEnvironmentHelpUrl = "https://go.microsoft.com/fwlink/?linkid=863373";

            if (_service.IsConfigurable(Factory.Configuration.Id))
            {
                IsConfigurable = true;
            }

            Description = Factory.Configuration.Description;
            IsDefault   = (_service != null && _service.DefaultInterpreterId == Configuration.Id);

            PrefixPath             = Factory.Configuration.GetPrefixPath();
            InterpreterPath        = Factory.Configuration.InterpreterPath;
            WindowsInterpreterPath = Factory.Configuration.GetWindowsInterpreterPath();

            Extensions = new ObservableCollection <object>();
            Extensions.Add(new EnvironmentPathsExtensionProvider());
            if (IsConfigurable)
            {
                Extensions.Add(new ConfigurationExtensionProvider(_service, alwaysCreateNew: false));
            }

            CanBeDefault = Factory.CanBeDefault();
            CanBeDeleted = Factory.CanBeDeleted();

            Company    = _registry.GetProperty(Factory.Configuration.Id, CompanyKey) as string ?? "";
            SupportUrl = _registry.GetProperty(Factory.Configuration.Id, SupportUrlKey) as string ?? "";

            LocalizedHelpText = Company;
        }
Esempio n. 3
0
        private AddInterpreter(PythonProjectNode project, IInterpreterOptionsService service) {
            _view = new AddInterpreterView(project, project.Site, project.InterpreterFactories);
            _view.PropertyChanged += View_PropertyChanged;
            DataContext = _view;

            InitializeComponent();
        }
Esempio n. 4
0
        private TestContainerDiscovererProject(
            [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider,
            [Import(typeof(IOperationState))] IOperationState operationState,
            [Import] IPythonWorkspaceContextProvider workspaceContextProvider,
            [Import] IInterpreterOptionsService interpreterOptionsService
            )
        {
            _serviceProvider          = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
            _workspaceContextProvider = workspaceContextProvider ?? throw new ArgumentNullException(nameof(workspaceContextProvider));
            _projectMap = new ConcurrentDictionary <string, ProjectInfo>();
            _packageManagerEventSink = new PackageManagerEventSink(interpreterOptionsService);
            _packageManagerEventSink.InstalledPackagesChanged += OnInstalledPackagesChanged;
            _firstLoad     = true;
            _isRefresh     = false;
            _setupComplete = false;
            _deferredTestChangeNotification = new Timer(OnDeferredTestChanged);

            _solutionListener = new SolutionEventsListener(_serviceProvider);
            _solutionListener.ProjectLoaded    += OnProjectLoaded;
            _solutionListener.ProjectUnloading += OnProjectUnloaded;
            _solutionListener.ProjectClosing   += OnProjectUnloaded;
            _solutionListener.SolutionOpened   += OnSolutionLoaded;
            _solutionListener.SolutionClosed   += OnSolutionClosed;
            _solutionListener.StartListeningForChanges();

            _testFilesAddRemoveListener = new TestFileAddRemoveListener(_serviceProvider, new Guid());
            _testFilesAddRemoveListener.TestFileChanged += OnProjectItemChanged;
            _testFilesAddRemoveListener.StartListeningForTestFileChanges();
        }
 public EnvironmentSwitcherFileContext(IServiceProvider serviceProvider, string filePath)
 {
     _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
     _optionsService  = serviceProvider.GetComponentModel().GetService <IInterpreterOptionsService>();
     _registryService = serviceProvider.GetComponentModel().GetService <IInterpreterRegistryService>();
     _filePath        = filePath ?? throw new ArgumentNullException(nameof(filePath));
 }
Esempio n. 6
0
        public AddVirtualEnvironmentView(
            PythonProjectNode project,
            IInterpreterOptionsService interpreterService,
            IPythonInterpreterFactory selectInterpreter
            )
        {
            _interpreterService = interpreterService;
            _project            = project;
            VirtualEnvBasePath  = _projectHome = project.ProjectHome;
            Interpreters        = new ObservableCollection <InterpreterView>(InterpreterView.GetInterpreters(project.Site, interpreterService));
            var selection = Interpreters.FirstOrDefault(v => v.Interpreter == selectInterpreter);

            if (selection == null)
            {
                selection = Interpreters.FirstOrDefault(v => v.Interpreter == interpreterService.DefaultInterpreter)
                            ?? Interpreters.LastOrDefault();
            }
            BaseInterpreter = selection;

            _interpreterService.InterpretersChanged += OnInterpretersChanged;

            var venvName = "env";

            for (int i = 1; Directory.Exists(Path.Combine(_projectHome, venvName)); ++i)
            {
                venvName = "env" + i.ToString();
            }
            VirtualEnvName = venvName;

            CanInstallRequirementsTxt  = File.Exists(CommonUtils.GetAbsoluteFilePath(_projectHome, "requirements.txt"));
            WillInstallRequirementsTxt = CanInstallRequirementsTxt;
        }
Esempio n. 7
0
        public void InitializeEnvironments(IInterpreterRegistryService interpreters, IInterpreterOptionsService options, bool synchronous = false)
        {
            if (_interpreters != null)
            {
                _interpreters.InterpretersChanged -= Service_InterpretersChanged;
            }
            _interpreters = interpreters;
            if (_interpreters != null)
            {
                _interpreters.InterpretersChanged += Service_InterpretersChanged;
            }

            if (_options != null)
            {
                _options.DefaultInterpreterChanged -= Service_DefaultInterpreterChanged;
            }
            _options = options;
            if (_options != null)
            {
                _options.DefaultInterpreterChanged += Service_DefaultInterpreterChanged;
            }

            if (_interpreters != null && _options != null)
            {
                if (synchronous)
                {
                    Dispatcher.Invoke(FirstUpdateEnvironments);
                }
                else
                {
                    Dispatcher.InvokeAsync(FirstUpdateEnvironments).Task.DoNotWait();
                }
            }
        }
Esempio n. 8
0
 public TestMethodResolver([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider,
                           [Import] TestContainerDiscoverer discoverer)
 {
     _serviceProvider    = serviceProvider;
     _discoverer         = discoverer;
     _interpreterService = ((IComponentModel)_serviceProvider.GetService(typeof(SComponentModel))).GetService <IInterpreterOptionsService>();
 }
Esempio n. 9
0
        public AddInterpreterView(
            IServiceProvider serviceProvider,
            IInterpreterOptionsService interpreterService,
            IEnumerable <IPythonInterpreterFactory> selected
            )
        {
            _interpreterService = interpreterService;
            Interpreters        = new ObservableCollection <InterpreterView>(InterpreterView.GetInterpreters(serviceProvider, interpreterService));

            var map = new Dictionary <IPythonInterpreterFactory, InterpreterView>();

            foreach (var view in Interpreters)
            {
                map[view.Interpreter] = view;
                view.IsSelected       = false;
            }

            foreach (var interp in selected)
            {
                InterpreterView view;
                if (map.TryGetValue(interp, out view))
                {
                    view.IsSelected = true;
                }
                else
                {
                    view            = new InterpreterView(interp, interp.Description, false);
                    view.IsSelected = true;
                    Interpreters.Add(view);
                }
            }

            _interpreterService.InterpretersChanged += OnInterpretersChanged;
        }
Esempio n. 10
0
 internal GlobalInterpreterOptions(PythonToolsService pyService, IInterpreterOptionsService interpreterOptions, IInterpreterRegistryService interpreters)
 {
     _pyService          = pyService;
     _interpreters       = interpreters;
     _interpreterOptions = interpreterOptions;
     Load();
 }
Esempio n. 11
0
        private AddInterpreter(PythonProjectNode project, IInterpreterOptionsService service)
        {
            _view       = new AddInterpreterView(project, project.Site, project.InterpreterIds);
            DataContext = _view;

            InitializeComponent();
        }
Esempio n. 12
0
        public AddVirtualEnvironmentView(
            PythonProjectNode project,
            IInterpreterOptionsService interpreterService,
            IPythonInterpreterFactory selectInterpreter
        ) {
            _interpreterService = interpreterService;
            _project = project;
            VirtualEnvBasePath = _projectHome = project.ProjectHome;
            Interpreters = new ObservableCollection<InterpreterView>(InterpreterView.GetInterpreters(project.Site, interpreterService));
            var selection = Interpreters.FirstOrDefault(v => v.Interpreter == selectInterpreter);
            if (selection == null) {
                selection = Interpreters.FirstOrDefault(v => v.Interpreter == interpreterService.DefaultInterpreter)
                    ?? Interpreters.LastOrDefault();
            }
            BaseInterpreter = selection;

            _interpreterService.InterpretersChanged += OnInterpretersChanged;

            var venvName = "env";
            for (int i = 1; Directory.Exists(Path.Combine(_projectHome, venvName)); ++i) {
                venvName = "env" + i.ToString();
            }
            VirtualEnvName = venvName;

            CanInstallRequirementsTxt = File.Exists(CommonUtils.GetAbsoluteFilePath(_projectHome, "requirements.txt"));
            WillInstallRequirementsTxt = CanInstallRequirementsTxt;
        }
        internal void LoadSettings()
        {
            _service = _propPage.Project.Site.GetComponentModel().GetService <IInterpreterOptionsService>();

            StartupFile      = _propPage.Project.GetProjectProperty(CommonConstants.StartupFile, false);
            WorkingDirectory = _propPage.Project.GetProjectProperty(CommonConstants.WorkingDirectory, false);
            if (string.IsNullOrEmpty(WorkingDirectory))
            {
                WorkingDirectory = ".";
            }
            IsWindowsApplication = Convert.ToBoolean(_propPage.Project.GetProjectProperty(CommonConstants.IsWindowsApplication, false));
            OnInterpretersChanged();

            if (_propPage.PythonProject.Interpreters.IsActiveInterpreterGlobalDefault)
            {
                // ActiveInterpreter will never be null, so we need to check
                // the property to find out if it's following the global
                // default.
                SetDefaultInterpreter(null);
            }
            else
            {
                SetDefaultInterpreter(_propPage.PythonProject.Interpreters.ActiveInterpreter);
            }
        }
 public AddVirtualEnvironmentOperation(
     IServiceProvider site,
     PythonProjectNode project,
     string virtualEnvPath,
     string baseInterpreterId,
     bool useVEnv,
     bool installRequirements,
     string requirementsPath,
     bool registerAsCustomEnv,
     string customEnvName,
     bool setAsCurrent,
     bool setAsDefault,
     bool viewInEnvWindow,
     Redirector output = null
     )
 {
     _site                = site ?? throw new ArgumentNullException(nameof(site));
     _project             = project;
     _virtualEnvPath      = virtualEnvPath ?? throw new ArgumentNullException(nameof(virtualEnvPath));
     _baseInterpreter     = baseInterpreterId ?? throw new ArgumentNullException(nameof(baseInterpreterId));
     _useVEnv             = useVEnv;
     _installReqs         = installRequirements;
     _reqsPath            = requirementsPath;
     _registerAsCustomEnv = registerAsCustomEnv;
     _customEnvName       = customEnvName;
     _setAsCurrent        = setAsCurrent;
     _setAsDefault        = setAsDefault;
     _viewInEnvWindow     = viewInEnvWindow;
     _output              = output;
     _statusCenter        = _site.GetService(typeof(SVsTaskStatusCenterService)) as IVsTaskStatusCenterService;
     _registry            = _site.GetComponentModel().GetService <IInterpreterRegistryService>();
     _options             = _site.GetComponentModel().GetService <IInterpreterOptionsService>();
     _logger              = _site.GetService(typeof(IPythonToolsLogger)) as IPythonToolsLogger;
 }
        public PythonInterpreterOptionsControl(IServiceProvider serviceProvider) {
            _serviceProvider = serviceProvider;
            InitializeComponent();

            _service = serviceProvider.GetComponentModel().GetService<IInterpreterOptionsService>();
            UpdateInterpreters();
        }
Esempio n. 16
0
        protected override void OnCreate() {
            base.OnCreate();

            _site = (IServiceProvider)this;

            _pyService = _site.GetPythonToolsService();

#if DEV14_OR_LATER
            // TODO: Get PYEnvironment added to image list
            BitmapImageMoniker = KnownMonikers.DockPanel;
#else
            BitmapResourceID = PythonConstants.ResourceIdForReplImages;
            BitmapIndex = 0;
#endif
            Caption = SR.GetString(SR.Environments);

            _service = _site.GetComponentModel().GetService<IInterpreterOptionsService>();
            
            _outputWindow = OutputWindowRedirector.GetGeneral(_site);
            Debug.Assert(_outputWindow != null);
            _statusBar = _site.GetService(typeof(SVsStatusbar)) as IVsStatusbar;
            
            var list = new ToolWindow();
            list.ViewCreated += List_ViewCreated;

            list.CommandBindings.Add(new CommandBinding(
                EnvironmentView.OpenInteractiveWindow,
                OpenInteractiveWindow_Executed,
                OpenInteractiveWindow_CanExecute
            ));
            list.CommandBindings.Add(new CommandBinding(
                EnvironmentView.OpenInteractiveOptions,
                OpenInteractiveOptions_Executed,
                OpenInteractiveOptions_CanExecute
            ));
            list.CommandBindings.Add(new CommandBinding(
                EnvironmentPathsExtension.StartInterpreter,
                StartInterpreter_Executed,
                StartInterpreter_CanExecute
            ));
            list.CommandBindings.Add(new CommandBinding(
                EnvironmentPathsExtension.StartWindowsInterpreter,
                StartInterpreter_Executed,
                StartInterpreter_CanExecute
            ));
            list.CommandBindings.Add(new CommandBinding(
                ApplicationCommands.Help,
                OnlineHelp_Executed,
                OnlineHelp_CanExecute
            ));
            list.CommandBindings.Add(new CommandBinding(
                ToolWindow.UnhandledException,
                UnhandledException_Executed,
                UnhandledException_CanExecute
            ));

            list.Service = _service;

            Content = list;
        }
Esempio n. 17
0
        public PythonWorkspaceContext(
            IWorkspace workspace,
            IPropertyEvaluatorService workspacePropertyEvaluator,
            IInterpreterOptionsService optionsService,
            IInterpreterRegistryService registryService)
        {
            _workspace                = workspace ?? throw new ArgumentNullException(nameof(workspace));
            _optionsService           = optionsService ?? throw new ArgumentNullException(nameof(optionsService));
            _registryService          = registryService ?? throw new ArgumentNullException(nameof(registryService));
            _workspaceSettingsMgr     = _workspace.GetSettingsManager();
            _propertyEvaluatorService = workspacePropertyEvaluator;


            // Initialization in 2 phases (Constructor + Initialize) is needed to
            // break a circular dependency.
            // We create a partially initialized object that can be used by
            // WorkspaceInterpreterFactoryProvider to discover the interpreters
            // in this workspace (it needs the interpreter setting to do that).
            // Once that is done, the IPythonInterpreterFactory on this object
            // can be resolved in Initialize.
            _interpreter           = ReadInterpreterSetting();
            _searchPaths           = ReadSearchPathsSetting();
            _testFramework         = GetStringProperty(TestFrameworkProperty);
            _unitTestRootDirectory = GetStringProperty(UnitTestRootDirectoryProperty);
            _unitTestPattern       = GetStringProperty(UnitTestPatternProperty);
        }
Esempio n. 18
0
        public static EnvironmentView CreateCondaEnvironmentView(IInterpreterOptionsService service, IInterpreterRegistryService interpreters)
        {
            var ev = new EnvironmentView(CondaEnvironmentViewId, Resources.EnvironmentViewCreateNewCondaEnvironmentAutomationName, null);

            ev.Extensions = new ObservableCollection <object>();
            ev.Extensions.Add(new CondaExtensionProvider(service, interpreters));
            return(ev);
        }
Esempio n. 19
0
 private PythonInterpreterOptionsControl GetWindow() {
     if (_window == null) {
         _service = ComponentModel.GetService<IInterpreterOptionsService>();
         _service.InterpretersChanged += InterpretersChanged;
         _window = new PythonInterpreterOptionsControl(ComponentModel.GetService<SVsServiceProvider>());
     }
     return _window;
 }
Esempio n. 20
0
        private AddInterpreter(PythonProjectNode project, IInterpreterOptionsService service)
        {
            _view = new AddInterpreterView(project, project.Site, project.InterpreterFactories);
            _view.PropertyChanged += View_PropertyChanged;
            DataContext            = _view;

            InitializeComponent();
        }
 public PythonReplEvaluatorProvider(
     [Import] IInterpreterOptionsService interpreterService,
     [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider
 ) {
     Debug.Assert(interpreterService != null);
     _interpreterService = interpreterService;
     _serviceProvider = serviceProvider;
 }
Esempio n. 22
0
        public static EnvironmentView CreateAddNewEnvironmentView(IInterpreterOptionsService service)
        {
            var ev = new EnvironmentView(AddNewEnvironmentViewId, Resources.EnvironmentViewCustomAutomationName, null);

            ev.Extensions = new ObservableCollection <object>();
            ev.Extensions.Add(new ConfigurationExtensionProvider(service, alwaysCreateNew: true));
            return(ev);
        }
Esempio n. 23
0
 public PythonReplEvaluator(IPythonInterpreterFactory interpreter, IServiceProvider serviceProvider, PythonReplEvaluatorOptions options, IInterpreterOptionsService interpreterService = null)
     : base(serviceProvider, serviceProvider.GetPythonToolsService(), options) {
     _interpreter = interpreter;
     _interpreterService = interpreterService;
     if (_interpreterService != null) {
         _interpreterService.InterpretersChanged += InterpretersChanged;
     }
 }
Esempio n. 24
0
        public PythonInterpreterOptionsControl(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;
            InitializeComponent();

            _service = serviceProvider.GetComponentModel().GetService <IInterpreterOptionsService>();
            UpdateInterpreters();
        }
Esempio n. 25
0
        private static async Task<IPythonInterpreterFactory> TryGetCondaFactoryAsync(
            IPythonInterpreterFactory target,
            IInterpreterOptionsService service
        ) {
            var condaMetaPath = CommonUtils.GetAbsoluteDirectoryPath(
                target.Configuration.PrefixPath,
                "conda-meta"
            );

            if (!Directory.Exists(condaMetaPath)) {
                return null;
            }

            string metaFile;
            try {
                metaFile = Directory.EnumerateFiles(condaMetaPath, "*.json").FirstOrDefault();
            } catch (Exception ex) {
                if (ex.IsCriticalException()) {
                    throw;
                }
                return null;
            }

            if (!string.IsNullOrEmpty(metaFile)) {
                string text = string.Empty;
                try {
                    text = File.ReadAllText(metaFile);
                } catch (Exception ex) {
                    if (ex.IsCriticalException()) {
                        throw;
                    }
                }

                var m = Regex.Match(text, @"\{[^{]+link.+?\{.+?""source""\s*:\s*""(.+?)""", RegexOptions.Singleline);
                if (m.Success) {
                    var pkg = m.Groups[1].Value;
                    if (!Directory.Exists(pkg)) {
                        return null;
                    }

                    var prefix = Path.GetDirectoryName(Path.GetDirectoryName(pkg));
                    var factory = service.Interpreters.FirstOrDefault(
                        f => CommonUtils.IsSameDirectory(f.Configuration.PrefixPath, prefix)
                    );

                    if (factory != null && !(await factory.FindModulesAsync("conda")).Any()) {
                        factory = null;
                    }

                    return factory;
                }
            }

            if ((await target.FindModulesAsync("conda")).Any()) {
                return target;
            }
            return null;
        }
Esempio n. 26
0
        protected override void OnCreate()
        {
            base.OnCreate();

            _site = (IServiceProvider)this;

            _pyService = _site.GetPythonToolsService();

            // TODO: Get PYEnvironment added to image list
            BitmapImageMoniker = KnownMonikers.DockPanel;
            Caption            = Strings.Environments;

            _service = _site.GetComponentModel().GetService <IInterpreterOptionsService>();

            _outputWindow = OutputWindowRedirector.GetGeneral(_site);
            Debug.Assert(_outputWindow != null);
            _statusBar = _site.GetService(typeof(SVsStatusbar)) as IVsStatusbar;

            var list = new ToolWindow();

            list.Site         = _site;
            list.ViewCreated += List_ViewCreated;

            list.CommandBindings.Add(new CommandBinding(
                                         EnvironmentView.OpenInteractiveWindow,
                                         OpenInteractiveWindow_Executed,
                                         OpenInteractiveWindow_CanExecute
                                         ));
            list.CommandBindings.Add(new CommandBinding(
                                         EnvironmentView.OpenInteractiveOptions,
                                         OpenInteractiveOptions_Executed,
                                         OpenInteractiveOptions_CanExecute
                                         ));
            list.CommandBindings.Add(new CommandBinding(
                                         EnvironmentPathsExtension.StartInterpreter,
                                         StartInterpreter_Executed,
                                         StartInterpreter_CanExecute
                                         ));
            list.CommandBindings.Add(new CommandBinding(
                                         EnvironmentPathsExtension.StartWindowsInterpreter,
                                         StartInterpreter_Executed,
                                         StartInterpreter_CanExecute
                                         ));
            list.CommandBindings.Add(new CommandBinding(
                                         ApplicationCommands.Help,
                                         OnlineHelp_Executed,
                                         OnlineHelp_CanExecute
                                         ));
            list.CommandBindings.Add(new CommandBinding(
                                         ToolWindow.UnhandledException,
                                         UnhandledException_Executed,
                                         UnhandledException_CanExecute
                                         ));

            list.Service = _service;

            Content = list;
        }
Esempio n. 27
0
        public static EnvironmentView CreateAddNewEnvironmentView(IInterpreterOptionsService service)
        {
            var ev = new EnvironmentView();

            ev._addNewEnvironmentView = true;
            ev.Extensions             = new ObservableCollection <object>();
            ev.Extensions.Add(new ConfigurationExtensionProvider(service, alwaysCreateNew: true));
            return(ev);
        }
Esempio n. 28
0
 public EnvironmentSwitcherWorkspaceContext(IServiceProvider serviceProvider, IWorkspace workspace)
 {
     _serviceProvider      = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
     _optionsService       = serviceProvider.GetComponentModel().GetService <IInterpreterOptionsService>();
     _registryService      = serviceProvider.GetComponentModel().GetService <IInterpreterRegistryService>();
     _workspace            = workspace ?? throw new ArgumentNullException(nameof(workspace));
     _workspaceSettingsMgr = _workspace.GetSettingsManager();
     _workspaceSettingsMgr.OnWorkspaceSettingsChanged += OnSettingsChanged;
 }
Esempio n. 29
0
        internal EnvironmentView(
            IInterpreterOptionsService service,
            IInterpreterRegistryService registry,
            IPythonInterpreterFactory factory,
            Redirector redirector
            )
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }
            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            _service  = service;
            _registry = registry;
            Factory   = factory;

            _withDb = factory as IPythonInterpreterFactoryWithDatabase;
            if (_withDb != null)
            {
                _withDb.IsCurrentChanged += Factory_IsCurrentChanged;
                IsCheckingDatabase        = _withDb.IsCheckingDatabase;
                IsCurrent = _withDb.IsCurrent;
            }


            if (_service.IsConfigurable(factory.Configuration.Id))
            {
                IsConfigurable = true;
            }

            Description = Factory.Configuration.Description;
            IsDefault   = (_service != null && _service.DefaultInterpreter == Factory);

            PrefixPath             = Factory.Configuration.PrefixPath;
            InterpreterPath        = Factory.Configuration.InterpreterPath;
            WindowsInterpreterPath = Factory.Configuration.WindowsInterpreterPath;

            Extensions = new ObservableCollection <object>();
            Extensions.Add(new EnvironmentPathsExtensionProvider());
            if (IsConfigurable)
            {
                Extensions.Add(new ConfigurationExtensionProvider(_service));
            }

            CanBeDefault = Factory.CanBeDefault();

            Company    = _registry.GetProperty(Factory.Configuration.Id, CompanyKey) as string ?? "";
            SupportUrl = _registry.GetProperty(Factory.Configuration.Id, SupportUrlKey) as string ?? "";
        }
 public PythonReplEvaluatorProvider(
     [Import] IInterpreterOptionsService interpreterService,
     [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider
     )
 {
     Debug.Assert(interpreterService != null);
     _interpreterService = interpreterService;
     _serviceProvider    = serviceProvider;
 }
Esempio n. 31
0
 private PythonInterpreterOptionsControl GetWindow()
 {
     if (_window == null)
     {
         _service = ComponentModel.GetService <IInterpreterOptionsService>();
         _service.InterpretersChanged += InterpretersChanged;
         _window = new PythonInterpreterOptionsControl(ComponentModel.GetService <SVsServiceProvider>());
     }
     return(_window);
 }
 public PythonWorkspaceContext(
     IWorkspace workspace,
     IInterpreterOptionsService optionsService,
     IInterpreterRegistryService registryService)
 {
     _workspace            = workspace ?? throw new ArgumentNullException(nameof(workspace));
     _optionsService       = optionsService ?? throw new ArgumentNullException(nameof(optionsService));
     _registryService      = registryService ?? throw new ArgumentNullException(nameof(registryService));
     _workspaceSettingsMgr = _workspace.GetSettingsManager();
 }
Esempio n. 33
0
 public PythonReplEvaluator(IPythonInterpreterFactory interpreter, IServiceProvider serviceProvider, PythonReplEvaluatorOptions options, IInterpreterOptionsService interpreterService = null)
     : base(serviceProvider, serviceProvider.GetPythonToolsService(), options)
 {
     _interpreter        = interpreter;
     _interpreterService = interpreterService;
     if (_interpreterService != null)
     {
         _interpreterService.InterpretersChanged += InterpretersChanged;
     }
 }
Esempio n. 34
0
 private ServiceHolder(
     AssemblyCatalog catalog,
     CompositionContainer container,
     IInterpreterOptionsService service
     )
 {
     _catalog   = catalog;
     _container = container;
     _service   = service;
 }
 public EnvironmentSwitcherManager(IServiceProvider serviceProvider)
 {
     _serviceProvider  = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
     _optionsService   = serviceProvider.GetComponentModel().GetService <IInterpreterOptionsService>();
     _registryService  = serviceProvider.GetComponentModel().GetService <IInterpreterRegistryService>();
     _monitorSelection = serviceProvider.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection;
     _shell            = serviceProvider.GetService(typeof(SVsShell)) as IVsShell;
     _workspaceService = serviceProvider.GetComponentModel().GetService <IVsFolderWorkspaceService>();
     AllFactories      = Enumerable.Empty <IPythonInterpreterFactory>();
 }
Esempio n. 36
0
 public static IEnumerable<IPythonInterpreterFactory> ShowDialog(
     PythonProjectNode project,
     IInterpreterOptionsService service) {
     using (var wnd = new AddInterpreter(project, service)) {
         if (wnd.ShowModal() ?? false) {
             return wnd._view.Interpreters.Where(iv => iv.IsSelected).Select(iv => iv.Interpreter);
         }
     }
     return null;
 }
Esempio n. 37
0
        internal PythonToolsService(IServiceContainer container)
        {
            _container = container;

            var langService = new PythonLanguageInfo(container);

            _container.AddService(langService.GetType(), langService, true);

            IVsTextManager textMgr = (IVsTextManager)container.GetService(typeof(SVsTextManager));

            if (textMgr != null)
            {
                var langPrefs = new LANGPREFERENCES[1];
                langPrefs[0].guidLang = typeof(PythonLanguageInfo).GUID;
                ErrorHandler.ThrowOnFailure(textMgr.GetUserPreferences(null, null, langPrefs, null));
                _langPrefs = new LanguagePreferences(this, langPrefs[0]);

                Guid             guid = typeof(IVsTextManagerEvents2).GUID;
                IConnectionPoint connectionPoint;
                ((IConnectionPointContainer)textMgr).FindConnectionPoint(ref guid, out connectionPoint);
                connectionPoint.Advise(_langPrefs, out _langPrefsTextManagerCookie);
            }

            _optionsService = (IPythonToolsOptionsService)container.GetService(typeof(IPythonToolsOptionsService));
            var compModel = (IComponentModel)container.GetService(typeof(SComponentModel));

            _interpreterRegistry = compModel.GetService <IInterpreterRegistryService>();
            if (_interpreterRegistry != null)
            {
                _interpreterRegistry.InterpretersChanged += InterpretersChanged;
            }

            _interpreterOptionsService = compModel.GetService <IInterpreterOptionsService>();
            if (_interpreterOptionsService != null)     // not available in some test cases...
            {
                _interpreterOptionsService.DefaultInterpreterChanged += UpdateDefaultAnalyzer;
                LoadInterpreterOptions();
            }

            _idleManager              = new IdleManager(container);
            _advancedOptions          = new AdvancedEditorOptions(this);
            _debuggerOptions          = new DebuggerOptions(this);
            _generalOptions           = new GeneralOptions(this);
            _surveyNews               = new SurveyNewsService(container);
            _suppressDialogOptions    = new SuppressDialogOptions(this);
            _globalInterpreterOptions = new GlobalInterpreterOptions(this, _interpreterOptionsService, _interpreterRegistry);
            _globalInterpreterOptions.Load();
            _interactiveOptions = new PythonInteractiveOptions(this, "Interactive");
            _interactiveOptions.Load();
            _debugInteractiveOptions = new PythonInteractiveOptions(this, "Debug Interactive Window");
            _debuggerOptions.Load();
            _factoryProviders = ComponentModel.DefaultExportProvider.GetExports <IPythonInterpreterFactoryProvider, Dictionary <string, object> >();
            _logger           = new PythonToolsLogger(ComponentModel.GetExtensions <IPythonToolsLogger>().ToArray());
            InitializeLogging();
        }
Esempio n. 38
0
        internal EnvironmentView(
            IInterpreterOptionsService service,
            IInterpreterRegistryService registry,
            IPythonInterpreterFactory factory,
            Redirector redirector
        ) {
            if (service == null) {
                throw new ArgumentNullException(nameof(service));
            }
            if (registry == null) {
                throw new ArgumentNullException(nameof(registry));
            }
            if (factory == null) {
                throw new ArgumentNullException(nameof(factory));
            }
            if (factory.Configuration == null) {
                throw new ArgumentException("factory must include a configuration");
            }

            _service = service;
            _registry = registry;
            Factory = factory;
            Configuration = Factory.Configuration;

            _withDb = factory as IPythonInterpreterFactoryWithDatabase;
            if (_withDb != null) {
                _withDb.IsCurrentChanged += Factory_IsCurrentChanged;
                IsCheckingDatabase = _withDb.IsCheckingDatabase;
                IsCurrent = _withDb.IsCurrent;
            }
            

            if (_service.IsConfigurable(Factory.Configuration.Id)) {
                IsConfigurable = true;
            }

            Description = Factory.Configuration.Description;
            IsDefault = (_service != null && _service.DefaultInterpreterId == Configuration.Id);

            PrefixPath = Factory.Configuration.PrefixPath;
            InterpreterPath = Factory.Configuration.InterpreterPath;
            WindowsInterpreterPath = Factory.Configuration.WindowsInterpreterPath;

            Extensions = new ObservableCollection<object>();
            Extensions.Add(new EnvironmentPathsExtensionProvider());
            if (IsConfigurable) {
                Extensions.Add(new ConfigurationExtensionProvider(_service, alwaysCreateNew: false));
            }

            CanBeDefault = Factory.CanBeDefault();

            Company = _registry.GetProperty(Factory.Configuration.Id, CompanyKey) as string ?? "";
            SupportUrl = _registry.GetProperty(Factory.Configuration.Id, SupportUrlKey) as string ?? "";
        }
Esempio n. 39
0
        internal EnvironmentView(
            IInterpreterOptionsService service,
            IPythonInterpreterFactory factory,
            Redirector redirector
            )
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            _service = service;
            Factory  = factory;

            _withDb = factory as IPythonInterpreterFactoryWithDatabase;
            if (_withDb != null)
            {
                _withDb.IsCurrentChanged += Factory_IsCurrentChanged;
                IsCheckingDatabase        = _withDb.IsCheckingDatabase;
                IsCurrent = _withDb.IsCurrent;
            }

            var configurableProvider = _service != null?
                                       _service.KnownProviders
                                       .OfType <ConfigurablePythonInterpreterFactoryProvider>()
                                       .FirstOrDefault() :
                                           null;

            if (configurableProvider != null && configurableProvider.IsConfigurable(factory))
            {
                IsConfigurable = true;
            }

            Description = Factory.Description;
            IsDefault   = (_service != null && _service.DefaultInterpreter == Factory);

            PrefixPath             = Factory.Configuration.PrefixPath;
            InterpreterPath        = Factory.Configuration.InterpreterPath;
            WindowsInterpreterPath = Factory.Configuration.WindowsInterpreterPath;
            LibraryPath            = Factory.Configuration.LibraryPath;

            Extensions = new ObservableCollection <object>();
            Extensions.Add(new EnvironmentPathsExtensionProvider());
            if (IsConfigurable)
            {
                Extensions.Add(new ConfigurationExtensionProvider(configurableProvider));
            }

            CanBeDefault = Factory.CanBeDefault();
        }
Esempio n. 40
0
 public static IEnumerable <IPythonInterpreterFactory> ShowDialog(
     PythonProjectNode project,
     IInterpreterOptionsService service)
 {
     using (var wnd = new AddInterpreter(project, service)) {
         if (wnd.ShowModal() ?? false)
         {
             return(wnd._view.Interpreters.Where(iv => iv.IsSelected).Select(iv => iv.Interpreter));
         }
     }
     return(null);
 }
Esempio n. 41
0
        public void InitializeEnvironments(IInterpreterRegistryService interpreters, IInterpreterOptionsService options, bool synchronous = false)
        {
            if (_interpreters != null)
            {
                _interpreters.InterpretersChanged -= Service_InterpretersChanged;
            }
            _interpreters = interpreters;
            if (_interpreters != null)
            {
                _interpreters.InterpretersChanged += Service_InterpretersChanged;
            }

            if (_options != null)
            {
                _options.DefaultInterpreterChanged -= Service_DefaultInterpreterChanged;
            }
            _options = options;
            if (_options != null)
            {
                _options.DefaultInterpreterChanged += Service_DefaultInterpreterChanged;
            }

            if (_interpreters != null && _options != null)
            {
                _addNewEnvironmentView = EnvironmentView.CreateAddNewEnvironmentView(_options);
                if (ExperimentalOptions.AutoDetectCondaEnvironments)
                {
                    _condaEnvironmentView = EnvironmentView.CreateCondaEnvironmentView(_options, _interpreters);
                    var provider = _condaEnvironmentView.Extensions.FirstOrDefault() as CondaExtensionProvider;
                    OnProviderCreated(provider);
                }
                else
                {
                    _condaEnvironmentView = null;
                }
                _onlineHelpView = EnvironmentView.CreateOnlineHelpEnvironmentView();

                if (synchronous)
                {
                    Dispatcher.Invoke(FirstUpdateEnvironments);
                }
                else
                {
                    Dispatcher.InvokeAsync(FirstUpdateEnvironments).Task.DoNotWait();
                }
            }
            else
            {
                _addNewEnvironmentView = null;
                _condaEnvironmentView  = null;
                _onlineHelpView        = null;
            }
        }
Esempio n. 42
0
 public static InstallPythonPackageView ShowDialog(
     IServiceProvider serviceProvider,
     IPythonInterpreterFactory factory,
     IInterpreterOptionsService service
 ) {
     var wnd = new InstallPythonPackage(serviceProvider, factory, service);
     if (wnd.ShowModal() ?? false) {
         return wnd._view;
     } else {
         return null;
     }
 }
Esempio n. 43
0
        private InstallPythonPackage(
            IServiceProvider serviceProvider,
            IPythonInterpreterFactory factory,
            IInterpreterOptionsService service
        ) {
            _view = new InstallPythonPackageView(
                serviceProvider,
                !Pip.IsSecureInstall(factory),
                Conda.CanInstall(factory, service)
            );
            DataContext = _view;

            InitializeComponent();
            _textBox.Focus();
        }
Esempio n. 44
0
        internal EnvironmentView(
            IInterpreterOptionsService service,
            IPythonInterpreterFactory factory,
            Redirector redirector
        ) {
            if (service == null) {
                throw new ArgumentNullException("service");
            }
            if (factory == null) {
                throw new ArgumentNullException("factory");
            }

            _service = service;
            Factory = factory;

            _withDb = factory as IPythonInterpreterFactoryWithDatabase;
            if (_withDb != null) {
                _withDb.IsCurrentChanged += Factory_IsCurrentChanged;
                IsCheckingDatabase = _withDb.IsCheckingDatabase;
                IsCurrent = _withDb.IsCurrent;
            }

            var configurableProvider = _service != null ?
                _service.KnownProviders
                    .OfType<ConfigurablePythonInterpreterFactoryProvider>()
                    .FirstOrDefault() :
                null;

            if (configurableProvider != null && configurableProvider.IsConfigurable(factory)) {
                IsConfigurable = true;
            }

            Description = Factory.Description;
            IsDefault = (_service != null && _service.DefaultInterpreter == Factory);

            PrefixPath = Factory.Configuration.PrefixPath;
            InterpreterPath = Factory.Configuration.InterpreterPath;
            WindowsInterpreterPath = Factory.Configuration.WindowsInterpreterPath;
            LibraryPath = Factory.Configuration.LibraryPath;

            Extensions = new ObservableCollection<object>();
            Extensions.Add(new EnvironmentPathsExtensionProvider());
            if (IsConfigurable) {
                Extensions.Add(new ConfigurationExtensionProvider(configurableProvider));
            }

            CanBeDefault = Factory.CanBeDefault();
        }
        /// <summary>
        /// Creates a new provider for the specified project and service.
        /// </summary>
        public MSBuildProjectInterpreterFactoryProvider(IInterpreterOptionsService service, MSBuild.Project project) {
            if (service == null) {
                throw new ArgumentNullException("service");
            }
            if (project == null) {
                throw new ArgumentNullException("project");
            }

            _rootPaths = new Dictionary<Guid, string>();
            _service = service;
            _project = project;

            // _active starts as null, so we need to start with this event
            // hooked up.
            _service.DefaultInterpreterChanged += GlobalDefaultInterpreterChanged;
        }
Esempio n. 46
0
 public static IPythonReplEvaluator Create(
     IServiceProvider serviceProvider,
     string id,
     string version,
     IInterpreterOptionsService interpreterService
 ) {
     var factory = interpreterService != null ? interpreterService.FindInterpreter(id, version) : null;
     if (factory == null) {
         try {
             factory = new UnavailableFactory(id, version);
         } catch (FormatException) {
             return null;
         }
     }
     return new PythonReplEvaluator(factory, serviceProvider, interpreterService);
 }
Esempio n. 47
0
        public InterpretersNode(
            PythonProjectNode project,
            ProjectItem item,
            IPythonInterpreterFactory factory,
            bool isInterpreterReference,
            bool canDelete,
            bool isGlobalDefault = false
        )
            : base(project, ChooseElement(project, item)) {
            ExcludeNodeFromScc = true;

            _interpreters = project.Interpreters;
            _interpreterService = project.Site.GetComponentModel().GetService<IInterpreterOptionsService>();
            _factory = factory;
            _isReference = isInterpreterReference;
            _canDelete = canDelete;
            _isGlobalDefault = isGlobalDefault;
            _canRemove = !isGlobalDefault;
            _captionSuffix = isGlobalDefault ? SR.GetString(SR.GlobalDefaultSuffix) : "";

            if (Directory.Exists(_factory.Configuration.LibraryPath)) {
                // TODO: Need to handle watching for creation
                try {
                    _fileWatcher = new FileSystemWatcher(_factory.Configuration.LibraryPath);
                } catch (ArgumentException) {
                    // Path was not actually valid, despite Directory.Exists
                    // returning true.
                }
                if (_fileWatcher != null) {
                    try {
                        _fileWatcher.IncludeSubdirectories = true;
                        _fileWatcher.Deleted += PackagesChanged;
                        _fileWatcher.Created += PackagesChanged;
                        _fileWatcher.EnableRaisingEvents = true;
                        // Only create the timer if the file watcher is running.
                        _timer = new Timer(CheckPackages);
                    } catch (IOException) {
                        // Raced with directory deletion
                        _fileWatcher.Dispose();
                        _fileWatcher = null;
                    }
                }
            }
        }
Esempio n. 48
0
        public ImportSettings(IInterpreterOptionsService service) {
            _service = service;

            if (_service != null) {
                AvailableInterpreters = new ObservableCollection<PythonInterpreterView>(
                    Enumerable.Repeat(_defaultInterpreter, 1)
                    .Concat(_service.Interpreters.Select(fact => new PythonInterpreterView(fact)))
                );
            } else {
                AvailableInterpreters = new ObservableCollection<PythonInterpreterView>();
                AvailableInterpreters.Add(_defaultInterpreter);
            }

            SelectedInterpreter = AvailableInterpreters[0];
            TopLevelPythonFiles = new BulkObservableCollection<string>();
            Customization = _projectCustomizations.First();

            Filters = "*.pyw;*.txt;*.htm;*.html;*.css;*.djt;*.js;*.ini;*.png;*.jpg;*.gif;*.bmp;*.ico;*.svg";
        }
        internal void LoadSettings() {
            _service = _propPage.Project.Site.GetComponentModel().GetService<IInterpreterOptionsService>();

            StartupFile = _propPage.Project.GetProjectProperty(CommonConstants.StartupFile, false);
            WorkingDirectory = _propPage.Project.GetProjectProperty(CommonConstants.WorkingDirectory, false);
            if (string.IsNullOrEmpty(WorkingDirectory)) {
                WorkingDirectory = ".";
            }
            IsWindowsApplication = Convert.ToBoolean(_propPage.Project.GetProjectProperty(CommonConstants.IsWindowsApplication, false));
            OnInterpretersChanged();

            if (_propPage.PythonProject.Interpreters.IsActiveInterpreterGlobalDefault) {
                // ActiveInterpreter will never be null, so we need to check
                // the property to find out if it's following the global
                // default.
                SetDefaultInterpreter(null);
            } else {
                SetDefaultInterpreter(_propPage.PythonProject.Interpreters.ActiveInterpreter);
            }

        }
Esempio n. 50
0
        public static async Task ShowDialog(
            PythonProjectNode project,
            IInterpreterOptionsService service,
            bool browseForExisting = false
        ) {
            using (var view = new AddVirtualEnvironmentView(project, service, project.Interpreters.ActiveInterpreter)) {
                var wnd = new AddVirtualEnvironment(view);

                if (browseForExisting) {
                    var path = project.Site.BrowseForDirectory(IntPtr.Zero, project.ProjectHome);
                    if (string.IsNullOrEmpty(path)) {
                        throw new OperationCanceledException();
                    }
                    view.VirtualEnvName = path;
                    view.WillInstallRequirementsTxt = false;
                    await view.WaitForReady();
                    if (view.WillAddVirtualEnv) {
                        await view.Create().HandleAllExceptions(SR.ProductName, typeof(AddVirtualEnvironment));
                        return;
                    }

                    view.ShowBrowsePathError = true;
                    view.BrowseOrigPrefix = DerivedInterpreterFactory.GetOrigPrefixPath(path);
                }

                wnd.VirtualEnvPathTextBox.ScrollToEnd();
                wnd.VirtualEnvPathTextBox.SelectAll();
                wnd.VirtualEnvPathTextBox.Focus();

                wnd.ShowModal();
                var op = wnd._currentOperation;
                if (op != null) {
                    await op;
                }
            }
        }
Esempio n. 51
0
        public static IPythonInterpreterFactory FindBaseInterpreterFromVirtualEnv(
            string prefixPath,
            string libPath,
            IInterpreterOptionsService service
        ) {
            string basePath = GetOrigPrefixPath(prefixPath, libPath);

            if (Directory.Exists(basePath)) {
                return service.Interpreters.FirstOrDefault(interp =>
                    PathUtils.IsSamePath(interp.Configuration.PrefixPath, basePath)
                );
            }
            return null;
        }
Esempio n. 52
0
        internal static void WriteProjectXml(
            IInterpreterOptionsService service,
            TextWriter writer,
            string projectPath,
            string sourcePath,
            string filters,
            string searchPaths,
            string startupFile,
            PythonInterpreterView selectedInterpreter,
            ProjectCustomization customization,
            bool detectVirtualEnv
        ) {
            var projectHome = CommonUtils.GetRelativeDirectoryPath(Path.GetDirectoryName(projectPath), sourcePath);

            var project = ProjectRootElement.Create();

            project.DefaultTargets = "Build";
            project.ToolsVersion = "4.0";

            var globals = project.AddPropertyGroup();
            globals.AddProperty("Configuration", "Debug").Condition = " '$(Configuration)' == '' ";
            globals.AddProperty("SchemaVersion", "2.0");
            globals.AddProperty("ProjectGuid", Guid.NewGuid().ToString("B"));
            globals.AddProperty("ProjectHome", projectHome);
            if (CommonUtils.IsValidPath(startupFile)) {
                globals.AddProperty("StartupFile", startupFile);
            } else {
                globals.AddProperty("StartupFile", "");
            }
            globals.AddProperty("SearchPath", searchPaths);
            globals.AddProperty("WorkingDirectory", ".");
            globals.AddProperty("OutputPath", ".");

            globals.AddProperty("ProjectTypeGuids", "{888888a0-9f3d-457c-b088-3a5042f75d52}");
            globals.AddProperty("LaunchProvider", DefaultLauncherProvider.DefaultLauncherName);

            var interpreterId = globals.AddProperty(PythonConstants.InterpreterId, "");
            var interpreterVersion = globals.AddProperty(PythonConstants.InterpreterVersion, "");

            if (selectedInterpreter != null && selectedInterpreter.Id != Guid.Empty) {
                interpreterId.Value = selectedInterpreter.Id.ToString("B");
                interpreterVersion.Value = selectedInterpreter.Version.ToString();
            }

            // VS requires property groups with conditions for Debug
            // and Release configurations or many COMExceptions are
            // thrown.
            var debugGroup = project.AddPropertyGroup();
            var releaseGroup = project.AddPropertyGroup();
            debugGroup.Condition = "'$(Configuration)' == 'Debug'";
            releaseGroup.Condition = "'$(Configuration)' == 'Release'";


            var folders = new HashSet<string>();
            var virtualEnvPaths = detectVirtualEnv ? new List<string>() : null;

            foreach (var unescapedFile in EnumerateAllFiles(sourcePath, filters, virtualEnvPaths)) {
                var file = ProjectCollection.Escape(unescapedFile);
                var ext = Path.GetExtension(file);
                var fileType = "Content";
                if (PythonConstants.FileExtension.Equals(ext, StringComparison.OrdinalIgnoreCase) ||
                    PythonConstants.WindowsFileExtension.Equals(ext, StringComparison.OrdinalIgnoreCase)) {
                    fileType = "Compile";
                }
                folders.Add(Path.GetDirectoryName(file));
                
                project.AddItem(fileType, file);
            }

            foreach (var folder in folders.Where(s => !string.IsNullOrWhiteSpace(s)).OrderBy(s => s)) {
                project.AddItem("Folder", folder);
            }

            if (selectedInterpreter != null && selectedInterpreter.Id != Guid.Empty) {
                project.AddItem(
                    MSBuildProjectInterpreterFactoryProvider.InterpreterReferenceItem,
                    string.Format("{0:B}\\{1}", selectedInterpreter.Id, selectedInterpreter.Version)
                );
            }
            if (virtualEnvPaths != null && virtualEnvPaths.Any() && service != null) {
                foreach (var options in virtualEnvPaths.Select(p => VirtualEnv.FindInterpreterOptions(p, service))) {
                    AddVirtualEnvironment(project, sourcePath, options);

                    if (string.IsNullOrEmpty(interpreterId.Value)) {
                        interpreterId.Value = options.IdString;
                        interpreterVersion.Value = options.LanguageVersionString;
                    }
                }
            }

            var imports = project.AddPropertyGroup();
            imports.AddProperty("VisualStudioVersion", "10.0").Condition = " '$(VisualStudioVersion)' == '' ";

            (customization ?? DefaultProjectCustomization.Instance).Process(
                project,
                new Dictionary<string, ProjectPropertyGroupElement> {
                    { "Globals", globals },
                    { "Imports", imports },
                    { "Debug", debugGroup },
                    { "Release", releaseGroup }
                }
            );

            project.Save(writer);
        }
 internal ConfigurationExtensionProvider(IInterpreterOptionsService interpreterOptions) {
     _interpreterOptions = interpreterOptions;
 }
Esempio n. 54
0
 public static EnvironmentView CreateAddNewEnvironmentView(IInterpreterOptionsService service) {
     var ev = new EnvironmentView(AddNewEnvironmentViewId);
     ev.Extensions = new ObservableCollection<object>();
     ev.Extensions.Add(new ConfigurationExtensionProvider(service, alwaysCreateNew: true));
     return ev;
 }
Esempio n. 55
0
 public TestExecutor() {
     _app = VisualStudioApp.FromEnvironmentVariable(PythonConstants.PythonToolsProcessIdEnvironmentVariable);
     _interpreterService = InterpreterOptionsServiceProvider.GetService(_app);
 }
Esempio n. 56
0
        public static bool CanInstall(
            IPythonInterpreterFactory factory,
            IInterpreterOptionsService service
        ) {
            if (!factory.IsRunnable()) {
                return false;
            }

            return TryGetCondaFactoryAsync(factory, service).WaitAndUnwrapExceptions() != null;
        }
Esempio n. 57
0
        public static async Task<bool> Install(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            IInterpreterOptionsService service,
            string package,
            Redirector output = null
        ) {
            factory.ThrowIfNotRunnable("factory");

            var condaFactory = await TryGetCondaFactoryAsync(factory, service); ;
            if (condaFactory == null) {
                throw new InvalidOperationException("Cannot find conda");
            }
            condaFactory.ThrowIfNotRunnable();

            if (output != null) {
                output.WriteLine(SR.GetString(SR.PackageInstalling, package));
                if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForPackageInstallation) {
                    output.ShowAndActivate();
                } else {
                    output.Show();
                }
            }

            using (var proc = ProcessOutput.Run(
                condaFactory.Configuration.InterpreterPath,
                new[] { "-m", "conda", "install", "--yes", "-n", factory.Configuration.PrefixPath, package },
                factory.Configuration.PrefixPath,
                UnbufferedEnv,
                false,
                output
            )) {
                var exitCode = await proc;
                if (output != null) {
                    if (exitCode == 0) {
                        output.WriteLine(SR.GetString(SR.PackageInstallSucceeded, package));
                    } else {
                        output.WriteLine(SR.GetString(SR.PackageInstallFailedExitCode, package, exitCode));
                    }
                    if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForPackageInstallation) {
                        output.ShowAndActivate();
                    } else {
                        output.Show();
                    }
                }
                return exitCode == 0;
            }
        }
Esempio n. 58
0
 internal TestDiscoverer(VisualStudioApp app, IInterpreterOptionsService interpreterService) {
     _app = app;
     _interpreterService = interpreterService;
 }
Esempio n. 59
0
        private AddInterpreter(PythonProjectNode project, IInterpreterOptionsService service) {
            _view = new AddInterpreterView(project, project.Site, project.InterpreterIds);
            DataContext = _view;

            InitializeComponent();
        }
Esempio n. 60
0
        public static InterpreterFactoryCreationOptions FindInterpreterOptions(
            string prefixPath,
            IInterpreterOptionsService service,
            IPythonInterpreterFactory baseInterpreter = null
        ) {
            var result = new InterpreterFactoryCreationOptions();

            var libPath = DerivedInterpreterFactory.FindLibPath(prefixPath);

            result.PrefixPath = prefixPath;
            result.LibraryPath = libPath;

            if (baseInterpreter == null) {
                baseInterpreter = DerivedInterpreterFactory.FindBaseInterpreterFromVirtualEnv(
                    prefixPath,
                    libPath,
                    service
                );
            }

            string interpExe, winterpExe;

            if (baseInterpreter != null) {
                // The interpreter name should be the same as the base interpreter.
                interpExe = Path.GetFileName(baseInterpreter.Configuration.InterpreterPath);
                winterpExe = Path.GetFileName(baseInterpreter.Configuration.WindowsInterpreterPath);
                var scripts = new[] { "Scripts", "bin" };
                result.InterpreterPath = CommonUtils.FindFile(prefixPath, interpExe, firstCheck: scripts);
                result.WindowInterpreterPath = CommonUtils.FindFile(prefixPath, winterpExe, firstCheck: scripts);
                result.PathEnvironmentVariableName = baseInterpreter.Configuration.PathEnvironmentVariable;
            } else {
                result.InterpreterPath = string.Empty;
                result.WindowInterpreterPath = string.Empty;
                result.PathEnvironmentVariableName = string.Empty;
            }

            if (baseInterpreter != null) {
                result.Description = string.Format(
                    "{0} ({1})",
                    CommonUtils.GetFileOrDirectoryName(prefixPath),
                    baseInterpreter.Description
                );

                result.Id = baseInterpreter.Id;
                result.LanguageVersion = baseInterpreter.Configuration.Version;
                result.Architecture = baseInterpreter.Configuration.Architecture;
                result.WatchLibraryForNewModules = true;
            } else {
                result.Description = CommonUtils.GetFileOrDirectoryName(prefixPath);

                result.Id = Guid.Empty;
                result.LanguageVersion = new Version(0, 0);
                result.Architecture = ProcessorArchitecture.None;
                result.WatchLibraryForNewModules = false;
            }

            return result;
        }