Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yaml_preprocessor: add support for $include and $[include] #93

Merged

Conversation

pbelanger-avid
Copy link
Contributor

@pbelanger-avid pbelanger-avid commented Jan 18, 2023

This commit adds support for a special $include keyword in the YAML preprocessor. This new keyword is similar to the existing $eval keyword and allows building the robot.model.yaml up from multiple separate files.

$include can process both absolute filenames as well as relative filenames, which are interpreted relative to the file currently being processed.

The included document is also processed by the YAML preprocessor, and so can include nested $includes and $evals.

This commit also updates the documentation and tests.

Some usage examples:

# Example of $include: 
# project/param/parent.yaml
foo: 123
bar: $include child.yaml # Looks in current directory (project/param/) for relative filenames
baz: $include /absolute/path/to/project/param/child.yaml # or an absolute path can be specified

# project/param/child.yaml
a: 1
b: 2

# result of YAML preprocessing parent.yaml:
foo: 123
bar:
  a: 1
  b: 2
baz:
  a: 1
  b: 2

# example of $[include]: 
# parent.yaml
foo:
  - first
  - $[include] child.yaml
  - last

#child.yaml
one
---
a: foo
b: baz
---
three

# result of YAML preprocessing of parent.yaml:
foo:
  - first
  - one
  - a: foo
    b: baz
  - three
  - last

This commit adds support for a special `$include` keyword in the YAML
preprocessor. This new keyword is similar to the existing `$eval` keyword
and allows building the `robot.model.yaml` up from multiple separate files.

$include can process both absolute filenames as well as relative filenames,
which are interpreted relative to the file currently being processed.

The included document is also processed by the YAML preprocessor, and so can
include nested `$include`s and `$eval`s.

This commit also updates the documentation and tests.
@pbelanger-avid
Copy link
Contributor Author

Note: currently this does not detect or handle recursive includes. (eg. a.yaml including itself)

* Add sequence include keyword $[include], which generates into one or more
  sequence elements
* One element is generated for each separate YAML document in the included
  file (separated by '---')
* Update tests
* Update docs
@pbelanger-avid
Copy link
Contributor Author

The second commit adds a second "sequence include" form, $[include], that can be used to dynamically populate sequences (such as the plugin list in my particular use case) with YAML elements pulled from individual documents in the included file.

@pbelanger-avid pbelanger-avid changed the title yaml_preprocessor: add support for $include yaml_preprocessor: add support for $include and $[include] Jan 18, 2023
@josephduchesne josephduchesne merged commit 631168f into avidbots:master Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants