Skip to content

Commit 6969ff7

Browse files
Add another missing gitignored file, and remove gitignore filter for tests/
1 parent 13e08fd commit 6969ff7

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

.gitignore

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@
44
.pytest_cache
55
.python-version
66
build/
7-
betterproto/tests/*.bin
8-
betterproto/tests/*_pb2.py
9-
betterproto/tests/*.py
10-
!betterproto/tests/generate.py
11-
!betterproto/tests/test_*.py
7+
betterproto/tests/output_*
128
**/__pycache__
139
dist
1410
**/*.egg-info
1511
output
16-
betterproto/tests/output_*
1712
.idea

betterproto/tests/util.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import os
2+
import subprocess
3+
from typing import Generator
4+
5+
os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
6+
7+
root_path = os.path.dirname(os.path.realpath(__file__))
8+
inputs_path = os.path.join(root_path, 'inputs')
9+
10+
if os.name == 'nt':
11+
plugin_path = os.path.join(root_path, '..', 'plugin.bat')
12+
else:
13+
plugin_path = os.path.join(root_path, '..', 'plugin.py')
14+
15+
16+
def get_files(path, end: str) -> Generator[str, None, None]:
17+
for r, dirs, files in os.walk(path):
18+
for filename in [f for f in files if f.endswith(end)]:
19+
yield os.path.join(r, filename)
20+
21+
22+
def get_directories(path):
23+
for root, directories, files in os.walk(path):
24+
for directory in directories:
25+
yield directory
26+
27+
28+
def relative(file: str, path: str):
29+
return os.path.join(os.path.dirname(file), path)
30+
31+
32+
def read_relative(file: str, path: str):
33+
with open(relative(file, path)) as fh:
34+
return fh.read()
35+
36+
37+
def protoc_plugin(path: str, output_dir: str):
38+
subprocess.run(
39+
f"protoc --plugin=protoc-gen-custom={plugin_path} --custom_out={output_dir} --proto_path={path} {path}/*.proto",
40+
shell=True,
41+
)
42+
43+
44+
def protoc_reference(path: str, output_dir: str):
45+
subprocess.run(f"protoc --python_out={output_dir} --proto_path={path} {path}/*.proto", shell=True)
46+

0 commit comments

Comments
 (0)