예제 #1
0
        private async Task UpdateSearchPathPackagesAsync(CancellationToken cancellationToken)
        {
            var packageDict = new Dictionary <string, string>();

            foreach (var searchPath in _searchPaths.MaybeEnumerate())
            {
                cancellationToken.ThrowIfCancellationRequested();

                IReadOnlyCollection <string> packages = null;
                if (File.Exists(searchPath))
                {
                    packages = await GetPackagesFromZipFileAsync(searchPath, cancellationToken);
                }
                else if (Directory.Exists(searchPath))
                {
                    packages = await GetPackagesFromDirectoryAsync(searchPath, cancellationToken);
                }
                foreach (var package in packages.MaybeEnumerate())
                {
                    packageDict[package] = searchPath;
                }
            }

            cancellationToken.ThrowIfCancellationRequested();
            Interlocked.Exchange(ref _searchPathPackages, packageDict);
            ModuleNamesChanged?.Invoke(this, EventArgs.Empty);
        }
예제 #2
0
 private void PythonAnalyzer_SearchPathsChanged(object sender, EventArgs e)
 {
     _searchPaths     = _state.GetSearchPaths();
     _searchPathDb    = null;
     _zipPackageCache = null;
     ModuleNamesChanged?.Invoke(this, EventArgs.Empty);
 }
예제 #3
0
        private void Factory_ImportableModulesChanged(object sender, EventArgs e)
        {
            _modules.Clear();
#if USE_TYPESHED
            lock (_typeShedPathsLock) {
                _typeShedPaths = null;
            }
#endif
            ModuleNamesChanged?.Invoke(this, EventArgs.Empty);
        }
 private void Factory_ImportableModulesChanged(object sender, EventArgs e)
 {
     _modules.Clear();
     if (_builtinModule != null)
     {
         _modules[BuiltinModuleName] = _builtinModule;
     }
     ModuleCache.Clear();
     ModuleNamesChanged?.Invoke(this, EventArgs.Empty);
 }
예제 #5
0
 /// <summary>
 /// Removes a module. If <c>retainName</c> is true, keeps returning
 /// the module name from <see cref="GetModuleNames"/>.
 /// </summary>
 public void RemoveModule(string name, bool retainName = false)
 {
     if (retainName)
     {
         _moduleNames.Add(name);
     }
     if (_modules.Remove(name))
     {
         ModuleNamesChanged?.Invoke(this, EventArgs.Empty);
     }
 }
예제 #6
0
 private void Analyzer_SearchPathsChanged(object sender, EventArgs e)
 {
     lock (_userSearchPathsLock) {
         // Remove imported modules from search paths so we will import them again.
         foreach (var name in _userSearchPathImported.MaybeEnumerate().ToArray())
         {
             _modules.TryRemove(name, out var mod);
         }
         _userSearchPathImported = null;
         _userSearchPathPackages = null;
         _userSearchPaths        = _analyzer.GetSearchPaths();
     }
     ModuleNamesChanged?.Invoke(this, EventArgs.Empty);
 }
        private void Analyzer_SearchPathsChanged(object sender, EventArgs e)
        {
            var moduleNames = _analyzer.CurrentPathResolver.GetInterpreterModuleNames().Append(BuiltinModuleName);

            lock (_userSearchPathsLock) {
                // Remove imported modules from search paths so we will import them again.
                var modulesNamesToRemove = _modules.Keys.Except(moduleNames).ToList();
                foreach (var moduleName in modulesNamesToRemove)
                {
                    _modules.TryRemove(moduleName, out _);
                }
            }
            ModuleNamesChanged?.Invoke(this, EventArgs.Empty);
        }
예제 #8
0
        private async void OnNewDatabaseAvailable(object sender, EventArgs e)
        {
            var factory = _factory;

            if (factory == null)
            {
                // We have been disposed already, so ignore this event
                return;
            }

            _typeDb          = factory.GetCurrentDatabase();
            _searchPathDb    = null;
            _zipPackageCache = null;

            ModuleNamesChanged?.Invoke(this, EventArgs.Empty);
        }
예제 #9
0
 internal void RaiseModuleNamesChanged()
 {
     ModuleNamesChanged?.Invoke(this, EventArgs.Empty);
 }
예제 #10
0
 private void Factory_ImportableModulesChanged(object sender, EventArgs e)
 {
     _modules.Clear();
     ModuleNamesChanged?.Invoke(this, EventArgs.Empty);
 }
예제 #11
0
 public void AddModule(string name, IPythonModule module)
 {
     _modules[name] = module;
     ModuleNamesChanged?.Invoke(this, EventArgs.Empty);
 }