Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

Commit

Permalink
config: add grpc_service_config attr to config (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz authored Oct 28, 2019
1 parent 329d4ce commit f14b1c9
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 52 deletions.
2 changes: 2 additions & 0 deletions artman/config/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def convert_to_legacy_config_dict(artifact_config, root_dir, output_dir):
common['service_yaml'] = artifact_config.service_yaml
common['gapic_yaml'] = artifact_config.gapic_yaml
common['proto_package'] = artifact_config.proto_package
if 'grpc_service_config' in artifact_config_dict:
common['grpc_service_config'] = artifact_config_dict['grpc_service_config']
common['samples'] = artifact_config.samples
src_proto_paths = artifact_config_dict.get('src_proto_paths', [])
common['src_proto_path'], excluded_proto_path = _calculate_proto_paths(src_proto_paths)
Expand Down
4 changes: 4 additions & 0 deletions artman/config/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ def _normalize_artifact_config(artifact_config, artman_config_path):
artifact_config.samples = _normalize_path(
artifact_config.samples, artman_config_path, 'samples')

if artifact_config.grpc_service_config:
artifact_config.grpc_service_config = _normalize_path(
artifact_config.grpc_service_config, artman_config_path, 'grpc_service_config')

normalized_src_proto_paths = []
for src_proto_path in artifact_config.src_proto_paths:
if src_proto_path.startswith('-'):
Expand Down
5 changes: 5 additions & 0 deletions artman/config/proto/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ message Artifact {
// yamls recursively in this directory.
string samples = 19;

// Path to a gRPC ServiceConfig JSON file. This config is only used by
// gapic-generator if the protos are configured with annotations. It can
// be an absolute path or a path relative to the artman config yaml.
string grpc_service_config = 20;

reserved 11;
reserved "import_proto_path";

Expand Down
107 changes: 57 additions & 50 deletions artman/config/proto/config_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion artman/tasks/gapic_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class GapicCodeGenTask(task_base.TaskBase):
def execute(self, language, toolkit_path, descriptor_set, service_yaml,
gapic_yaml, package_metadata_yaml, proto_package,
gapic_code_dir, api_name, api_version, organization_name,
aspect, samples, generator_args):
aspect, samples, generator_args, grpc_service_config=''):
existing = glob.glob('%s/*' % gapic_code_dir)
if existing:
self.exec_command(['rm', '-r'] + existing)
Expand All @@ -118,6 +118,8 @@ def execute(self, language, toolkit_path, descriptor_set, service_yaml,
gapic_args.append('--sample_yamls')
for sample_yaml in sample_yamls:
gapic_args.append(sample_yaml)
if grpc_service_config:
gapic_args.append('--grpc_service_config=' + os.path.abspath(grpc_service_config))

args = [
'--descriptor_set=' + os.path.abspath(descriptor_set),
Expand Down
1 change: 1 addition & 0 deletions test/config/testdata/artman_library.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ common:
proto_path: google/iam/v1
service_yaml: /tmp/input/google/example/library/library.yaml
# gapic yaml not given
grpc_service_config : /tmp/input/google/example/library/v1/library_grpc_service_config.json
proto_package: google.example.library.v1
artifacts:
- name: java_gapic
Expand Down
1 change: 1 addition & 0 deletions test/config/testdata/expected_library_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ common:
excluded_proto_path:
- /tmp/input/google/example/library/v1/excluded
gapic_yaml: ''
grpc_service_config: /tmp/input/google/example/library/v1/library_grpc_service_config.json
import_proto_path:
- /tmp/input
organization_name: google-cloud
Expand Down
1 change: 1 addition & 0 deletions test/config/testdata/valid_artman.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ common:
organization_name: test-org
service_yaml: test.yaml
gapic_yaml: v1/test_gapic.yaml
grpc_service_config: v1/test_grpc_service_config.json
src_proto_paths:
- v1
proto_deps:
Expand Down
4 changes: 3 additions & 1 deletion test/tasks/test_gapic.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def test_execute(self, exec_command, check_output):
aspect='ALL',
samples='',
generator_args='--extra_args',
proto_package=''
proto_package='',
grpc_service_config='/path/to/my_grpc_service_config.json'
)
expected_cmds = [
' '.join(['java -cp',
Expand All @@ -170,6 +171,7 @@ def test_execute(self, exec_command, check_output):
'--output=/path/to/output --language=python',
'--service_yaml=/path/to/service.yaml',
'--gapic_yaml=/path/to/pubsub.yaml',
'--grpc_service_config=/path/to/my_grpc_service_config.json',
'--extra_args'
])
]
Expand Down

0 comments on commit f14b1c9

Please sign in to comment.