File size: 2,457 Bytes
05c9ac2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os


def main():
    asset_paths = [
        "Project/Assets",
        "DevProject/Assets",
        "com.unity.ml-agents",
        "com.unity.ml-agents.extensions",
    ]
    meta_suffix = ".meta"
    python_suffix = ".py"
    allow_list = frozenset(
        [
            "com.unity.ml-agents/.editorconfig",
            "com.unity.ml-agents/.gitignore",
            "com.unity.ml-agents/.npmignore",
            "com.unity.ml-agents/.git",
            "com.unity.ml-agents/Tests/.tests.json",
            "com.unity.ml-agents/.pre-commit-config.yaml",
            "com.unity.ml-agents/.pre-commit-search-and-replace.yaml",
            "com.unity.ml-agents.extensions/.gitignore",
            "com.unity.ml-agents.extensions/.npmignore",
            "com.unity.ml-agents.extensions/Tests/.tests.json",
            "com.unity.ml-agents/Samples/3DBall/.sample.json",
        ]
    )
    ignored_dirs = {
        "Documentation~",
        ".github",
        ".yamato",
    }

    num_matched = 0

    unmatched = set()

    for asset_path in asset_paths:
        for root, dirs, files in os.walk(asset_path):
            # Modifying the dirs list with topdown=True (the default) will prevent us from recursing those directories
            for ignored in ignored_dirs:
                try:
                    dirs.remove(ignored)
                except ValueError:
                    pass

            dirs = set(dirs)
            files = set(files)

            combined = dirs | files
            for f in combined:

                if f.endswith(python_suffix):
                    # Probably this script; skip it
                    continue

                full_path = os.path.join(root, f)
                if full_path in allow_list:
                    continue

                # We expect each non-.meta file to have a .meta file, and each .meta file to have a non-.meta file
                if f.endswith(meta_suffix):
                    expected = f.replace(meta_suffix, "")
                else:
                    expected = f + meta_suffix

                if expected not in combined:
                    unmatched.add(full_path)
                else:
                    num_matched += 1

    if unmatched:
        raise Exception(
            f"Mismatch between expected files and their .meta files: {sorted(unmatched)}"
        )

    print(f"Found {num_matched} correctly matched files")


if __name__ == "__main__":
    main()