MCPcopy Create free account
hub / github.com/AdaCompNUS/summit / generate_pb_docs

Function generate_pb_docs

PythonAPI/docs/bp_doc_gen.py:117–172  ·  view source on GitHub ↗

Generates markdown file

()

Source from the content-addressed store, hash-verified

115
116
117def generate_pb_docs():
118 """Generates markdown file"""
119
120 print('Generating API blueprint documentation...')
121 client = carla.Client('127.0.0.1', 2000)
122 client.set_timeout(2.0)
123 world = client.get_world()
124
125 bp_dict = {}
126 blueprints = [bp for bp in world.get_blueprint_library().filter('*')] # Returns list of all blueprints
127 blueprint_ids = [bp.id for bp in world.get_blueprint_library().filter('*')] # Returns list of all blueprint ids
128
129 # Creates a dict key = walker, static, prop, vehicle, sensor, controller; value = [bp_id, blueprint]
130 for bp_id in sorted(blueprint_ids):
131 bp_type = bp_id.split('.')[0]
132 value = []
133 for bp in blueprints:
134 if bp.id == bp_id:
135 value = [bp_id, bp]
136 if bp_type in bp_dict:
137 bp_dict[bp_type].append(value)
138 else:
139 bp_dict[bp_type] = [value]
140
141 # Actual documentation
142 md = MarkdownFile()
143 md.not_title('Blueprint Library')
144 md.textn(
145 "The Blueprint Library ([`carla.BlueprintLibrary`](../python_api/#carlablueprintlibrary-class)) " +
146 "is a summary of all [`carla.ActorBlueprint`](../python_api/#carla.ActorBlueprint) " +
147 "and its attributes ([`carla.ActorAttribute`](../python_api/#carla.ActorAttribute)) " +
148 "available to the user in CARLA.")
149
150 md.textn("\nHere is an example code for printing all actor blueprints and their attributes:")
151 md.textn(md.code_block("blueprints = [bp for bp in world.get_blueprint_library().filter('*')]\n"
152 "for blueprint in blueprints:\n"
153 " print(blueprint.id)\n"
154 " for attr in blueprint:\n"
155 " print(' - {}'.format(attr))", "py"))
156 md.textn("Check out our [blueprint tutorial](../python_api_tutorial/#blueprints).")
157
158 for key, value in bp_dict.items(): # bp types, bp's
159 md.title(3, key) # Key = walker, static, controller, sensor, vehicle
160 for bp in sorted(value): # Value = bp[0]= name bp[1]= blueprint
161 md.list_pushn(bold(color(COLOR_LIST, bp[0]))) # bp name
162 md.list_push(bold('Attributes:') + '\n')
163 for attr in sorted(bp[1], key=lambda x: x.id): # for attribute in blueprint
164 md.list_push(code(attr.id))
165 md.text(' ' + parentheses(italic(str(attr.type))))
166 if attr.is_modifiable:
167 md.text(sub(italic(' – Modifiable')))
168 md.list_popn()
169 md.list_pop()
170 md.list_pop()
171 md.list_pop()
172 return md.data()
173
174

Callers 1

mainFunction · 0.85

Calls 15

set_timeoutMethod · 0.95
not_titleMethod · 0.95
textnMethod · 0.95
code_blockMethod · 0.95
titleMethod · 0.95
list_pushnMethod · 0.95
list_pushMethod · 0.95
textMethod · 0.95
list_popnMethod · 0.95
list_popMethod · 0.95
dataMethod · 0.95
MarkdownFileClass · 0.70

Tested by

no test coverage detected