Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/opentelemetry/util/_importlib_metadata.py: 90%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

10 statements  

1# Copyright The OpenTelemetry Authors 

2# 

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

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

5# You may obtain a copy of the License at 

6# 

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

8# 

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

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

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

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

13# limitations under the License. 

14 

15from functools import cache 

16 

17# FIXME: Use importlib.metadata (not importlib_metadata) 

18# when support for 3.11 is dropped if the rest of 

19# the supported versions at that time have the same API. 

20from importlib_metadata import ( # type: ignore 

21 Distribution, 

22 EntryPoint, 

23 EntryPoints, 

24 PackageNotFoundError, 

25 distributions, 

26 requires, 

27 version, 

28) 

29from importlib_metadata import ( 

30 entry_points as original_entry_points, 

31) 

32 

33 

34@cache 

35def _original_entry_points_cached(): 

36 return original_entry_points() 

37 

38 

39def entry_points(**params): 

40 """Replacement for importlib_metadata.entry_points that caches getting all the entry points. 

41 

42 That part can be very slow, and OTel uses this function many times.""" 

43 return _original_entry_points_cached().select(**params) 

44 

45 

46__all__ = [ 

47 "entry_points", 

48 "version", 

49 "EntryPoint", 

50 "EntryPoints", 

51 "requires", 

52 "Distribution", 

53 "distributions", 

54 "PackageNotFoundError", 

55]