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

Commit

Permalink
Add proto_package option (#636)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreamlin authored Jun 12, 2019
1 parent 36f9288 commit c191dc2
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 30 deletions.
1 change: 1 addition & 0 deletions artman/config/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def convert_to_legacy_config_dict(artifact_config, root_dir, output_dir):
common['organization_name'] = artifact_config.organization_name
common['service_yaml'] = artifact_config.service_yaml
common['gapic_yaml'] = artifact_config.gapic_yaml
common['proto_package'] = artifact_config.proto_package
src_proto_paths = artifact_config_dict.get('src_proto_paths', [])
common['src_proto_path'], excluded_proto_path = _calculate_proto_paths(src_proto_paths)
if excluded_proto_path:
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 @@ -178,6 +178,11 @@ message Artifact {
// for a full GAPIC config spec.
string gapic_yaml = 10;

// The proto package of the proto files to generate a client for,
// e.g. "google.example.library.v1".
// If a gRPC client is to be generated, either a gapic_yaml or a proto_package must be given.
string proto_package = 18;

reserved 11;
reserved "import_proto_path";

Expand Down
60 changes: 34 additions & 26 deletions artman/config/proto/config_pb2.py

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

2 changes: 1 addition & 1 deletion artman/pipelines/code_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# kwargs required by multiple pipelines
COMMON_REQUIRED = ['src_proto_path', 'import_proto_path', 'toolkit_path', 'root_dir',
'output_dir', 'api_name', 'api_version',
'organization_name']
'organization_name', 'proto_package']

COMMON_DISCO_REQUIRED = ['discovery_doc', 'toolkit_path', 'root_dir', 'output_dir',
'api_name', 'api_version', 'organization_name']
Expand Down
8 changes: 6 additions & 2 deletions artman/tasks/gapic_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,17 @@ class GapicCodeGenTask(task_base.TaskBase):
default_provides = 'gapic_code_dir'

def execute(self, language, toolkit_path, descriptor_set, service_yaml,
gapic_yaml, package_metadata_yaml,
gapic_yaml, package_metadata_yaml, proto_package,
gapic_code_dir, api_name, api_version, organization_name,
aspect, generator_args):
existing = glob.glob('%s/*' % gapic_code_dir)
if existing:
self.exec_command(['rm', '-r'] + existing)
gapic_args = ['--gapic_yaml=' + os.path.abspath(gapic_yaml)]
gapic_args = []
if proto_package:
gapic_args.append('--package=' + proto_package)
if gapic_yaml:
gapic_args.append('--gapic_yaml=' + os.path.abspath(gapic_yaml))
args = [
'--descriptor_set=' + os.path.abspath(descriptor_set),
'--package_yaml2=' + os.path.abspath(package_metadata_yaml),
Expand Down
4 changes: 4 additions & 0 deletions test/config/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def test_pubsub_python(self):
self._test('artman_pubsub.yaml', 'python_gapic',
'expected_pubsub_python_legacy_config.yaml')

def test_library(self):
self._test('artman_library.yaml', 'java_gapic',
'expected_library_config.yaml')

def _test(self, artman_yaml, artifact_name, expected_legacy_config):
artifact_config = loader.load_artifact_config(os.path.join(
self.TESTDATA, artman_yaml), artifact_name)
Expand Down
20 changes: 20 additions & 0 deletions test/config/testdata/artman_library.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
common:
api_name: library
api_version: v1
organization_name: google-cloud
src_proto_paths:
- /tmp/input/google/example/library/v1
- -/tmp/input/google/example/library/v1/excluded
proto_deps:
- name: google-common-protos
- name: google-iam-v1
proto_path: google/iam/v1
test_proto_deps:
- name: google-iam-v1
proto_path: google/iam/v1
service_yaml: /tmp/input/google/example/library/library.yaml
# gapic yaml not given
proto_package: google.example.library.v1
artifacts:
- name: java_gapic
release_level: GA
25 changes: 25 additions & 0 deletions test/config/testdata/expected_library_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
common:
api_name: library
api_version: v1
artifact_type: GAPIC
excluded_proto_path:
- /tmp/input/google/example/library/v1/excluded
gapic_yaml: ''
import_proto_path:
- /tmp/input
organization_name: google-cloud
output_dir: /tmp/output
proto_deps:
- name: google-common-protos
- name: google-iam-v1
proto_path: google/iam/v1
proto_package: google.example.library.v1
service_yaml: /tmp/input/google/example/library/library.yaml
src_proto_path:
- /tmp/input/google/example/library/v1
test_proto_deps:
- name: google-iam-v1
proto_path: google/iam/v1
java:
gapic_code_dir: /tmp/output/java/gapic-google-cloud-library-v1
release_level: ga
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ common:
- name: google-common-protos
- name: google-iam-v1
proto_path: google/iam/v1
proto_package: ''
service_yaml: /tmp/input/google/pubsub/pubsub.yaml
src_proto_path:
- /tmp/input/google/pubsub/v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ common:
- name: google-common-protos
- name: google-iam-v1
proto_path: google/iam/v1
proto_package: ''
test_proto_deps:
- name: google-iam-v1
proto_path: google/iam/v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ common:
- name: google-common-protos
- name: google-iam-v1
proto_path: google/iam/v1
proto_package: ''
service_yaml: /tmp/input/google/pubsub/pubsub.yaml
src_proto_path:
- /tmp/input/google/pubsub/v1
Expand Down
3 changes: 2 additions & 1 deletion test/tasks/test_gapic.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ def test_execute(self, exec_command, check_output):
service_yaml='/path/to/service.yaml',
toolkit_path='/path/to/toolkit',
aspect='ALL',
generator_args='--extra_args'
generator_args='--extra_args',
proto_package=''
)
expected_cmds = [
' '.join(['java -cp',
Expand Down

0 comments on commit c191dc2

Please sign in to comment.