Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/pyquickhelper/helpgen/default_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ def set_sphinx_variables(fileconf, module_name, author, year, theme, theme_path,
enable_disabled_parts="enable_disabled_documented_pieces_of_code",
sharepost="facebook-linkedin-twitter-20-body", custom_style=None,
extlinks=None, github_user=None, github_repo=None, title=None,
book=True, link_resolve=None, nblayout='classic', doc_version=None):
book=True, link_resolve=None, nblayout='classic', doc_version=None,
branch='master'):
"""
Defines variables for :epkg:`Sphinx`.

Expand Down Expand Up @@ -291,6 +292,7 @@ def set_sphinx_variables(fileconf, module_name, author, year, theme, theme_path,
@param nblayout ``'classic'`` or ``'table'``, specifies the layout for
the notebook gallery
@param doc_version if not None, overwrites the current version
@param branch default branch (`'master'` by default)

If the parameter *custom_style* is not None, it will call ``app.add_css_file(custom_style)``
in the setup.
Expand Down Expand Up @@ -496,7 +498,7 @@ def set_sphinx_variables(fileconf, module_name, author, year, theme, theme_path,
jupyter_sphinx_thebelab_config = { # pragma: no cover
'requestKernel': True,
'binderOptions': {
'repo': "sdpython/pyquickhelper/master?filepath=_doc"
'repo': "sdpython/pyquickhelper/%s?filepath=_doc" % branch
# 'repo': "{0}/{1}/master?filepath=_doc%2Fnotebooks".format(
# github_user, module_name)
}}
Expand Down Expand Up @@ -819,7 +821,7 @@ def modify_commit_function(nbch, date, author, comment):
'org': github_user,
'repo': github_repo,
'binderhub_url': 'https://mybinder.org',
'branch': 'master',
'branch': branch,
'dependencies': os.path.abspath(
os.path.join(os.path.dirname(version_file), 'requirements.txt')),
'use_jupyter_lab': True,
Expand Down
5 changes: 3 additions & 2 deletions src/pyquickhelper/helpgen/utils_sphinx_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def locate_image_documentation(image_name):
raise FileNotFoundError(image_name)


def NbImage(name, repository=None, force_github=False, width=None):
def NbImage(name, repository=None, force_github=False, width=None, branch='master'):
"""
Retrieves a name or a url of the image if it is not found in the local folder
or a subfolder.
Expand All @@ -63,6 +63,7 @@ def NbImage(name, repository=None, force_github=False, width=None):
@param force_github force the system to retrieve the image from GitHub
@param repository repository, see below
@param width to modify the width
@param branch branch
@return an `Image object <http://ipython.org/ipython-doc/2/api/generated/IPython.core.display.html
#IPython.core.display.Image>`_

Expand Down Expand Up @@ -117,7 +118,7 @@ def NbImage(name, repository=None, force_github=False, width=None):
repository = modobj.__github__
repository = repository.rstrip("/")

