MCPcopy Create free account
hub / github.com/apple/coremltools / preprocess

Function preprocess

mlmodel/docs/preprocess.py:7–30  ·  view source on GitHub ↗

splits _sources/reference.rst into separate files

()

Source from the content-addressed store, hash-verified

5
6
7def preprocess():
8 "splits _sources/reference.rst into separate files"
9
10 text = open("./_sources/reference.rst", "r").read()
11 os.remove("./_sources/reference.rst")
12
13 if not os.path.exists("./_sources/reference"):
14 os.makedirs("./_sources/reference")
15
16 def pairwise(iterable):
17 "s -> (s0, s1), (s2, s3), (s4, s5), ..."
18
19 iteration = iter(iterable)
20 return izip(iteration, iteration)
21
22 sections = map(str.strip, re.split(r"<!--\s*(.+)\s*-->", text))
23 for section, content in pairwise(sections[1:]):
24 if section.endswith(".proto"):
25 section_name = section[: -len(".proto")]
26 file_name = "./_sources/reference/{0}.rst".format(section_name)
27 with open(file_name, "w") as f:
28 f.truncate()
29 f.write(content)
30 f.close()
31
32
33if __name__ == "__main__":

Callers 1

preprocess.pyFile · 0.85

Calls 8

openFunction · 0.85
pairwiseFunction · 0.85
lenFunction · 0.50
readMethod · 0.45
removeMethod · 0.45
formatMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected