MCPcopy Index your code
hub / github.com/python/mypy / main

Function main

misc/convert-cache.py:22–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20
21
22def main() -> None:
23 parser = argparse.ArgumentParser()
24 parser.add_argument(
25 "--to-sqlite",
26 action="store_true",
27 default=False,
28 help="Convert to a sqlite cache (default: convert from)",
29 )
30 parser.add_argument(
31 "--num-shards",
32 type=int,
33 default=SQLITE_NUM_SHARDS,
34 dest="num_shards",
35 help=argparse.SUPPRESS,
36 )
37 parser.add_argument(
38 "--output_dir",
39 action="store",
40 default=None,
41 help="Output cache location (default: same as input)",
42 )
43 parser.add_argument("input_dir", help="Input directory for the cache")
44 args = parser.parse_args()
45
46 input_dir = args.input_dir
47 output_dir = args.output_dir or input_dir
48 num_shards = args.num_shards
49 assert os.path.isdir(output_dir), f"{output_dir} is not a directory"
50 if args.to_sqlite:
51 input: MetadataStore = FilesystemMetadataStore(input_dir)
52 output: MetadataStore = SqliteMetadataStore(output_dir, num_shards=num_shards)
53 else:
54 if num_shards <= 1:
55 db_files = [os.path.join(input_dir, "cache.db")]
56 else:
57 db_files = [os.path.join(input_dir, f"cache.{i}.db") for i in range(num_shards)]
58 for fnam in db_files:
59 msg = f"{fnam} does not exist"
60 if not re.match(r"[0-9]+\.[0-9]+$", os.path.basename(input_dir)):
61 msg += f" (are you missing Python version at the end, e.g. {input_dir}/3.11)"
62 assert os.path.isfile(fnam), msg
63 input = SqliteMetadataStore(input_dir, num_shards=num_shards)
64 output = FilesystemMetadataStore(output_dir)
65
66 for s in input.list_all():
67 if s.endswith((".json", ".ff")):
68 assert output.write(
69 s, input.read(s), input.getmtime(s)
70 ), f"Failed to write cache file {s}!"
71 output.commit()
72
73
74if __name__ == "__main__":

Callers 1

convert-cache.pyFile · 0.70

Calls 13

list_allMethod · 0.95
writeMethod · 0.95
readMethod · 0.95
getmtimeMethod · 0.95
commitMethod · 0.95
SqliteMetadataStoreClass · 0.90
rangeClass · 0.85
add_argumentMethod · 0.80
isdirMethod · 0.45
joinMethod · 0.45
isfileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…