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""" 

2@file 

3@brief Helpers to prepare a local Jenkins server. 

4""" 

5import sys 

6from ..loghelper import noLOG 

7 

8 

9def get_platform(platform=None): 

10 """ 

11 Returns *platform* if not *None*, ``sys.platform`` otherwise. 

12 

13 @param platform default values for which OS or 

14 ``sys.platform``. 

15 @return platform 

16 

17 This documentation was generated with a machine using the 

18 following *OS* (among the 

19 `possible values <https://docs.python.org/3/library/sys.html#sys.platform>`_). 

20 

21 .. runpython:: 

22 :showcode: 

23 

24 from pyquickhelper.jenkinshelper.jenkins_helper import get_platform 

25 print(get_platform()) 

26 """ 

27 return platform or sys.platform 

28 

29 

30def default_engines(platform=None): 

31 """ 

32 Returns a dictionary with default values for Jenkins server, 

33 you should update the path if the proposed path are not good. 

34 

35 @param platform default values for which OS or 

36 ``get_platform(platform)``. 

37 @return dictionary 

38 

39 .. warning:: 

40 

41 Virtual environment with conda must be created on the same disk 

42 as the original interpreter. The other scenario is not supported 

43 by Anaconda. 

44 

45 It returns: 

46 

47 .. runpython:: 

48 

49 from pyquickhelper.jenkinshelper import default_engines 

50 print(default_engines()) 

51 """ 

52 platform = get_platform(platform) 

53 if platform == "win32": 

54 res = dict(Anaconda3="d:\\Anaconda3", 

55 Python39="c:\\Python39_x64", 

56 Python38="c:\\Python38_x64", 

57 Python37="c:\\Python37_x64", 

58 WinPython39="c:\\APythonENSAE\\python39", 

59 WinPython38="c:\\APythonENSAE\\python38", 

60 WinPython37="c:\\APythonENSAE\\python37") 

61 elif platform == "linux": 

62 res = dict(Anaconda3="/usr/local/miniconda3", 

63 Python39="/usr/local/python39", 

64 Python38="/usr/local/python38", 

65 Python37="/usr/local/python37", 

66 Python36="/usr/local/python36", 

67 WinPython39="ERROR", 

68 WinPython38="ERROR", 

69 WinPython37="ERROR") 

70 else: 

71 raise ValueError( # pragma: no cover 

72 "Unknown value for platform '{0}'.".format(platform)) 

73 

74 return res 

75 

76 

77def default_jenkins_jobs(platform=None, github_owner="sdpython", 

78 module_name="pyquickhelper"): 

79 """ 

80 Example of a list of jobs for parameter *module* 

81 of function @see fn setup_jenkins_server_yml. 

82 

83 @param platform platform 

84 @param github_owner GitHub user 

85 @param module_name module name or list of modules names 

86 @return tuple 

87 

88 It returns: 

89 

90 .. runpython:: 

91 

92 from pyquickhelper.jenkinshelper import default_jenkins_jobs 

93 print(default_jenkins_jobs()) 

94 """ 

95 platform = get_platform(platform) 

96 plat = "win" if platform.startswith("win") else "lin" 

97 pattern = "https://raw.githubusercontent.com/{1}/%s/master/.local.jenkins.{0}.yml".format( 

98 plat, github_owner) 

99 yml = [] 

100 if not isinstance(module_name, list): 

101 module_name = [module_name] 

102 for i, c in enumerate(module_name): 

103 yml.append(('yml', pattern % c, 'H H(5-6) * * %d' % (i % 7))) 

104 return yml 

105 

106 

107def setup_jenkins_server_yml(js, github="sdpython", modules=None, 

108 overwrite=False, location=None, prefix="", 

109 delete_first=False, disable_schedule=False, 

110 fLOG=noLOG, **kwargs): 

111 """ 

112 Sets up many jobs on :epkg:`Jenkins`. 

113 

114 @param js @see cl JenkinsExt, jenkins server 

115 @param github github account if it does not start with *http://*, 

116 the link to git repository of the project otherwise, 

117 we assume the job comes from the same repository, 

118 otherwise the function will have to called several times 

119 @param modules modules for which to generate the Jenkins job (see @see fn default_jenkins_jobs) 

120 @param overwrite do not create the job if it already exists 

121 @param location None for default or a local folder 

122 @param prefix add a prefix to the name 

123 @param delete_first removes all jobs before adding new ones 

124 @param disable_schedule disable scheduling for all jobs 

125 @param fLOG logging function 

126 @param kwargs see method @see me setup_jenkins_server 

127 @return list of created jobs 

128 

129 Example:: 

130 

131 from pyquickhelper.jenkinshelper ( 

132 import JenkinsExt, setup_jenkins_server_yml, 

133 default_jenkins_jobs, default_engines) 

134 

135 user = "<user>" 

136 password = "<password>" 

137 modules = default_jenkins_jobs() 

138 engines = default_engines() 

139 js = JenkinsExt('http://localhost:8080/', user, password, engines=engines) 

140 setup_jenkins_server_yml(js, github="sdpython", modules=modules, fLOG=print, 

141 overwrite=True, delete_first=False, 

142 location="d:\\\\jenkins\\\\pymy") 

143 

144 See `.local.jenkins.win.yml 

145 <https://github.com/sdpython/pyquickhelper/blob/ 

146 master/.local.jenkins.win.yml>`_ (Windows) or 

147 `.local.jenkins.lin.yml 

148 <https://github.com/sdpython/pyquickhelper/blob/ 

149 master/.local.jenkins.lin.yml>`_ (Linux) 

150 about the syntax of a :epkg:`yml` job description. 

151 If *modules* is None, it is replaced by the results of 

152 @see fn default_jenkins_jobs. 

153 The platform is stored in *srv*. 

154 """ 

155 if modules is None: 

156 modules = default_jenkins_jobs(js.platform) # pragma: no cover 

157 if delete_first: 

158 js.delete_all_jobs() # pragma: no cover 

159 r = js.setup_jenkins_server( 

160 github=github, modules=modules, overwrite=overwrite, 

161 location=location, prefix=prefix, disable_schedule=disable_schedule, 

162 **kwargs) 

163 return r 

164 

165 

166def jenkins_final_postprocessing(xml_job, py27): 

167 """ 

168 Postprocesses a job produced by :epkg:`Jenkins`. 

169 

170 @param xml_job :epkg:`xml` definition 

171 @param py27 is it for :epkg:`Python` 27 

172 @return new xml job 

173 """ 

174 if py27: 

175 # options are not allowed 

176 xml_job = xml_job.replace( 

177 "python -X faulthandler -X showrefcount", "python") 

178 return xml_job