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, pywin32_set 

9from .packaged_config_0_pyquickhelper import pyquickhelper_set 

10from .packaged_config_1_pyensae import pyensae_set 

11from .packaged_config_1_small import small_set 

12from .packaged_config_2_cloud import cloud_set 

13from .packaged_config_2_sphinx import sphinx_theme_set 

14from .packaged_config_3_extended import extended_set 

15from .packaged_config_4_ml import ml_set, ensae_set 

16from .packaged_config_A_teachings import teachings_set 

17from .packaged_config_A_orange import orange_set 

18from .packaged_config_B_iot import iot_set 

19from .packaged_config_C_webscraping import scraping_set 

20from .packaged_config_Z_datascientist import datascientistbase_set 

21 

22 

23def ensae_fullset(): 

24 """ 

25 Installation of all possible modules for my teachings at the ENSAE. 

26 """ 

27 base = small_set() + \ 

28 sphinx_theme_set() + \ 

29 cloud_set() + \ 

30 extended_set() + \ 

31 ensae_set() + \ 

32 teachings_set() + \ 

33 orange_set() 

34 

35 return base 

36 

37 

38def all_set(): 

39 """ 

40 Installation of all possible modules listed in this module. 

41 """ 

42 base = small_set() + \ 

43 sphinx_theme_set() + \ 

44 cloud_set() + \ 

45 extended_set() + \ 

46 ensae_set() + \ 

47 teachings_set() + \ 

48 iot_set() + \ 

49 orange_set() + \ 

50 scraping_set() 

51 

52 return base 

53 

54 

55_modules_set = [all_set, 

56 cloud_set, 

57 datascientistbase_set, 

58 extended_set, 

59 iot_set, 

60 minimal_set, 

61 ml_set, ensae_set, 

62 orange_set, 

63 pyensae_set, 

64 pyquickhelper_set, 

65 pywin32_set, 

66 scraping_set, 

67 small_set, 

68 sphinx_theme_set, 

69 teachings_set, 

70 ] 

71 

72 

73def _function_set_name(f): 

74 """ 

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

76 

77 @param f function 

78 @return name 

79 

80 .. versionadded:: 1.1 

81 """ 

82 name = f.__name__ 

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

84 

85 

86def _build_set_correspondance(module_set): 

87 """ 

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

89 

90 @param module_set list of functions 

91 @return dictionary 

92 """ 

93 res = {} 

94 for f in module_set: 

95 name = _function_set_name(f) 

96 res[name] = f 

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

98 res[name] = f 

99 return res 

100 

101 

102_module_set_name = _build_set_correspondance(_modules_set) 

103 

104 

105def get_package_set(name): 

106 """ 

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

108 

109 @param name set name 

110 @return list of modules 

111 

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

113 """ 

114 if name not in _module_set_name: 

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

116 keys = list(sorted(set(keys))) 

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

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

119 return _module_set_name[name] 

120 

121 

122def name_sets_dataframe(module_set=None): 

123 """ 

124 returns a RST tables which described all the available sets 

125 

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

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

128 

129 the functions requires 

130 """ 

131 if module_set is None: 

132 module_set = _modules_set 

133 

134 def process_doc(doc): 

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

136 res = [] 

137 for line in lines: 

138 if "@return" in line: 

139 break 

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

141 res.append(line) 

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

143 

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

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

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

147 so.sort() 

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

149 

150 

151def classifiers2string(l): 

152 """ 

153 shorten the list of classifiers into a string 

154 

155 @param l list 

156 @return string 

157 

158 Example:: 

159 

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

161 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 

162 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', 

163 'Programming Language :: Python :: 3.4', 'License :: OSI Approved :: Apache Software License'] 

164 """ 

165 if l is None: 

166 return "" 

167 res = [] 

168 for cl in sorted(set(l)): 

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

170 s = "Python" 

171 else: 

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

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

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

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

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

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

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

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

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

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

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

183 if s == "3 :: Only": 

184 s = "py3" 

185 elif s == "2 :: Only": 

186 s = "py2" 

187 elif s == "MacOS :: MacOS X": 

188 s = "MacOS/X" 

189 elif s == "POSIX :: Linux": 

190 s = "Linux" 

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

192 s = "FreeBSD" 

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

194 s = "Qt" 

195 elif s.startswith("Windows"): 

196 s = "Windows" 

197 if "Framework" not in s and "Topic" not in s and "Intended Audience" not in s and "Natural Language" not in s: 

198 res.append(s) 

199 return ", ".join(res)