loc = "/".join(["master", "_doc", "notebooks"] + paths[pos + 2:])
loc = "/".join([branch, "_doc", "notebooks"] + paths[pos + 2:])
url = repository + "/" + loc
url = url.replace("github.com", "raw.githubusercontent.com")
return Image(url, width=width)
8 changes: 6 additions & 2 deletions src/pyquickhelper/jenkinshelper/jenkins_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,14 @@ def default_jenkins_jobs(platform=None, github_owner="sdpython",
from pyquickhelper.jenkinshelper import default_jenkins_jobs
print(default_jenkins_jobs())
"""
if ':' in module_name:
module_name, branch = module_name.split(':')
else:
branch = 'master'
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)
pattern = "https://raw.githubusercontent.com/{1}/%s/{2}/.local.jenkins.{0}.yml".format(
plat, github_owner, branch)
yml = []
if not isinstance(module_name, list):
module_name = [module_name]
Expand Down
32 changes: 24 additions & 8 deletions src/pyquickhelper/jenkinshelper/jenkins_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,8 @@ def create_job_template(self, name, git_repo, credentials="", upstreams=None, sc
location=None, keep=10, scheduler=None, py27=False, description=None,
default_engine_paths=None, success_only=False, update=False,
timeout=_timeout_default, additional_requirements=None,
return_job=False, adjust_scheduler=True, clean_repo=True, **kwargs):
return_job=False, adjust_scheduler=True, clean_repo=True,
branch='master', **kwargs):
"""
Adds a job to the :epkg:`Jenkins` server.

Expand Down Expand Up @@ -743,6 +744,7 @@ def create_job_template(self, name, git_repo, credentials="", upstreams=None, sc
is already taken
@param return_job return job instead of submitting the job
@param clean_repo clean the repository before building (default is yes)
@param branch default branch

The job can be modified on Jenkins. To add a time trigger::

Expand All @@ -756,6 +758,9 @@ def create_job_template(self, name, git_repo, credentials="", upstreams=None, sc
Options *success_only* must be specified.
Parameter *update* updates a job instead of creating it.
"""
if ':' in name:
raise ValueError( # pragma: no cover
"Unexpected value name=%r and branch=%r." % (name, branch))
if 'platform' in kwargs:
raise NameError( # pragma: no cover
"Parameter 'platform' should be set up in the constructor.")
Expand Down Expand Up @@ -853,6 +858,7 @@ def create_job_template(self, name, git_repo, credentials="", upstreams=None, sc
git_repo_xml = JenkinsExt._git_repo \
.replace("__GITREPO__", git_repo) \
.replace("__WIPE__", wipe) \
.replace("__BRANCH__", branch) \
.replace("__CRED__", "<credentialsId>%s</credentialsId>" % credentials)

# additional scripts
Expand Down Expand Up @@ -1156,9 +1162,18 @@ def setup_jenkins_server(self, github, modules, get_jenkins_script=None, overwri
"Empty jobs in the list.") # pragma: no cover
if jobs[0] == "yml" and len(jobs) != 3:
raise ValueError( # pragma: no cover
"If it is a yml jobs, the tuple should contain 3 elements: ('yml', filename, schedule or None or dictionary).\n" +
"If it is a yml jobs, the tuple should contain 3 elements: "
"('yml', filename, schedule or None or dictionary).\n" +
"Not: {0}".format(jobs))

branch = 'master'
if isinstance(jobs, tuple) and jobs[0] == 'yml':
url = jobs[1]
url_spl = url.split('/')
if len(url_spl) > 2:
branch = url_spl[-2]
else:
branch = 'master'
cre, ds, locs = self._setup_jenkins_server_modules_loop(
jobs=jobs, counts=counts,
get_jenkins_script=get_jenkins_script,
Expand All @@ -1167,15 +1182,15 @@ def setup_jenkins_server(self, github, modules, get_jenkins_script=None, overwri
overwrite=overwrite, prefix=prefix,
credentials=credentials, github=github,
disable_schedule=disable_schedule, jenkins_server=self,
update=update, indexes=indexes, deps=deps)
update=update, indexes=indexes, deps=deps, branch=branch)
created.extend(cre)
locations.extend(locs)
deps.extend(ds)
return created

def _setup_jenkins_server_modules_loop(self, jobs, counts, get_jenkins_script, location, adjust_scheduler,
add_environ, yml_engine, overwrite, prefix, credentials, github,
disable_schedule, jenkins_server, update, indexes, deps):
disable_schedule, jenkins_server, update, indexes, deps, branch):
if not isinstance(jobs, list):
jobs = [jobs]
indexes["unit"] = 0
Expand All @@ -1194,7 +1209,7 @@ def _setup_jenkins_server_modules_loop(self, jobs, counts, get_jenkins_script, l
disable_schedule=disable_schedule,
jenkins_server=jenkins_server,
update=update, indexes=indexes,
deps=deps, i=i)
deps=deps, i=i, branch=branch)
created.extend(cre)
new_dep.extend(dep)
locations.extend(loc)
Expand All @@ -1205,14 +1220,15 @@ def _setup_jenkins_server_modules_loop(self, jobs, counts, get_jenkins_script, l

def _setup_jenkins_server_job_iteration(self, job, get_jenkins_script, location, adjust_scheduler,
add_environ, yml_engine, overwrite, prefix, credentials, github,
disable_schedule, jenkins_server, update, indexes, deps, i, counts):
disable_schedule, jenkins_server, update, indexes, deps, i,
counts, branch):
order = indexes["order"]
dozen = indexes["dozen"]
unit = indexes["unit"]
new_dep = []
created = []
locations = []

if isinstance(job, tuple):
if len(job) < 2:
raise JenkinsJobException( # pragma: no cover
Expand Down Expand Up @@ -1399,7 +1415,7 @@ def _setup_jenkins_server_job_iteration(self, job, get_jenkins_script, location,
success_only=success_only, timeout=timeout, platform=self.platform,
adjust_scheduler=adjust_scheduler, overwrite=overwrite,
build_location=location, mails=self.mails,
job_options=scheduler_options):
job_options=scheduler_options, branch=branch):
if name in done:
s = "A name '{0}' was already used for a job, from:\n{1}\nPROCESS:\n{2}" # pragma: no cover
raise ValueError( # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion src/pyquickhelper/jenkinshelper/jenkins_server_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>*/master</name>
<name>*/__BRANCH__</name>
</hudson.plugins.git.BranchSpec>
</branches>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
Expand Down
11 changes: 7 additions & 4 deletions src/pyquickhelper/jenkinshelper/yaml_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def infer_project_name(file_or_buffer, source):
name = None
while len(spl) > -pos:
name = spl[pos]
if name in {'master'}:
if name in {'master', 'main'}:
pos -= 1
elif 'github' in name:
break
Expand All @@ -605,7 +605,7 @@ def infer_project_name(file_or_buffer, source):

def enumerate_processed_yml(file_or_buffer, context=None, engine="jinja2", platform=None,
server=None, git_repo=None, add_environ=True, overwrite=False,
build_location=None, **kwargs):
build_location=None, branch='master', **kwargs):
"""
Submits or enumerates jobs based on the content of a :epkg:`yml` file.

Expand All @@ -618,11 +618,13 @@ def enumerate_processed_yml(file_or_buffer, context=None, engine="jinja2", platf
@param add_environ add environment variable before interpreting the job
@param overwrite overwrite the job if it already exists in Jenkins
@param build_location location for the build
@param branch default branch
@param kwargs see @see me create_job_template
@return enumerator for *(job, name, variables)*

Example of a :epkg:`yml` file
`.local.jenkins.win.yml <https://github.com/sdpython/pyquickhelper/blob/master/.local.jenkins.win.yml>`_.
`.local.jenkins.win.yml
<https://github.com/sdpython/pyquickhelper/blob/master/.local.jenkins.win.yml>`_.
A subfolder was added to the project location.
A scheduler can be defined as well by adding ``SCHEDULER:'* * * * *'``.
"""
Expand Down Expand Up @@ -712,6 +714,7 @@ def enumerate_processed_yml(file_or_buffer, context=None, engine="jinja2", platf
kwargs["adjuster_scheduler"] = adjuster_scheduler
yield server.create_job_template(name, script=conv, git_repo=git_repo,
update=update_job, location=loc,
clean_repo=clean_repo, **kwargs), name, var
clean_repo=clean_repo, branch=branch,
**kwargs), name, var
else:
yield conv, None, var