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

Update YAML for RViz Config #12

Merged
merged 1 commit into from
Dec 11, 2023
Merged
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
20 changes: 10 additions & 10 deletions src/ros_introspect/components/rviz_config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from ..package import PackageFile, package_file, DependencyType
import yaml
import ruamel.yaml # For custom yaml dumping
import ruamel.yaml


my_yaml_writer = ruamel.yaml.YAML()
my_yaml_writer.indent(mapping=2, sequence=4, offset=2)
my_yaml_writer.representer.add_representer(type(None),
lambda self, data:
self.represent_scalar('tag:yaml.org,2002:null', '~')
)
rviz_yaml = ruamel.yaml.YAML()
rviz_yaml.indent(mapping=2, sequence=4, offset=2)
rviz_yaml.width = 4096
rviz_yaml.representer.add_representer(type(None),
lambda self, data:
self.represent_scalar('tag:yaml.org,2002:null', '~')
)


def get_class_dicts(entry):
Expand Down Expand Up @@ -45,7 +45,7 @@ def dictionary_subtract(alpha, beta):
class RVizConfig(PackageFile):
def __init__(self, full_path, package):
super().__init__(full_path, package)
self.contents = yaml.safe_load(open(full_path))
self.contents = rviz_yaml.load(open(full_path))

@classmethod
def is_type(cls, path):
Expand Down Expand Up @@ -73,4 +73,4 @@ def get_dependencies(self, dependency_type):

def write(self, output_path):
with open(output_path, 'w') as f:
my_yaml_writer.dump(self.contents, f, transform=lambda s: s.replace(": ''\n", ': ""\n'))
rviz_yaml.dump(self.contents, f, transform=lambda s: s.replace(": ''\n", ': ""\n'))