Coverage for sources/librovore/inventories/sphinx/main.py: 40%

18 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''' Sphinx inventory processor for objects.inv format. ''' 

22 

23from . import __ 

24from . import detection as _detection 

25 

26 

27class SphinxInventoryProcessor( __.Processor ): 

28 ''' Processes Sphinx inventory files (objects.inv format). ''' 

29 

30 name: str = 'sphinx' 

31 

32 @property 

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

34 ''' Returns Sphinx inventory processor capabilities. ''' 

35 return __.ProcessorCapabilities( 

36 processor_name = 'sphinx', 

37 version = '1.0.0', 

38 supported_filters = [ 

39 __.FilterCapability( 

40 name = 'domain', 

41 description = 'Filter by object domain (e.g., py, js)', 

42 type = 'string' 

43 ), 

44 __.FilterCapability( 

45 name = 'role', 

46 description = 'Filter by object role (e.g., class, func)', 

47 type = 'string' 

48 ), 

49 __.FilterCapability( 

50 name = 'priority', 

51 description = 'Filter by object priority', 

52 type = 'string' 

53 ), 

54 ], 

55 results_limit_max = 10000, 

56 response_time_typical = 'fast', 

57 notes = 'Processes Sphinx inventory files (objects.inv format)' 

58 ) 

59 

60 async def detect( 

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

62 ) -> __.InventoryDetection: 

63 ''' Detects if source has a Sphinx inventory file. ''' 

64 base_url = __.normalize_base_url( source ) 

65 has_objects_inv = await check_objects_inv( auxdata, base_url ) 

66 if has_objects_inv: 

67 return _detection.SphinxInventoryDetection( 

68 processor = self, confidence = 1.0 ) 

69 return _detection.SphinxInventoryDetection( 

70 processor = self, confidence = 0.0 ) 

71 

72 

73async def check_objects_inv( 

74 auxdata: __.ApplicationGlobals, base_url: __.typx.Any 

75) -> bool: 

76 ''' Checks if objects.inv exists at the source for inventory detection. ''' 

77 inventory_url = _detection.derive_inventory_url( base_url ) 

78 try: 

79 return await __.probe_url( 

80 auxdata.probe_cache, inventory_url ) 

81 except Exception: return False