private async Task <IPythonModule> ImportFromTypeStubsAsync(string name, TryImportModuleContext context, CancellationToken cancellationToken) { var mp = FindModuleInSearchPath(context.TypeStubPaths, null, name); if (mp == null) { int i = name.IndexOf('.'); if (i == 0) { Debug.Fail("Invalid module name"); return(null); } var stubName = i < 0 ? (name + "-stubs") : (name.Remove(i)) + "-stubs" + name.Substring(i); ModulePath?stubMp = null; if (context.FindModuleInUserSearchPathAsync != null) { try { stubMp = await context.FindModuleInUserSearchPathAsync(stubName, cancellationToken); } catch (Exception ex) { _log?.Log(TraceLevel.Error, "Exception", ex.ToString()); _log?.Flush(); return(null); } } if (stubMp == null) { stubMp = await FindModuleInSearchPathAsync(stubName, cancellationToken); } if (stubMp != null) { mp = new ModulePath(name, stubMp?.SourceFile, stubMp?.LibraryPath); } } if (mp == null && context.TypeStubPaths != null && context.TypeStubPaths.Count > 0) { mp = FindModuleInSearchPath(context.TypeStubPaths.SelectMany(GetTypeShedPaths).ToArray(), null, name); } if (mp == null) { return(null); } if (mp.Value.IsCompiled) { Debug.Fail("Unsupported native module in typeshed"); return(null); } _log?.Log(TraceLevel.Verbose, "ImportTypeStub", mp?.FullName, mp?.SourceFile); return(PythonModuleLoader.FromTypeStub(context.Interpreter, mp?.SourceFile, _configuration.Version.ToLanguageVersion(), mp?.FullName)); }
protected virtual void Dispose(bool disposing) { if (!_disposed) { _disposed = true; _log?.Flush(synchronous: true); if (disposing) { if (_log != null) { _log.Dispose(); } } } }
public void LogFileRotation() { var logFile = Path.Combine(TestData.GetTempPath(), "Log.txt"); var writer = new AnalysisLogWriter(logFile, false, false); for (int i = 0; i < 100; ++i) { writer.Log("Event", i); } writer.Flush(synchronous: true); var lines = File.ReadAllLines(logFile); Assert.AreEqual(101, lines.Length); writer.Rotate(11); lines = File.ReadAllLines(logFile); AssertUtil.ContainsExactly(lines.Select(l => l.Substring(l.IndexOf(']') + 1).Trim()), "Event: 90", "Event: 91", "Event: 92", "Event: 93", "Event: 94", "Event: 95", "Event: 96", "Event: 97", "Event: 98", "Event: 99" ); }
protected void Dispose(bool disposing) { if (!_disposed) { _disposed = true; _log?.Flush(!disposing); if (disposing) { if (PackageManager != null) { PackageManager.InstalledPackagesChanged -= PackageManager_InstalledFilesChanged; } } } }
protected virtual void Dispose(bool disposing) { if (!_disposed) { _disposed = true; _log?.Flush(synchronous: true); if (disposing) { if (_log != null) { _log.Dispose(); } if (PackageManager != null) { PackageManager.InstalledPackagesChanged -= PackageManager_InstalledFilesChanged; } } } }
private ModulePath?FindModuleInSearchPath( IEnumerable <string> searchPaths, IReadOnlyDictionary <string, string> packages, string name ) { if (searchPaths == null) { return(null); } try { int i = name.IndexOf('.'); var firstBit = i < 0 ? name : name.Remove(i); string searchPath; ModulePath mp; if (packages != null && packages.TryGetValue(firstBit, out searchPath) && !string.IsNullOrEmpty(searchPath)) { if (ModulePath.FromBasePathAndName_NoThrow(searchPath, name, out mp)) { return(mp); } } foreach (var sp in searchPaths.MaybeEnumerate()) { if (ModulePath.FromBasePathAndName_NoThrow(sp, name, out mp)) { return(mp); } } } catch (Exception ex) { _log?.Log(TraceLevel.Error, "Exception", ex.ToString()); _log?.Flush(); } return(null); }