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
Changes from 1 commit
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: 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