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

Add a gapic-samples field to artman config and pass sample configs to gapic-generator #677

Merged
merged 3 commits into from
Jul 31, 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
1 change: 1 addition & 0 deletions artman/config/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ 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
common['gapic_samples'] = artifact_config.gapic_samples
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
4 changes: 4 additions & 0 deletions artman/config/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ def _normalize_artifact_config(artifact_config, artman_config_path):
artifact_config.gapic_yaml = _normalize_path(
artifact_config.gapic_yaml, artman_config_path, 'gapic_yaml')

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

normalized_src_proto_paths = []
for src_proto_path in artifact_config.src_proto_paths:
if src_proto_path.startswith('-'):
Expand Down
6 changes: 6 additions & 0 deletions artman/config/proto/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ message Artifact {
// If a gRPC client is to be generated, either a gapic_yaml or a proto_package must be given.
string proto_package = 18;

// The path to sample config yaml(s). It can be an absolute path or a path
// relative to the artman config yaml. It can also be either a directory or
// a file. When it is a directory, artman will consume all the sample config
// yamls recursively in this directory.
string gapic_samples = 19;

reserved 11;
reserved "import_proto_path";

Expand Down
59 changes: 33 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.

22 changes: 21 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, generator_args):
aspect, gapic_samples, generator_args):
existing = glob.glob('%s/*' % gapic_code_dir)
if existing:
self.exec_command(['rm', '-r'] + existing)
Expand All @@ -112,6 +112,13 @@ def execute(self, language, toolkit_path, descriptor_set, service_yaml,
gapic_args.append('--package=' + proto_package)
if gapic_yaml:
gapic_args.append('--gapic_yaml=' + os.path.abspath(gapic_yaml))
if gapic_samples:
sample_yamls = self._get_sample_yamls(gapic_samples)
if sample_yamls:
gapic_args.append('--sample_yamls')
for sample_yaml in sample_yamls:
gapic_args.append(sample_yaml)

args = [
'--descriptor_set=' + os.path.abspath(descriptor_set),
'--package_yaml2=' + os.path.abspath(package_metadata_yaml),
Expand Down Expand Up @@ -140,6 +147,19 @@ def execute(self, language, toolkit_path, descriptor_set, service_yaml,

return gapic_code_dir

def _get_sample_yamls(self, path):
sample_path = os.path.abspath(path)
if os.path.isfile(sample_path):
return [sample_path]
elif os.path.isdir(sample_path):
sample_paths = []
for root, dirnames, filenames in os.walk(sample_path):
for filename in filenames:
if filename.endswith('.yaml'):
sample_paths.append(os.path.join(root, filename))
return sample_paths
else:
raise ValueError('GapicCodeGenTask: `--samples` directory or file does not exist.')

class DiscoGapicCodeGenTask(task_base.TaskBase):
"""Generates GAPIC wrappers from a Discovery document"""
Expand Down
1 change: 1 addition & 0 deletions test/config/testdata/artman_pubsub.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/pubsub/pubsub.yaml
gapic_yaml: /tmp/input/google/pubsub/v1/pubsub_gapic.yaml
gapic_samples: /path/to/the/samples
artifacts:
- name: java_gapic
release_level: BETA
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 @@ -14,6 +14,7 @@ common:
- name: google-iam-v1
proto_path: google/iam/v1
proto_package: google.example.library.v1
gapic_samples: ''
service_yaml: /tmp/input/google/example/library/library.yaml
src_proto_path:
- /tmp/input/google/example/library/v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ common:
- name: google-iam-v1
proto_path: google/iam/v1
proto_package: ''
gapic_samples: /path/to/the/samples
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 @@ -14,6 +14,7 @@ common:
- name: google-iam-v1
proto_path: google/iam/v1
proto_package: ''
gapic_samples: /path/to/the/samples
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 @@ -12,6 +12,7 @@ common:
- name: google-iam-v1
proto_path: google/iam/v1
proto_package: ''
gapic_samples: /path/to/the/samples
service_yaml: /tmp/input/google/pubsub/pubsub.yaml
src_proto_path:
- /tmp/input/google/pubsub/v1
Expand Down
Binary file not shown.
Loading