示例#1
0
        /// <summary>
        /// Locates database file based on module information. Module is identified
        /// by name, version, current Python interpreter version and/or hash of the
        /// module content (typically file sizes).
        /// </summary>
        private string FindDatabaseFile(string moduleName, string filePath)
        {
            var interpreter = _services.GetService <IPythonInterpreter>();
            var uniqueId    = ModuleUniqueId.GetUniqueId(moduleName, filePath, ModuleType.Specialized, _services, GetCachingLevel());

            if (string.IsNullOrEmpty(uniqueId))
            {
                return(null);
            }

            // Try module name as is.
            var dbPath = Path.Combine(_databaseFolder, $"{uniqueId}.db");

            if (_fs.FileExists(dbPath))
            {
                return(dbPath);
            }

            // TODO: resolving to a different version can be an option
            // Try with the major.minor Python version.
            var pythonVersion = interpreter.Configuration.Version;

            dbPath = Path.Combine(_databaseFolder, $"{uniqueId}({pythonVersion.Major}.{pythonVersion.Minor}).db");
            if (_fs.FileExists(dbPath))
            {
                return(dbPath);
            }

            // Try with just the major Python version.
            dbPath = Path.Combine(_databaseFolder, $"{uniqueId}({pythonVersion.Major}).db");
            return(_fs.FileExists(dbPath) ? dbPath : null);
        }
        /// <summary>
        /// Locates database file based on module information. Module is identified
        /// by name, version, current Python interpreter version and/or hash of the
        /// module content (typically file sizes).
        /// </summary>
        private string FindDatabaseFile(string moduleName, string filePath, ModuleType moduleType)
        {
            var uniqueId = ModuleUniqueId.GetUniqueId(moduleName, filePath, moduleType, _services, GetCachingLevel());

            return(string.IsNullOrEmpty(uniqueId) ? null : FindDatabaseFile(uniqueId));
        }