Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# -*- coding: utf-8 -*- 

2""" 

3@file 

4@brief Defines different set of modules to install. 

5 

6 

7""" 

8from .packaged_config_0_minimal import minimal_set 

9from .packaged_config_1_small import small_set 

10 

11 

12_modules_set = [minimal_set, small_set] 

13 

14 

15def _function_set_name(f): 

16 """ 

17 return the name of a function (not the module) 

18 

19 @param f function 

20 @return name 

21 

22 .. versionadded:: 1.1 

23 """ 

24 name = f.__name__ 

25 return name.split(".")[-1] 

26 

27 

28def _build_set_correspondance(module_set): 

29 """ 

30 builds a dictionary which returns a dictionary *{ name: function_set }*. 

31 

32 @param module_set list of functions 

33 @return dictionary 

34 """ 

35 res = {} 

36 for f in module_set: 

37 name = _function_set_name(f) 

38 res[name] = f 

39 name = name.replace("_set", "") 

40 res[name] = f 

41 return res 

42 

43 

44_module_set_name = _build_set_correspondance(_modules_set) 

45 

46 

47def get_package_set(name): 

48 """ 

49 return a list of modules included in one the functions imported in this module 

50 

51 @param name set name 

52 @return list of modules 

53 

54 See :ref:`l-name-set-table` to get the list of available sets. 

55 """ 

56 if name not in _module_set_name: 

57 keys = [_.replace("_set", "") for _ in _module_set_name.keys()] 

58 keys = list(sorted(set(keys))) 

59 raise ValueError("unable to find set for {0}\navailable sets:\n{1}".format( 

60 name, "\n".join(keys))) 

61 return _module_set_name[name] 

62 

63 

64def name_sets_dataframe(module_set=None): 

65 """ 

66 returns a RST tables which described all the available sets 

67 

68 @param module_set list of module sets or None to get all the sets described in this module 

69 @return list of dictionaries ``[ { "name": name1, "description": description } ]`` 

70 

71 the functions requires 

72 """ 

73 if module_set is None: 

74 module_set = _modules_set 

75 

76 def process_doc(doc): 

77 lines = [_.strip() for _ in doc.split("\n")] 

78 res = [] 

79 for line in lines: 

80 if "@return" in line: 

81 break 

82 if not line.startswith(".. index::"): 

83 res.append(line) 

84 return (" ".join(res)).strip() 

85 

86 res = [{"name": _function_set_name(f).replace("_set", ""), 

87 "description": process_doc(f.__doc__)} for f in module_set] 

88 so = [(_["name"], _) for _ in res] 

89 so.sort() 

90 return [_[1] for _ in so] 

91 

92 

93def classifiers2string(li): 

94 """ 

95 Shortens the list of classifiers into a string. 

96 

97 @param li list 

98 @return string 

99 

100 Example:: 

101 

102 ['Development Status :: 4 - Beta', 'Programming Language :: Python', 

103 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3', 

104 'Programming Language :: Python :: 3.9', 'License :: OSI Approved :: Apache Software License'] 

105 """ 

106 if li is None: 

107 return "" 

108 res = [] 

109 for cl in sorted(set(li)): 

110 if cl == "Programming Language :: Python": 

111 s = "Python" 

112 else: 

113 s = cl.replace("Programming Language :: Python :: ", "") 

114 s = s.replace("License :: ", "") 

115 s = s.replace("OSI Approved :: ", "OSI Approved ") 

116 s = s.replace("Development Status :: ", "") 

117 s = s.replace("Operating System :: Microsoft :: ", "") 

118 s = s.replace("Operating System :: ", "") 

119 s = s.replace("Implementation :: ", "") 

120 s = s.replace("Programming Language :: ", "") 

121 s = s.replace("Environment :: ", "") 

122 s = s.replace("POSIX :: ", "") 

123 s = s.replace("BSD :: ", "") 

124 if s == "3 :: Only": 

125 s = "py3" 

126 elif s == "2 :: Only": 

127 s = "py2" 

128 elif s == "MacOS :: MacOS X": 

129 s = "MacOS/X" 

130 elif s == "POSIX :: Linux": 

131 s = "Linux" 

132 elif s == "POSIX :: BSD :: FreeBSD": 

133 s = "FreeBSD" 

134 elif s == "X11 Applications :: Qt": 

135 s = "Qt" 

136 elif s.startswith("Windows"): 

137 s = "Windows" 

138 if ("Framework" not in s and "Topic" not in s and 

139 "Intended Audience" not in s and "Natural Language" not in s): 

140 res.append(s) 

141 return ", ".join(res)