8000 Clear output directories before generating python files · arpitjain799/python-betterproto@c3f08b9 · GitHub
[go: up one dir, main page]

Skip to content

Commit c3f08b9

Browse files
Clear output directories before generating python files
1 parent 24d4489 commit c3f08b9

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

betterproto/tests/generate.py

Lines changed: 25 additions & 8 deletions
65
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python
2+
import glob
23
import os
4+
import shutil
35
import sys
46
from typing import Set
57

@@ -17,33 +19,48 @@
1719
os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
1820

1921

22+
def clear_directory(path: str):
23+
for file_or_directory in glob.glob(os.path.join(path, "*")):
24+
if os.path.isdir(file_or_directory):
25+
shutil.rmtree(file_or_directory)
26+
else:
27+
os.remove(file_or_directory)
28+
29+
2030
def generate(whitelist: Set[str]):
2131
path_whitelist = {os.path.realpath(e) for e in whitelist if os.path.exists(e)}
2232
name_whitelist = {e for e in whitelist if not os.path.exists(e)}
2333

2434
test_case_names = set(get_directories(inputs_path))
2535

2636
for test_case_name in sorted(test_case_names):
27-
test_case_path = os.path.realpath(os.path.join(inputs_path, test_case_name))
37+
test_case_input_path = os.path.realpath(
38+
os.path.join(inputs_path, test_case_name)
39+
)
2840

2941
if (
3042
whitelist
31-
and test_case_path not in path_whitelist
43+
and test_case_input_path not in path_whitelist
3244
and test_case_name not in name_whitelist
3345
):
3446
continue
3547

36-
case_output_dir_reference = os.path.join(output_path_reference, test_case_name< 8000 /span>)
37-
case_output_dir_betterproto = os.path.join(
48+
test_case_output_path_reference = os.path.join(
49+
output_path_reference, test_case_name
50+
)
51+
test_case_output_path_betterproto = os.path.join(
3852
output_path_betterproto, test_case_name
3953
)
4054

4155
print(f"Generating output for {test_case_name}")
42-
os.makedirs(case_output_dir_reference, exist_ok=True)
43-
os.makedirs(case_output_dir_betterproto, exist_ok=True)
56+
os.makedirs(test_case_output_path_reference, exist_ok=True)
57+
os.makedirs(test_case_output_path_betterproto, exist_ok=True)
58+
59+
clear_directory(test_case_output_path_reference)
60+
clear_directory(test_case_output_path_betterproto)
4461

45-
protoc_reference(test_case_path, case_output_dir_reference)
46-
protoc_plugin(test_case_path, case_output_dir_betterproto)
62+
protoc_reference(test_case_input_path, test_case_output_path_reference)
63+
protoc_plugin(test_case_input_path, test_case_output_path_betterproto)
4764

48

4966
HELP = "\n".join(

0 commit comments

Comments
 (0)
0