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

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

""" 

@file 

@brief Helpers to prepare a local Jenkins server. 

""" 

import sys 

from ..loghelper import noLOG 

 

 

def get_platform(platform=None): 

""" 

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

 

@param platform default values for which OS or 

``sys.platform``. 

@return platform 

 

This documentation was generated with a machine using the 

following *OS* (among the 

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

 

.. runpython:: 

:showcode: 

 

from pyquickhelper.jenkinshelper.jenkins_helper import get_platform 

print(get_platform()) 

 

.. versionadded:: 1.8 

""" 

return platform or sys.platform 

 

 

def default_engines(platform=None): 

""" 

Returns a dictionary with default values for Jenkins server, 

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

 

@param platform default values for which OS or 

``get_platform(platform)``. 

@return dictionary 

 

.. warning:: 

 

Virtual environment with conda must be created on the same disk 

as the original interpreter. The other scenario is not supported 

by Anaconda. 

 

It returns: 

 

.. runpython:: 

 

from pyquickhelper.jenkinshelper import default_engines 

print(default_engines()) 

""" 

platform = get_platform(platform) 

if platform == "win32": 

res = dict(Anaconda2="d:\\Anaconda", 

Anaconda3="d:\\Anaconda3", 

Python37="c:\\Python37_x64", 

Python36="c:\\Python36_x64", 

Python35="c:\\Python35_x64", 

Python34="c:\\Python34_x64", 

Python27="c:\\Python27", 

WinPython37="c:\\APythonENSAE\\python37", 

WinPython36="c:\\APythonENSAE\\python36", 

WinPython35="c:\\APythonENSAE\\python35") 

elif platform == "linux": 

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

Python37="/usr/local/python37", 

Python36="/usr/local/python36") 

else: 

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

 

return res 

 

 

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

module_name="pyquickhelper"): 

""" 

Example of a list of jobs for parameter *module* 

of function @see fn setup_jenkins_server_yml. 

 

@param platform platform 

@param github_owner GitHub user 

@param module_name module name or list of modules names 

@return tuple 

 

It returns: 

 

.. runpython:: 

 

from pyquickhelper.jenkinshelper import default_jenkins_jobs 

print(default_jenkins_jobs()) 

""" 

platform = get_platform(platform) 

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

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

plat, github_owner) 

yml = [] 

if not isinstance(module_name, list): 

module_name = [module_name] 

for i, c in enumerate(module_name): 

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

return yml 

 

 

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

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

delete_first=False, disable_schedule=False, 

fLOG=noLOG, **kwargs): 

""" 

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

 

@param js @see cl JenkinsExt, jenkins server 

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

the link to git repository of the project otherwise, 

we assume the job comes from the same repository, 

otherwise the function will have to called several times 

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

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

@param location None for default or a local folder 

@param prefix add a prefix to the name 

@param delete_first removes all jobs before adding new ones 

@param disable_schedule disable scheduling for all jobs 

@param fLOG logging function 

@param kwargs see method @see me setup_jenkins_server 

@return list of created jobs 

 

Example:: 

 

from pyquickhelper.jenkinshelper import JenkinsExt, setup_jenkins_server_yml, default_jenkins_jobs, default_engines 

 

user = "<user>" 

password = "<password>" 

modules = default_jenkins_jobs() 

engines = default_engines() 

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

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

overwrite=True, delete_first=False, 

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

 

See `.local.jenkins.win.yml <https://github.com/sdpython/pyquickhelper/blob/master/.local.jenkins.win.yml>`_ 

(Windows) or 

`.local.jenkins.lin.yml <https://github.com/sdpython/pyquickhelper/blob/master/.local.jenkins.lin.yml>`_ 

(Linux) 

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

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

@see fn default_jenkins_jobs. 

The platform is stored in *srv*. 

""" 

if modules is None: 

modules = default_jenkins_jobs(js.platform) 

if delete_first: 

js.delete_all_jobs() 

r = js.setup_jenkins_server(github=github, modules=modules, overwrite=overwrite, 

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

**kwargs) 

return r 

 

 

def jenkins_final_postprocessing(xml_job, py27): 

""" 

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

 

@param xml_job :epkg:`xml` definition 

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

@return new xml job 

""" 

if py27: 

# options are not allowed 

xml_job = xml_job.replace( 

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

return xml_job