Coverage for sources/librovore/structures/sphinx/main.py: 33%

29 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-03 21:59 +0000

1# vim: set filetype=python fileencoding=utf-8: 

2# -*- coding: utf-8 -*- 

3 

4#============================================================================# 

5# # 

6# Licensed under the Apache License, Version 2.0 (the "License"); # 

7# you may not use this file except in compliance with the License. # 

8# You may obtain a copy of the License at # 

9# # 

10# http://www.apache.org/licenses/LICENSE-2.0 # 

11# # 

12# Unless required by applicable law or agreed to in writing, software # 

13# distributed under the License is distributed on an "AS IS" BASIS, # 

14# WITHOUT WARRANTIES OR CONDITIONS of ANY KIND, either express or implied. # 

15# See the License for the specific language governing permissions and # 

16# limitations under the License. # 

17# # 

18#============================================================================# 

19 

20 

21''' Main Sphinx processor implementation. ''' 

22 

23 

24from . import __ 

25from . import detection as _detection 

26from . import urls as _urls 

27 

28 

29_scribe = __.acquire_scribe( __name__ ) 

30_search_behaviors_default = __.SearchBehaviors( ) 

31_filters_default = __.immut.Dictionary[ str, __.typx.Any ]( ) 

32 

33 

34class SphinxProcessor( __.Processor ): 

35 ''' Processor for Sphinx documentation sources. ''' 

36 

37 name: str = 'sphinx' 

38 

39 @property 

40 def capabilities( self ) -> __.ProcessorCapabilities: 

41 ''' Returns Sphinx processor capabilities. ''' 

42 return __.ProcessorCapabilities( 

43 processor_name = 'sphinx', 

44 version = '1.0.0', 

45 supported_filters = [ 

46 __.FilterCapability( 

47 name = 'domain', 

48 description = 'Sphinx domain (py, std, js, etc.)', 

49 type = 'string', 

50 values = None, 

51 ), 

52 __.FilterCapability( 

53 name = 'role', 

54 description = 'Object role (class, function, method)', 

55 type = 'string', 

56 values = None, 

57 ), 

58 __.FilterCapability( 

59 name = 'priority', 

60 description = 'Documentation priority level', 

61 type = 'string', 

62 values = [ '0', '1', '-1' ], 

63 ), 

64 ], 

65 results_limit_max = 100, 

66 response_time_typical = 'fast', 

67 notes = 'Works with Sphinx-generated documentation sites', 

68 ) 

69 

70 async def detect( 

71 self, auxdata: __.ApplicationGlobals, source: str 

72 ) -> __.StructureDetection: 

73 ''' Detects if can process documentation from source. ''' 

74 try: base_url = _urls.normalize_base_url( source ) 

75 except Exception: 

76 return _detection.SphinxDetection( 

77 processor = self, confidence = 0.0, source = source ) 

78 confidence = 0.0 

79 has_searchindex = ( 

80 await _detection.check_searchindex( auxdata, base_url ) ) 

81 if has_searchindex: 

82 confidence += 0.8 

83 theme = None 

84 try: 

85 theme_metadata = ( 

86 await _detection.detect_theme( auxdata, base_url ) ) 

87 theme = theme_metadata.get( 'theme' ) 

88 if theme is not None: 

89 confidence += 0.2 

90 except Exception as exc: 

91 _scribe.debug( f"Theme detection failed for {source}: {exc}" ) 

92 confidence = min( confidence, 1.0 ) 

93 

94 return _detection.SphinxDetection( 

95 processor = self, 

96 confidence = confidence, 

97 source = source, 

98 has_searchindex = has_searchindex, 

99 normalized_source = base_url.geturl( ), 

100 theme = theme ) 

101