private bool TryCreateStubModule(string name, out IPythonModule module) { module = null; var moduleImport = CurrentPathResolver.GetModuleImportFromModuleName(name); if (moduleImport != null) { if (moduleImport.IsCompiled) { Log?.Log(TraceEventType.Warning, "Unsupported native module in stubs", moduleImport.FullName, moduleImport.ModulePath); return(false); } module = new StubPythonModule(moduleImport.FullName, moduleImport.ModulePath, true, Services); return(true); } var i = name.IndexOf('.'); if (i == 0) { Debug.Fail("Invalid module name"); return(false); } var stubPath = CurrentPathResolver.GetPossibleModuleStubPaths(name).FirstOrDefault(p => FileSystem.FileExists(p)); if (stubPath != null) { module = new StubPythonModule(name, stubPath, true, Services); return(true); } return(false); }
private IDocument CreateDocument(ModuleCreationOptions mco) { IDocument document; switch (mco.ModuleType) { case ModuleType.Stub: document = new StubPythonModule(mco.ModuleName, mco.FilePath, _services); break; case ModuleType.Compiled: document = new CompiledPythonModule(mco.ModuleName, ModuleType.Compiled, mco.FilePath, mco.Stub, _services); break; case ModuleType.CompiledBuiltin: document = new CompiledBuiltinPythonModule(mco.ModuleName, mco.Stub, _services); break; case ModuleType.User: case ModuleType.Library: document = new PythonModule(mco, _services); break; default: throw new InvalidOperationException($"CreateDocument does not support module type {mco.ModuleType}"); } _documentsByUri[document.Uri] = document; _documentsByName[mco.ModuleName] = document; _moduleResolution.AddModulePath(document.FilePath); return(OpenDocument(document, mco.LoadOptions)); }
private bool TryCreateModuleStub(string name, string modulePath, out IPythonModule module) { // First check stub next to the module. if (!string.IsNullOrEmpty(modulePath)) { var pyiPath = Path.ChangeExtension(modulePath, "pyi"); if (FileSystem.FileExists(pyiPath)) { module = new StubPythonModule(name, pyiPath, false, Services); return(true); } } // Try location of stubs that are in a separate folder next to the package. var stubPath = CurrentPathResolver.GetPossibleModuleStubPaths(name).FirstOrDefault(p => FileSystem.FileExists(p)); module = !string.IsNullOrEmpty(stubPath) ? new StubPythonModule(name, stubPath, false, Services) : null; return(module != null); }