Skip to main content

pyyaml loader. With this loader you can inject (include) other yaml files either from local file system or from public web or from already constructed sections of the yaml.

Project description

yaml-injection

usage

in python

import yaml
from yaml_injection import InjectionLoader

with open(file_path) as in_:
    data = yaml.load(in_, InjectionLoader)

in yaml

The key word is !inject.

There are two types of syntax: simple and extended.

simple syntax

!inject file: path to file in local file system
!inject ref: section subsection 

ref is a keys leading to section separated by space.

* Yep it will works only if keys does not contain spaces.

!inject url: public url with yaml file 

extended syntax

WARNING: A SPACE SYMBOL AFTER !inject AND BEFORE : IS MANDATORY!!

!inject : 
    file: path to file in local file system
    url: public url with yaml file 
    ref: section subsection 

Both simple and extended syntax accept lists in file, url and ref sections.

examples

Examples are gotten from tests.

example 1

sub.yaml

sub_only: sub_only
both_files: both_files_value_from_sub
non_map_object:
  - sub
non_map_only_sub:
  - sub_only
both_files_map:
  sub_only: sub_only
  both_files: both_files_value_from_sub
deep:
  deep:
    deep:
      map:
        sub_only: sub_only
        both_files: both_files_value_from_sub

main.yml

!inject file: sub.yml

main_only: main_only
both_files: both_files_value_from_main
both_files_map:
  both_files: both_files_value_from_main
  main_only: main_only_value_from_main
deep:
  deep:
    deep:
      map:
        main_only: main_only
        both_files: both_files_value_from_main
non_map_object:
  - main
non_map_only_main:
  - main_only

will be loaded as:

both_files: both_files_value_from_main
both_files_map:
  both_files: both_files_value_from_main
  main_only: main_only_value_from_main
  sub_only: sub_only
main_only: main_only
sub_only: sub_only
deep:
  deep:
    deep:
      map:
        main_only: main_only
        both_files: both_files_value_from_main
        sub_only: sub_only
non_map_object:
  - main
non_map_only_main:
  - main_only
non_map_only_sub:
  - sub_only

example 2

sections:
  sub:
    common:
      variables:
        job_name: sub_name
        script: sub

    job_1:
      only:
        - refs
      script:
        - make build
        - make start

    job_2:
      except:
        - tags
      script:
        - make build
        - make start

main:
  !inject :
    ref: sections sub

  common:
    variables:
      script: main
      runner: main_runner

  job_1:
    only:
      - release

  job_2:
    before_script:
      - make prepare

will be loaded as:

main:
  common:
    variables:
      job_name: sub_name
      runner: main_runner
      script: main
  job_1:
    only:
    - release
    script:
    - make build
    - make start
  job_2:
    before_script:
    - make prepare
    except:
    - tags
    script:
    - make build
    - make start
sections:
  sub:
    common:
      variables:
        job_name: sub_name
        script: sub
    job_1:
      only:
      - refs
      script:
      - make build
      - make start
    job_2:
      except:
      - tags
      script:
      - make build
      - make start

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yaml-injection-0.0.4.tar.gz (4.0 kB view details)

Uploaded Source

File details

Details for the file yaml-injection-0.0.4.tar.gz.

File metadata

  • Download URL: yaml-injection-0.0.4.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for yaml-injection-0.0.4.tar.gz
Algorithm Hash digest
SHA256 6afef9b80e121348e3a1585be9e1c95f5db9376eb2bb5952210ba2cb8fd01f89
MD5 214009e15731e1b4a32e229e0b524637
BLAKE2b-256 8777c7f8afa86658733e302c48b856026fa1b628fe03290436b6e006d20418a4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page