module jenkinshelper.yaml_helper

Short summary

module pyquickhelper.jenkinshelper.yaml_helper

Parse a file .yml and convert it into a set of actions.

source on GitHub

Functions

function

truncated documentation

convert_sequence_into_batch_file

Converts a sequence of instructions into a batch file.

enumerate_convert_yaml_into_instructions

Converts a yml file into sequences of instructions, conditions are interpreted.

enumerate_processed_yml

Submits or enumerates jobs based on the content of a yml file.

evaluate_condition

Evaluates a condition inserted in a yml file.

infer_project_name

Infers a project name based on yml file.

interpret_instruction

Interprets an instruction with if statement.

load_yaml

Loads a yml file (.yml).

ospathdirname

Simple o.path.dirname for a specific platform.

ospathjoin

Simple o.path.join for a specific platform.

pickname

Picks the first string non null in the list.

Documentation

Parse a file .yml and convert it into a set of actions.

source on GitHub

pyquickhelper.jenkinshelper.yaml_helper.convert_sequence_into_batch_file(seq, variables=None, platform=None)[source]

Converts a sequence of instructions into a batch file.

Parameters:
  • seq – sequence of instructions

  • variables – list of variables

  • platformget_platform(platform) if None

Returns:

(str) batch file or a list of batch file if the constant JENKINS_SPLIT was found in section install (this tweak is needed when the job has to be split for Jenkins.

source on GitHub

pyquickhelper.jenkinshelper.yaml_helper.enumerate_convert_yaml_into_instructions(obj, variables=None, add_environ=True)[source]

Converts a yml file into sequences of instructions, conditions are interpreted.

Parameters:
  • obj – yaml objects (load_yaml)

  • variables – additional variables to be used

  • add_environ – add environment variables available, does not overwrite existing variables when the job is generated

Returns:

list of tuple(instructions, variables)

The function expects the following list of steps in this order:

  • automatedsetup: added by this module

  • language: should be python

  • python: list of interpreters (multiplies jobs)

  • virtualenv: name of the virtual environment

  • install: list of installation steps in the virtual environment

  • before_script: list of steps to run

  • script: list of script to run (multiplies jobs)

  • after_script: list of steps to run

  • documentation: documentation to run after the

Each step multiplies jobs creates a sequence of jobs and a Jenkins job.

source on GitHub

pyquickhelper.jenkinshelper.yaml_helper.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, branch='master', **kwargs)[source]

Submits or enumerates jobs based on the content of a yml file.

Parameters:
  • file_or_buffer – filename or string

  • context – variables to replace in the configuration

  • engine – see apply_template

  • server – see JenkinsExt

  • platform – plaform where the job will be executed

  • git_repo – git repository (if server is not None)

  • add_environ – add environment variable before interpreting the job

  • overwrite – overwrite the job if it already exists in Jenkins

  • build_location – location for the build

  • branch – default branch

  • kwargs – see create_job_template

Returns:

enumerator for (job, name, variables)

Example of a yml file .local.jenkins.win.yml. A subfolder was added to the project location. A scheduler can be defined as well by adding SCHEDULER:'* * * * *'.

source on GitHub

pyquickhelper.jenkinshelper.yaml_helper.evaluate_condition(cond, variables=None)[source]

Evaluates a condition inserted in a yml file.

Parameters:
  • cond – (str) condition

  • variables – (dict|None) dictionary

Returns:

boolean

Example of a condition:

[ ${PYTHON} == "C:\Python370_x64" ]

source on GitHub

pyquickhelper.jenkinshelper.yaml_helper.infer_project_name(file_or_buffer, source)[source]

Infers a project name based on yml file.

Parameters:
Returns:

name

The function can infer a name for source in {'r', 'u'}. For source equal to 's', it returns 'unknown_string'.

source on GitHub

pyquickhelper.jenkinshelper.yaml_helper.interpret_instruction(inst, variables=None)[source]

Interprets an instruction with if statement.

Parameters:
  • inst – (str) instruction

  • variables – (dict|None)

Returns:

(str|None)

Example of a statement:

- if [ ${PYTHON} == "C:\\Python391_x64" ] then python setup.py build_sphinx fi

Another example:

- if [ ${VERSION} == "3.9" and ${DIST} == "std" ]
  then
    --CMD=$PYINT -u scikit-learn/bench_plot_polynomial_features_partial_fit.py;;
    --NAME=SKL_POLYF_PF;;
  fi

In this second syntax, lines must end with ;;. If an instruction cannot be interpreted, it is left left unchanged as the function assumes it can only be solved in a bash script.

Switch to ;; instead of ; as a instruction separator for conditional instructions.

source on GitHub

pyquickhelper.jenkinshelper.yaml_helper.load_yaml(file_or_buffer, context=None, engine='jinja2', platform=None)[source]

Loads a yml file (.yml).

Parameters:
  • file_or_buffer – string or physical file or url

  • context – variables to replace in the configuration

  • engine – see apply_template

  • platform – to join path differently based on the OS

Returns:

see PyYAML

source on GitHub

pyquickhelper.jenkinshelper.yaml_helper.ospathdirname(lp, platform=None)[source]

Simple o.path.dirname for a specific platform.

Parameters:
  • lp – path

  • platform – platform

Returns:

path

source on GitHub

pyquickhelper.jenkinshelper.yaml_helper.ospathjoin(*args, **kwargs)[source]

Simple o.path.join for a specific platform.

Parameters:
  • args – list of paths

  • kwargs – additional parameters, among them, platform (win32 or …)

Returns:

path

source on GitHub

pyquickhelper.jenkinshelper.yaml_helper.pickname(*args)[source]

Picks the first string non null in the list.

Parameters:

l – list of string

Returns:

string

source on GitHub