Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/scikit_learn-1.4.dev0-py3.8-linux-x86_64.egg/sklearn/utils/_show_versions.py: 21%

38 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-12 06:31 +0000

1""" 

2Utility methods to print system info for debugging 

3 

4adapted from :func:`pandas.show_versions` 

5""" 

6# License: BSD 3 clause 

7 

8import platform 

9import sys 

10 

11from .. import __version__ 

12from ..utils.fixes import threadpool_info 

13from ._openmp_helpers import _openmp_parallelism_enabled 

14 

15 

16def _get_sys_info(): 

17 """System information 

18 

19 Returns 

20 ------- 

21 sys_info : dict 

22 system and Python version information 

23 

24 """ 

25 python = sys.version.replace("\n", " ") 

26 

27 blob = [ 

28 ("python", python), 

29 ("executable", sys.executable), 

30 ("machine", platform.platform()), 

31 ] 

32 

33 return dict(blob) 

34 

35 

36def _get_deps_info(): 

37 """Overview of the installed version of main dependencies 

38 

39 This function does not import the modules to collect the version numbers 

40 but instead relies on standard Python package metadata. 

41 

42 Returns 

43 ------- 

44 deps_info: dict 

45 version information on relevant Python libraries 

46 

47 """ 

48 deps = [ 

49 "pip", 

50 "setuptools", 

51 "numpy", 

52 "scipy", 

53 "Cython", 

54 "pandas", 

55 "matplotlib", 

56 "joblib", 

57 "threadpoolctl", 

58 ] 

59 

60 deps_info = { 

61 "sklearn": __version__, 

62 } 

63 

64 from importlib.metadata import PackageNotFoundError, version 

65 

66 for modname in deps: 

67 try: 

68 deps_info[modname] = version(modname) 

69 except PackageNotFoundError: 

70 deps_info[modname] = None 

71 return deps_info 

72 

73 

74def show_versions(): 

75 """Print useful debugging information" 

76 

77 .. versionadded:: 0.20 

78 """ 

79 

80 sys_info = _get_sys_info() 

81 deps_info = _get_deps_info() 

82 

83 print("\nSystem:") 

84 for k, stat in sys_info.items(): 

85 print("{k:>10}: {stat}".format(k=k, stat=stat)) 

86 

87 print("\nPython dependencies:") 

88 for k, stat in deps_info.items(): 

89 print("{k:>13}: {stat}".format(k=k, stat=stat)) 

90 

91 print( 

92 "\n{k}: {stat}".format( 

93 k="Built with OpenMP", stat=_openmp_parallelism_enabled() 

94 ) 

95 ) 

96 

97 # show threadpoolctl results 

98 threadpool_results = threadpool_info() 

99 if threadpool_results: 

100 print() 

101 print("threadpoolctl info:") 

102 

103 for i, result in enumerate(threadpool_results): 

104 for key, val in result.items(): 

105 print(f"{key:>15}: {val}") 

106 if i != len(threadpool_results) - 1: 

107 print()