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

Improve code quality #62

Merged
merged 3 commits into from
May 19, 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
4 changes: 2 additions & 2 deletions ros2autodoc/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
77 changes: 41 additions & 36 deletions ros2autodoc/api/node_interface_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
12 changes: 10 additions & 2 deletions ros2autodoc/verb/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,22 @@ 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:
if not check_for_node(node, f"/{node_name}"):
print(f"Node '{node_name}' is not running and will be ignored.")
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",
)
Loading