-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathproduce_config.py
106 lines (104 loc) · 3.5 KB
/
produce_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#
# Copyright (c) 2023 Radiance Technologies, Inc.
#
# This file is part of PRISM
# (see https://github.com/orgs/Radiance-Technologies/prism).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
#
"""
Module to produce config file.
"""
import argparse
import json
from pathlib import Path
from git import InvalidGitRepositoryError
from git.repo import Repo
if __name__ == "__main__":
parser = argparse.ArgumentParser("Repair config file generation")
parser.add_argument("cache_dir", type=str, help="Root of build cache.")
parser.add_argument(
"--repair_dir",
type=str,
default=None,
help="Root of repair directory."
" By default the checked out coq-pearls commit SHA")
parser.add_argument(
"--repo",
type=str,
help="Root of the coq-pearls repo."
" By default discovered based on parent directories of this script.",
default=None)
parser.add_argument(
"--metadata-yml",
type=str,
help="Path to metadata storage YAML file."
" By default 'dataset/metadata.yml' in the coq-pearls repo",
default=None)
parser.add_argument(
"--file",
type=str,
help="Output file."
" By default 'mine_repair_instances_config.json'"
" in the same directory as this script.",
default=None)
args = parser.parse_args()
repo = args.repo
metadata_yml = args.metadata_yml
if repo is None:
repo = Path(__file__).parent
try:
repo = Repo(path=repo)
except InvalidGitRepositoryError:
repo = Repo(path=repo, search_parent_directories=True)
working_tree_dir = repo.working_tree_dir
if working_tree_dir is None:
raise RuntimeError("Cannot produce config from bare repository")
working_tree_dir = Path(working_tree_dir)
if metadata_yml is None:
metadata_yml = str(working_tree_dir / "dataset" / "metadata.yml")
if args.repair_dir is None:
repair_dir = repo.commit().hexsha
else:
repair_dir = args.repair_dir
file = args.file or (
Path(__file__).parent / "mine_repair_instances_config.json")
config = {
"cache_root":
args.cache_dir,
"repair_instance_db_directory":
f"/workspace/pearls/repairs/{repair_dir}",
"metadata_storage_file":
metadata_yml,
"cache_format_extension":
"json",
"prepare_pairs":
"prism.data.repair.mining.prepare_label_pairs",
"repair_miner":
"prism.data.repair.instance.ProjectCommitDataRepairInstance",
"changeset_miner":
"prism.data.repair.instance.ProjectCommitDataErrorInstance.default_changeset_miner",
"serial":
False,
"max_workers":
64,
"logging_level":
"DEBUG",
"skip_errors":
True,
"fast":
True
}
json.dump(config, open(file, "w"))