Skip to content

Commit 672052a

Browse files
author
Chris Elion
authored
Automate meta file check (#2133)
* Script to validate .meta files are set up correctly * Add command to CI * don't gitignore Gizmos, add .meta * Move to utils directory
1 parent 04168ae commit 672052a

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

.circleci/config.yml

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ jobs:
4848
black --check ml-agents-envs
4949
black --check gym-unity
5050
51+
- run:
52+
name: Verify there are no hidden/missing metafiles.
53+
# Renaming files or deleting files can leave metafiles behind that makes Unity very unhappy.
54+
command: |
55+
. venv/bin/activate
56+
python utils/validate_meta_files.py
57+
5158
- store_test_results:
5259
path: test-reports
5360

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
/UnitySDK/[Uu]nity[Pp]ackage[Mm]anager/
88
/UnitySDK/Assets/AssetStoreTools*
99
/UnitySDK/Assets/Plugins*
10-
/UnitySDK/Assets/Gizmos*
1110
/UnitySDK/Assets/Demonstrations*
1211

1312
# Tensorflow Model Info

UnitySDK/Assets/Gizmos.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

utils/__init__.py

Whitespace-only changes.

utils/validate_meta_files.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import json
2+
import os
3+
4+
5+
def main():
6+
asset_path = "UnitySDK/Assets"
7+
meta_suffix = ".meta"
8+
python_suffix = ".py"
9+
10+
num_matched = 0
11+
12+
unmatched = set()
13+
14+
for root, dirs, files in os.walk(asset_path):
15+
dirs = set(dirs)
16+
files = set(files)
17+
18+
combined = dirs | files
19+
for f in combined:
20+
if f.endswith(python_suffix):
21+
# Probably this script; skip it
22+
continue
23+
24+
# We expect each non-.meta file to have a .meta file, and each .meta file to have a non-.meta file
25+
if f.endswith(meta_suffix):
26+
expected = f.replace(meta_suffix, "")
27+
else:
28+
expected = f + meta_suffix
29+
30+
if expected not in combined:
31+
unmatched.add(os.path.join(root, f))
32+
else:
33+
num_matched += 1
34+
35+
if unmatched:
36+
raise Exception(f"Mismatch between expected files and their .meta files: {sorted(unmatched)}")
37+
38+
print(f"Found {num_matched} correctly matched files")
39+
40+
41+
if __name__ == "__main__":
42+
main()

0 commit comments

Comments
 (0)