1515
1616import argparse
1717
18+ from mypy .defaults import SQLITE_NUM_SHARDS
1819from mypy .metastore import FilesystemMetadataStore , MetadataStore , SqliteMetadataStore
1920
2021
@@ -26,6 +27,13 @@ def main() -> None:
2627 default = False ,
2728 help = "Convert to a sqlite cache (default: convert from)" ,
2829 )
30+ parser .add_argument (
31+ "--num-shards" ,
32+ type = int ,
33+ default = SQLITE_NUM_SHARDS ,
34+ dest = "num_shards" ,
35+ help = argparse .SUPPRESS ,
36+ )
2937 parser .add_argument (
3038 "--output_dir" ,
3139 action = "store" ,
@@ -37,17 +45,23 @@ def main() -> None:
3745
3846 input_dir = args .input_dir
3947 output_dir = args .output_dir or input_dir
48+ num_shards = args .num_shards
4049 assert os .path .isdir (output_dir ), f"{ output_dir } is not a directory"
4150 if args .to_sqlite :
4251 input : MetadataStore = FilesystemMetadataStore (input_dir )
43- output : MetadataStore = SqliteMetadataStore (output_dir )
52+ output : MetadataStore = SqliteMetadataStore (output_dir , num_shards = num_shards )
4453 else :
45- fnam = os .path .join (input_dir , "cache.db" )
46- msg = f"{ fnam } does not exist"
47- if not re .match (r"[0-9]+\.[0-9]+$" , os .path .basename (input_dir )):
48- msg += f" (are you missing Python version at the end, e.g. { input_dir } /3.11)"
49- assert os .path .isfile (fnam ), msg
50- input , output = SqliteMetadataStore (input_dir ), FilesystemMetadataStore (output_dir )
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 )
5165
5266 for s in input .list_all ():
5367 if s .endswith ((".json" , ".ff" )):
0 commit comments