15
15
"power_sensor" : "powersensor" ,
16
16
"generic_service" : "generic" ,
17
17
"base_remote_control" : "baseremotecontrol" ,
18
- "data_manager" : "datamanager"
18
+ "data_manager" : "datamanager" ,
19
+ "data" : "DataClient" ,
20
+ "dataset" : "DataClient"
19
21
}
20
22
21
23
## Ignore these specific APIs if they error, are deprecated, etc:
@@ -85,7 +87,8 @@ def parse(self, type, viam_resources):
85
87
elif type == "robot" :
86
88
url = f"{ self .scrape_url } /go.viam.com/rdk/{ type } "
87
89
elif type == "app" :
88
- continue
90
+ url = f"{ self .scrape_url } /go.viam.com/rdk/{ type } "
91
+ print (url )
89
92
90
93
self .go_methods [type ][resource ] = {}
91
94
@@ -99,36 +102,107 @@ def parse(self, type, viam_resources):
99
102
soup = make_soup (url )
100
103
101
104
## Get a raw dump of all go methods by interface for each resource:
102
- go_methods_raw = soup .find_all (
103
- lambda tag : tag .name == 'div'
104
- and tag .get ('class' ) == ['Documentation-declaration' ]
105
- and tag .pre .text .startswith ('type' )
106
- and "interface {" in tag .pre .text )
105
+ if type == "app" :
106
+ ## For app resources, look for client type definitions instead of interfaces
107
+ go_methods_raw = soup .find_all (
108
+ lambda tag : tag .name == 'div'
109
+ and tag .get ('class' ) == ['Documentation-declaration' ]
110
+ and tag .pre .text .startswith ('func (' )
111
+ and any (client in tag .pre .text for client in ["DataClient" , "AppClient" , "BillingClient" , "MLTrainingClient" ]))
112
+ else :
113
+ go_methods_raw = soup .find_all (
114
+ lambda tag : tag .name == 'div'
115
+ and tag .get ('class' ) == ['Documentation-declaration' ]
116
+ and tag .pre .text .startswith ('type' )
117
+ and "interface {" in tag .pre .text )
118
+
119
+ if type == "app" :
120
+ ## For app resources, process function definitions directly
121
+ for func_div in go_methods_raw :
122
+ ## Extract method name from function definition
123
+ func_text = func_div .find ('pre' ).text
124
+ if 'DataClient' in func_text :
125
+ method_name = func_text .split (') ' )[1 ].split ('(' )[0 ]
126
+
127
+ ## Create new empty dictionary for this specific method
128
+ this_method_dict = {}
107
129
108
- # some resources have more than one interface:
109
- for resource_interface in go_methods_raw :
130
+ ## Check if this method is mapped to the current resource in the CSV file
131
+ method_mapped_to_resource = False
132
+ with open (self .proto_map_file , 'r' ) as f :
133
+ for row in f :
134
+ if not row .startswith ('#' ) \
135
+ and row .startswith (resource + ',' ) \
136
+ and row .split (',' )[4 ] == method_name :
137
+ method_mapped_to_resource = True
138
+ break
139
+
140
+ ## Only include methods that are mapped to this resource
141
+ if method_mapped_to_resource :
142
+
143
+ ## Exclude unwanted Go methods:
144
+ check_method_name = resource + '.' + method_name
145
+ if not check_method_name in go_ignore_apis :
146
+
147
+ ## Debug: Print found methods for app resources
148
+ if type == "app" :
149
+ print (f"Found method: { method_name } for resource: { resource } " )
150
+
151
+ ## Look up method_name in proto_map file, and return matching proto:
152
+ with open (self .proto_map_file , 'r' ) as f :
153
+ for row in f :
154
+ if not row .startswith ('#' ) \
155
+ and row .startswith (resource + ',' ) \
156
+ and row .split (',' )[4 ] == method_name :
157
+ this_method_dict ["proto" ] = row .split (',' )[1 ]
158
+
159
+ ## Extract method description
160
+ method_description = ""
161
+ if func_div .find ('p' ):
162
+ method_description = func_div .find ('p' ).text .replace ("\n " , " " )
163
+ this_method_dict ["description" ] = method_description
110
164
111
- ## Determine the interface name, which we need for the method_link:
112
- interface_name = resource_interface . find ( 'pre' ). text . splitlines ()[ 0 ]. removeprefix ( 'type ' ). removesuffix ( ' interface {' )
165
+ ## Extract method usage
166
+ this_method_dict [ "usage" ] = func_text . replace ( " \t " , " " ). lstrip (). rstrip ( )
113
167
114
- ## Exclude unwanted Go interfaces:
115
- check_interface_name = 'interface.' + interface_name
116
- if not check_interface_name in go_ignore_apis :
168
+ ## Set method link
169
+ if self .staging :
170
+ this_method_dict ["method_link" ] = str (url + '#DataClient.' + method_name ).replace (self .scrape_url , 'https://pkg.go.dev' )
171
+ else :
172
+ this_method_dict ["method_link" ] = url + '#DataClient.' + method_name
117
173
118
- ## Loop through each method found for this interface:
119
- for tag in resource_interface . find_all ( 'span' , attrs = { "data-kind" : "method" }):
174
+ ## Store the method
175
+ self . go_methods [ type ][ resource ][ method_name ] = this_method_dict
120
176
121
- ## Create new empty dictionary for this specific method, to be appended to ongoing go_methods dictionary,
122
- ## in form: go_methods[type][resource][method_name] = this_method_dict
123
- this_method_dict = {}
177
+ else :
178
+ # some resources have more than one interface:
179
+ for resource_interface in go_methods_raw :
180
+
181
+ ## Determine the interface name, which we need for the method_link:
182
+ interface_name = resource_interface .find ('pre' ).text .splitlines ()[0 ].removeprefix ('type ' ).removesuffix (' interface {' )
183
+
184
+ ## Exclude unwanted Go interfaces:
185
+ check_interface_name = 'interface.' + interface_name
186
+ if not check_interface_name in go_ignore_apis :
187
+
188
+ ## Loop through each method found for this interface:
189
+ for tag in resource_interface .find_all ('span' , attrs = {"data-kind" : "method" }):
124
190
125
- tag_id = tag .get ('id' )
126
- method_name = tag .get ('id' ).split ('.' )[1 ]
191
+ ## Create new empty dictionary for this specific method, to be appended to ongoing go_methods dictionary,
192
+ ## in form: go_methods[type][resource][method_name] = this_method_dict
193
+ this_method_dict = {}
194
+
195
+ tag_id = tag .get ('id' )
196
+ method_name = tag .get ('id' ).split ('.' )[1 ]
127
197
128
198
## Exclude unwanted Go methods:
129
199
check_method_name = resource + '.' + method_name
130
200
if not check_method_name in go_ignore_apis :
131
201
202
+ ## Debug: Print found methods for app resources
203
+ if type == "app" :
204
+ print (f"Found method: { method_name } for resource: { resource } " )
205
+
132
206
## Look up method_name in proto_map file, and return matching proto:
133
207
with open (self .proto_map_file , 'r' ) as f :
134
208
for row in f :
@@ -141,7 +215,11 @@ def parse(self, type, viam_resources):
141
215
## Split by method span, throwing out remainder of span tag, catching cases where
142
216
## id is first attr or data-kind is first attr, and slicing to omit the first match,
143
217
## which is the opening of the method span tag, not needed:
144
- this_method_raw1 = regex .split (r'id="' + tag_id + '"' , str (resource_interface ))[1 ].removeprefix ('>' ).removeprefix (' data-kind="method">' ).lstrip ()
218
+ split_result = regex .split (r'id="' + tag_id + '"' , str (resource_interface ))
219
+ if len (split_result ) > 1 :
220
+ this_method_raw1 = split_result [1 ].removeprefix ('>' ).removeprefix (' data-kind="method">' ).lstrip ()
221
+ else :
222
+ continue
145
223
146
224
## Then, omit all text that begins a new method span, and additionally remove trailing
147
225
## element closers for earlier tags we spliced into (pre and span):
@@ -347,9 +425,5 @@ def parse(self, type, viam_resources):
347
425
if resource == "generic_service" :
348
426
self .go_methods [type ][resource ]['DoCommand' ]['code_sample' ] = 'myGenericService, err := generic.FromRobot(machine, "my_generic_service")\n \n command := map[string]interface{}{"cmd": "test", "data1": 500}\n result, err := myGenericService.DoCommand(context.Background(), command)\n '
349
427
350
- # elif type == "app":
351
- # ##Go SDK has no APP API!
352
- # pass
353
-
354
428
return self .go_methods
355
429
0 commit comments