From 743c437f9df6c2e9f9ae30beeaee17362cfb4080 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Tue, 25 Jun 2024 10:05:29 -0500 Subject: [PATCH 1/2] Add !relative_url YAML constructor The purpose of this constructor is to support relative URL resolution in arbitrary locations in the buildfarm's configuration YAML. Some fields in the config already implicitly do this (such as the buildfile references from the index), but this will add support for any field to contain a relative URL. --- ros_buildfarm/config/__init__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ros_buildfarm/config/__init__.py b/ros_buildfarm/config/__init__.py index dce7a7bbb..493deb888 100644 --- a/ros_buildfarm/config/__init__.py +++ b/ros_buildfarm/config/__init__.py @@ -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): From b34de5df6ffe48f094da4d367fa2725af8e1f2f4 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Tue, 8 Oct 2024 12:15:49 -0500 Subject: [PATCH 2/2] Add documentation for special YAML tags --- doc/configuration_options.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/doc/configuration_options.rst b/doc/configuration_options.rst index 12f356cb8..a27e3148f 100644 --- a/doc/configuration_options.rst +++ b/doc/configuration_options.rst @@ -10,6 +10,20 @@ example and can be found on `GitHub (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 ----------------