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

Add __init__.py to directories created by grpcio #7984

Merged
merged 9 commits into from
Jul 4, 2019
Merged
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
3 changes: 2 additions & 1 deletion src/python/pants/backend/codegen/grpcio/python/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ python_library(
'src/python/pants/build_graph',
'src/python/pants/subsystem',
'src/python/pants/util:contextutil',
'src/python/pants/util:memo',
'src/python/pants/task',
],
)
)
8 changes: 8 additions & 0 deletions src/python/pants/backend/codegen/grpcio/python/grpcio_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

import functools
import logging
from pathlib import Path

from pants.backend.codegen.grpcio.python.grpcio_prep import GrpcioPrep
from pants.backend.codegen.grpcio.python.python_grpcio_library import PythonGrpcioLibrary
from pants.backend.python.subsystems.pex_build_util import identify_missing_init_files
from pants.backend.python.targets.python_library import PythonLibrary
from pants.base.build_environment import get_buildroot
from pants.base.exceptions import TaskError
Expand Down Expand Up @@ -45,6 +47,12 @@ def execute_codegen(self, target, target_workdir):
if exit_code != 0:
raise TaskError('{} ... exited non-zero ({}).'.format(cmdline, exit_code),
exit_code=exit_code)
# Create __init__.py in each subdirectory of the target directory so that setup_py recognizes
# them as modules.
target_workdir_path = Path(target_workdir)
sources = [str(p.relative_to(target_workdir_path)) for p in target_workdir_path.rglob("*.py")]
for missing_init in identify_missing_init_files(sources):
(target_workdir_path / missing_init).touch()
logging.info("Grpcio finished code generation into: [{}]".format(target_workdir))

def build_args(self, target, target_workdir):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ def test_multiple_dependent_protobufs(self):
# then
self.assertIsNotNone(synthetic_target)
self.assertEqual(2, len(synthetic_target))
self.assertEqual({'com/foo/foo_example_pb2_grpc.py',
self.assertEqual({'com/__init__.py',
'com/foo/__init__.py',
'com/foo/foo_example_pb2_grpc.py',
'com/foo/foo_example_pb2.py'},
set(synthetic_target[0].sources_relative_to_source_root()))
self.assertEqual({'com/bar/bar_example_pb2_grpc.py',
self.assertEqual({'com/__init__.py',
'com/bar/__init__.py',
'com/bar/bar_example_pb2_grpc.py',
'com/bar/bar_example_pb2.py'},
set(synthetic_target[1].sources_relative_to_source_root()))
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def test_single_protobuf(self):

# then
self.assertEqual(1, len(synthetic_target))
self.assertEqual({'com/example/example_pb2_grpc.py',
self.assertEqual({'com/__init__.py',
'com/example/__init__.py',
'com/example/example_pb2_grpc.py',
'com/example/example_pb2.py'},
set(synthetic_target[0].sources_relative_to_source_root()))