MCPcopy Index your code
hub / github.com/googleapis/google-api-python-client / scan_readme_files

Function scan_readme_files

samples-index.py:158–196  ·  view source on GitHub ↗

Scans all subdirs of dirname for README files. Args: dirname: string, name of directory to walk. Returns: (samples, keyword_set): list of information about all samples, the union of all keywords found.

(dirname)

Source from the content-addressed store, hash-verified

156
157
158def scan_readme_files(dirname):
159 """Scans all subdirs of dirname for README files.
160
161 Args:
162 dirname: string, name of directory to walk.
163
164 Returns:
165 (samples, keyword_set): list of information about all samples, the union
166 of all keywords found.
167 """
168 samples = []
169 keyword_set = set()
170
171 for root, dirs, files in os.walk(dirname):
172 if "README" in files:
173 filename = os.path.join(root, "README")
174 with open(filename, "r") as f:
175 content = f.read()
176 lines = content.splitlines()
177 desc = " ".join(itertools.takewhile(lambda x: x, lines))
178 api = get_lines("api", lines)
179 keywords = get_lines("keywords", lines)
180 uri = get_lines("uri", lines)
181 if not uri:
182 uri = None
183
184 for k in keywords:
185 if k not in KEYWORDS:
186 raise ValueError(
187 "%s is not a valid keyword in file %s" % (k, filename)
188 )
189 keyword_set.update(keywords)
190 if not api:
191 api = [None]
192 samples.append((api[0], keywords, root[1:], desc, uri))
193
194 samples.sort()
195
196 return samples, keyword_set
197
198
199def main():

Callers 1

mainFunction · 0.85

Calls 3

get_linesFunction · 0.85
readMethod · 0.80
updateMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…