From 7e93f0d23e776cc7268cc41a1b3dc899d6f40d07 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelaziz Date: Sun, 19 May 2024 17:37:24 +0000 Subject: [PATCH 1/3] Decrease the number of parameters to the function --- ros2autodoc/api/__init__.py | 4 ++-- ros2autodoc/verb/generate.py | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ros2autodoc/api/__init__.py b/ros2autodoc/api/__init__.py index 56d5b30..d64efa0 100644 --- a/ros2autodoc/api/__init__.py +++ b/ros2autodoc/api/__init__.py @@ -47,12 +47,12 @@ def get_nodes(package_name): return nodes -def document_node(node, package_name, node_name, path, file_name="/README.md"): +def document_node(node, package_name, node_name, file_path): """Document the given node.""" interface_collector = NodeInterfaceCollector(node, node_name) node_interface = interface_collector.get_interfaces() writer = DocWriter(package_name, node_name, node_interface) - writer.write(path + file_name) + writer.write(file_path) def check_node_documentation(node, node_name, file_path): diff --git a/ros2autodoc/verb/generate.py b/ros2autodoc/verb/generate.py index bf3750d..0328c82 100644 --- a/ros2autodoc/verb/generate.py +++ b/ros2autodoc/verb/generate.py @@ -41,6 +41,9 @@ def add_arguments(self, parser, cli_name): def main(self, *, args): if args.package_name and not check_for_package(args.package_name): return f"Package '{args.package_name}' could not be found." + + # Ensure no trailing slash + args.output_dir = args.output_dir.rstrip('/') with NodeStrategy(args) as node: for node_name in args.nodes: @@ -49,7 +52,12 @@ def main(self, *, args): continue if args.seperate_files: document_node( - node, None, node_name, args.output_dir, f"/{node_name}.md" + node, None, node_name, f"{args.output_dir}/{node_name}.md" ) else: - document_node(node, args.package_name, node_name, args.output_dir) + document_node( + node, + args.package_name, + node_name, + f"{args.output_dir}/README.md", + ) From ed0dcc52c44fe544f6ad28c56190c102f3723a86 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 19 May 2024 17:37:56 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- ros2autodoc/verb/generate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ros2autodoc/verb/generate.py b/ros2autodoc/verb/generate.py index 0328c82..685791a 100644 --- a/ros2autodoc/verb/generate.py +++ b/ros2autodoc/verb/generate.py @@ -41,9 +41,9 @@ def add_arguments(self, parser, cli_name): def main(self, *, args): if args.package_name and not check_for_package(args.package_name): return f"Package '{args.package_name}' could not be found." - + # Ensure no trailing slash - args.output_dir = args.output_dir.rstrip('/') + args.output_dir = args.output_dir.rstrip("/") with NodeStrategy(args) as node: for node_name in args.nodes: From f637aa99da9ffa9e6ce29bd6a0e9be138df103d6 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelaziz Date: Sun, 19 May 2024 18:00:16 +0000 Subject: [PATCH 3/3] code refactoring --- ros2autodoc/api/node_interface_collector.py | 77 +++++++++++---------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/ros2autodoc/api/node_interface_collector.py b/ros2autodoc/api/node_interface_collector.py index a803652..959add6 100644 --- a/ros2autodoc/api/node_interface_collector.py +++ b/ros2autodoc/api/node_interface_collector.py @@ -57,61 +57,66 @@ def get_interfaces(self): def _query_interfaces(self): # Parameters param_names, params_map, desciption_map = self._get_parameters() - if len(param_names) > 0: - for param in param_names: - if param not in PARAMS_TO_IGNORE: - param_type = params_map[param] - param_description = desciption_map[param] - if not param_description: - param_description = TODO - self.interfaces["parameters"][param] = { - "type": param_type, - "description": param_description, - } + if param_names: + self._add_parameter_info(param_names, params_map, desciption_map) + # Subscribers subscribers = get_subscriber_info( node=self.node, remote_node_name=self.node_name, include_hidden=False ) - if len(subscribers) > 0: - for sub in subscribers: - if sub.name not in SUBSCRIBERS_TO_IGNORE: - self.interfaces["subscribers"][sub.name] = { - "type": ", ".join(sub.types), - "description": TODO, - } + if subscribers: + self._add_interface_info( + self.interfaces["subscribers"], subscribers, SUBSCRIBERS_TO_IGNORE + ) + # Publishers publishers = get_publisher_info( node=self.node, remote_node_name=self.node_name, include_hidden=False ) - if len(publishers) > 0: - for pub in publishers: - if pub.name not in PUBLISHERS_TO_IGNORE: - self.interfaces["publishers"][pub.name] = { - "type": ", ".join(pub.types), - "description": TODO, - } + if publishers: + self._add_interface_info( + self.interfaces["publishers"], publishers, PUBLISHERS_TO_IGNORE + ) + # Services service_servers = get_service_server_info( node=self.node, remote_node_name=self.node_name, include_hidden=False ) - if len(service_servers) > 0: - for srv in service_servers: - if not self._ignore_service(self.node_name, srv.name): - self.interfaces["services"][srv.name] = { - "type": ", ".join(srv.types), - "description": TODO, - } + if service_servers: + filtered_services = [ + srv + for srv in service_servers + if not self._ignore_service(self.node_name, srv.name) + ] + self._add_interface_info(self.interfaces["services"], filtered_services, []) + # Actions actions_servers = get_action_server_info( node=self.node, remote_node_name=self.node_name, include_hidden=False ) - if len(actions_servers) > 0: - for action in actions_servers: - self.interfaces["actions"][action.name] = { - "type": ", ".join(action.types), + if actions_servers: + self._add_interface_info(self.interfaces["actions"], actions_servers, []) + + def _add_interface_info(self, interface_dict, items, ignore_list): + for item in items: + if item.name not in ignore_list: + interface_dict[item.name] = { + "type": ", ".join(item.types), "description": TODO, } + def _add_parameter_info(self, param_names, params_map, desciption_map): + for param in param_names: + if param not in PARAMS_TO_IGNORE: + param_type = params_map[param] + param_description = desciption_map[param] + if not param_description: + param_description = TODO + self.interfaces["parameters"][param] = { + "type": param_type, + "description": param_description, + } + def _get_parameters(self): name_to_type_map = {} name_to_description_map = {}