Exemple #1
0
        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);
        }
        protected override IPythonModule CreateModule(string name)
        {
            var mp = FindModuleInSearchPath(_typeStubPaths, null, name);

            if (mp != null)
            {
                if (mp.Value.IsCompiled)
                {
                    _log?.Log(TraceEventType.Warning, "Unsupported native module in stubs", mp.Value.FullName, mp.Value.SourceFile);
                    return(null);
                }
                return(new StubPythonModule(mp.Value.FullName, mp.Value.SourceFile, true, _services));
            }

            var i = name.IndexOf('.');

            if (i == 0)
            {
                Debug.Fail("Invalid module name");
                return(null);
            }

            var stubPath = CurrentPathResolver.GetPossibleModuleStubPaths(name).FirstOrDefault(p => _fs.FileExists(p));

            return(stubPath != null ? new StubPythonModule(name, stubPath, true, _services) : null);
        }
Exemple #3
0
        protected override IPythonModule CreateModule(string name)
        {
            var moduleImport = CurrentPathResolver.GetModuleImportFromModuleName(name);

            if (moduleImport != default)
            {
                if (moduleImport.IsCompiled)
                {
                    Log?.Log(TraceEventType.Warning, "Unsupported native module in stubs", moduleImport.FullName, moduleImport.ModulePath);
                    return(null);
                }
                return(new StubPythonModule(moduleImport.FullName, moduleImport.ModulePath, true, Services));
            }

            var i = name.IndexOf('.');

            if (i == 0)
            {
                Debug.Fail("Invalid module name");
                return(null);
            }

            var stubPath = CurrentPathResolver.GetPossibleModuleStubPaths(name).FirstOrDefault(p => FileSystem.FileExists(p));

            return(stubPath != null ? new StubPythonModule(name, stubPath, true, Services) : null);
        }
        private async Task <IPythonModule> ImportFromTypeStubsAsync(string name, CancellationToken cancellationToken = default)
        {
            var mp = FindModuleInSearchPath(_typeStubPaths, null, name);

            if (mp != null)
            {
                if (mp.Value.IsCompiled)
                {
                    _log?.Log(TraceEventType.Warning, "Unsupported native module in stubs", mp.Value.FullName, mp.Value.SourceFile);
                    return(null);
                }
                return(await CreateStubModuleAsync(mp.Value.FullName, mp.Value.SourceFile, cancellationToken));
            }

            var i = name.IndexOf('.');

            if (i == 0)
            {
                Debug.Fail("Invalid module name");
                return(null);
            }

            var stubPath = CurrentPathResolver.GetPossibleModuleStubPaths(name).FirstOrDefault(p => _fs.FileExists(p));

            return(stubPath != null ? await CreateStubModuleAsync(name, stubPath, cancellationToken) : null);
        }
        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);
        }