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

Add !relative_url YAML constructor #1057

Merged
merged 3 commits into from
Oct 8, 2024
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
14 changes: 14 additions & 0 deletions doc/configuration_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ example and can be found on
`GitHub (ros-infrastructure/ros_buildfarm_config) <https://github.com/ros-infrastructure/ros_buildfarm_config>`_.


Special YAML tags
-----------------

YAML tags can be used to treat certain data in the configuration different.

The following special tags are available in ROS build farm configuration
files:

* ``!include``: parse the YAML file at the given relative URL and include it
under the node where the tag was found.
* ``!relative_url``: resolve the given relative URL to an absolute URL based
from the file in which the tag was found.


Entry point yaml
----------------

Expand Down
14 changes: 10 additions & 4 deletions ros_buildfarm/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,22 @@ def load_yaml(url):
# Resolve relative file paths from CWD
url = urljoin('file://' + os.getcwd() + '/', url)

class SafeLoaderWithInclude(yaml.SafeLoader):
class BuildfarmConfigSafeLoader(yaml.SafeLoader):

def include(self, node):
include_url = urljoin(url, self.construct_scalar(node))
include_url = self.relative_url(node)
return load_yaml(include_url)

SafeLoaderWithInclude.add_constructor('!include', SafeLoaderWithInclude.include)
def relative_url(self, node):
return urljoin(url, self.construct_scalar(node))

BuildfarmConfigSafeLoader.add_constructor(
'!include', BuildfarmConfigSafeLoader.include)
BuildfarmConfigSafeLoader.add_constructor(
'!relative_url', BuildfarmConfigSafeLoader.relative_url)

yaml_str = load_url(url)
return yaml.load(yaml_str, SafeLoaderWithInclude)
return yaml.load(yaml_str, BuildfarmConfigSafeLoader)


def get_index(url):
Expand Down
Loading