From 6969ff7ff6531b7cf5326596370c4acf29861939 Mon Sep 17 00:00:00 2001 From: boukeversteegh Date: Fri, 22 May 2020 15:34:25 +0200 Subject: [PATCH] Add another missing gitignored file, and remove gitignore filter for tests/ --- .gitignore | 7 +----- betterproto/tests/util.py | 46 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 betterproto/tests/util.py diff --git a/.gitignore b/.gitignore index a2d3d32..dd22728 100644 --- a/.gitignore +++ b/.gitignore @@ -4,14 +4,9 @@ .pytest_cache .python-version build/ -betterproto/tests/*.bin -betterproto/tests/*_pb2.py -betterproto/tests/*.py -!betterproto/tests/generate.py -!betterproto/tests/test_*.py +betterproto/tests/output_* **/__pycache__ dist **/*.egg-info output -betterproto/tests/output_* .idea \ No newline at end of file diff --git a/betterproto/tests/util.py b/betterproto/tests/util.py new file mode 100644 index 0000000..c65e2a6 --- /dev/null +++ b/betterproto/tests/util.py @@ -0,0 +1,46 @@ +import os +import subprocess +from typing import Generator + +os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python" + +root_path = os.path.dirname(os.path.realpath(__file__)) +inputs_path = os.path.join(root_path, 'inputs') + +if os.name == 'nt': + plugin_path = os.path.join(root_path, '..', 'plugin.bat') +else: + plugin_path = os.path.join(root_path, '..', 'plugin.py') + + +def get_files(path, end: str) -> Generator[str, None, None]: + for r, dirs, files in os.walk(path): + for filename in [f for f in files if f.endswith(end)]: + yield os.path.join(r, filename) + + +def get_directories(path): + for root, directories, files in os.walk(path): + for directory in directories: + yield directory + + +def relative(file: str, path: str): + return os.path.join(os.path.dirname(file), path) + + +def read_relative(file: str, path: str): + with open(relative(file, path)) as fh: + return fh.read() + + +def protoc_plugin(path: str, output_dir: str): + subprocess.run( + f"protoc --plugin=protoc-gen-custom={plugin_path} --custom_out={output_dir} --proto_path={path} {path}/*.proto", + shell=True, + ) + + +def protoc_reference(path: str, output_dir: str): + subprocess.run(f"protoc --python_out={output_dir} --proto_path={path} {path}/*.proto", shell=True) +