Skip to content

Commit

Permalink
Log warning when gen_protos is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandInguva committed Oct 17, 2023
1 parent a6917d4 commit e1f1311
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion sdks/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,37 @@ def cythonize(*args, **kwargs):
'pandas>=1.4.3,!=1.5.0,!=1.5.1,<1.6;python_version>="3.8"',
]

def find_by_ext(root_dir, ext):
for root, _, files in os.walk(root_dir):
for file in files:
if file.endswith(ext):
yield os.path.realpath(os.path.join(root, file))

# We must generate protos after setup_requires are installed.
def generate_protos_first():
try:
# Pyproject toml build happens in isolated environemnts. In those envs,
# gen_protos is unable to get imported. so we run a subprocess call.
cwd = os.path.abspath(os.path.dirname(__file__))
# when pip install <>.tar.gz gets called, if gen_protos.py is not available
# in the sdist,then the proto files would have already been generated. So we
# skip proto generation in that case.
if not os.path.exists(os.path.join(cwd, 'gen_protos.py')):
# make sure we already generated protos
pb2_files = list(find_by_ext(os.path.join(
cwd, 'apache_beam', 'portability', 'api'), '_pb2.py'))
if not pb2_files:
raise RuntimeError('protobuf files are not generated. '
'Please generate pb2 files')

warnings.warn('Skipping proto generation as they are already generated.')
return

out = subprocess.run([
sys.executable,
os.path.join(cwd, 'gen_protos.py'),
'--no-force'
], capture_output=True, check=True)
print(out.stdout)
except subprocess.CalledProcessError as err:
raise RuntimeError('Could not generate protos due to error: %s',
err.stderr)
Expand Down

0 comments on commit e1f1311

Please sign in to comment.