Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle Ctrl felix patch 1 #4

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 41 additions & 21 deletions compile.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,80 @@
import logging
import os
import subprocess
import sys
import logging

package_name = 'cosmospy_protobuf'
logging.basicConfig(format='%(asctime)s - %(levelname)s:%(message)s', level=logging.DEBUG)
package_name = "cosmospy_protobuf"
logging.basicConfig(format="%(asctime)s - %(levelname)s:%(message)s",
level=logging.DEBUG)
absolute_path = os.path.abspath(package_name)


def run_protoc(filepath):
if os.path.basename(filepath) == "query.proto":
cmd = [sys.executable, '-m', 'grpc_tools.protoc',
'--proto_path', absolute_path,
'--python_out', 'cosmospy_protobuf',
'--grpc_python_out', 'cosmospy_protobuf',
filepath]
cmd = [
sys.executable,
"-m",
"grpc_tools.protoc",
"--proto_path",
absolute_path,
"--python_out",
"cosmospy_protobuf",
"--grpc_python_out",
"cosmospy_protobuf",
filepath,
]
logging.info(f"Compiling proto and grpc file: {filepath}")
else:
cmd = [sys.executable, '-m', 'grpc_tools.protoc',
f'--proto_path={absolute_path}',
'--python_out=cosmospy_protobuf',
filepath]
cmd = [
sys.executable,
"-m",
"grpc_tools.protoc",
f"--proto_path={absolute_path}",
"--python_out=cosmospy_protobuf",
filepath,
]
logging.info(f"Compiling proto file: {filepath}")

subprocess.run(cmd)


def fix_proto_imports(filepath):
logging.info(f"Fixing file at: {filepath}")
cmd = [sys.executable, '-m', 'protoletariat',
'--create-package', '--in-place',
'--python-out', 'cosmospy_protobuf',
'protoc', f'--proto-path={absolute_path}',
filepath]
cmd = [
sys.executable,
"-m",
"protoletariat",
"--create-package",
"--in-place",
"--python-out",
"cosmospy_protobuf",
"protoc",
f"--proto-path={absolute_path}",
filepath,
]
subprocess.run(cmd)


def walk_through_project_and_compile_proto(directory):
for root, dirs, files in os.walk(directory):
for filename in files:
if filename.endswith('.proto'):
if filename.endswith(".proto"):
run_protoc(os.path.abspath(os.path.join(root, filename)))


def walk_through_project_and_fix_imports(directory):
for root, dirs, files in os.walk(directory):
for filename in files:
if filename.endswith('.proto'):
fix_proto_imports(os.path.abspath(os.path.join(root, filename)))
if filename.endswith(".proto"):
fix_proto_imports(os.path.abspath(os.path.join(root,
filename)))
logging.info(f"Fixed imports for {filename}")


def remove_all_compiled_python_files(directory):
for root, dirs, files in os.walk(directory):
for filename in files:
if filename.endswith('.py') or filename.endswith('.pyi'):
if filename.endswith(".py") or filename.endswith(".pyi"):
logging.info(f"Deleting {os.path.join(root, filename)}")
os.remove(os.path.join(root, filename))

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
grpcio-tools ==1.46.3
grpcio-tools ==1.46.3