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

Commit

Permalink
Creating aspect option (ALL, CODE, PACKAGE) (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjonesgoogle authored Jul 26, 2018
1 parent e1fd225 commit 8662dfe
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 198 deletions.
13 changes: 12 additions & 1 deletion artman/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ def parse_args(*args):
type=str,
help='[Required] Name of the artifact for artman to generate. Must '
'match an artifact in the artman config yaml.')
parser_generate.add_argument(
'--aspect',
type=str,
default=None,
help='[Optional] Aspect of output to generate: ALL, CODE, or PACKAGE')

# `publish` sub-command.
parser_publish = subparsers.add_parser('publish', help='Publish artifact')
Expand All @@ -187,6 +192,11 @@ def parse_args(*args):
type=str,
help='[Required] Name of the artifact for artman to generate. Must '
'match an artifact in the artman config yaml.')
parser_publish.add_argument(
'--aspect',
type=str,
default=None,
help='[Optional] Aspect of output to generate: ALL, CODE, or PACKAGE')
parser_publish.add_argument(
'--target',
type=str,
Expand Down Expand Up @@ -276,7 +286,7 @@ def normalize_flags(flags, user_config):

try:
artifact_config = loader.load_artifact_config(
artman_config_path, flags.artifact_name)
artman_config_path, flags.artifact_name, flags.aspect)
except ValueError as ve:
logger.error('Artifact config loading failed with `%s`' % ve)
sys.exit(96)
Expand All @@ -292,6 +302,7 @@ def normalize_flags(flags, user_config):
# Set the pipeline
artifact_type = artifact_config.type
pipeline_args['artifact_type'] = Artifact.Type.Name(artifact_type)
pipeline_args['aspect'] = Artifact.Aspect.Name(artifact_config.aspect)
if artifact_type == Artifact.GAPIC_ONLY:
pipeline_name = 'GapicOnlyClientPipeline'
pipeline_args['language'] = language
Expand Down
5 changes: 4 additions & 1 deletion artman/config/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
}


def load_artifact_config(artman_config_path, artifact_name):
def load_artifact_config(artman_config_path, artifact_name, aspect=None):
artman_config = _read_artman_config(artman_config_path)
artifact_config = Artifact()
artifact_config.CopyFrom(artman_config.common)
Expand All @@ -70,6 +70,9 @@ def load_artifact_config(artman_config_path, artifact_name):
loaded_artifact.MergeFrom(artifact)
break

if aspect:
loaded_artifact.aspect = Artifact.Aspect.Value(aspect)

artifact_config.MergeFrom(loaded_artifact)
_validate_artifact_config(artifact_config)
return _normalize_artifact_config(
Expand Down
15 changes: 14 additions & 1 deletion artman/config/proto/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ message Artifact {
// This artifact type will only generate a GRPC library without GAPIC layer.
GRPC = 2;

// This artifact type will generate a protobuf library using protobuf
// This artifact type will generate a protobuf library using the protobuf
// compiler.
PROTOBUF = 3;

Expand Down Expand Up @@ -326,4 +326,17 @@ message Artifact {
// Discovery Document. The path can be an absolute path or a path relative
// to the artman config yaml.
string discovery_doc = 16;

enum Aspect {
// Generate both the code and packaging files for a library
ALL = 0;

// Generate only the code for a library
CODE = 1;

// Generate only the packaging files for a library
PACKAGE = 2;
}

Aspect aspect = 17;
}
72 changes: 54 additions & 18 deletions artman/config/proto/config_pb2.py

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

18 changes: 8 additions & 10 deletions artman/pipelines/gapic_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


# kwargs required by GAPIC code gen
_GAPIC_REQUIRED = ['service_yaml', 'gapic_yaml', 'language', 'publish']
_GAPIC_REQUIRED = ['service_yaml', 'gapic_yaml', 'language', 'aspect', 'publish']

_DISCOGAPIC_REQUIRED = ['gapic_yaml', 'language', 'publish']

Expand Down Expand Up @@ -77,7 +77,7 @@ class GapicOnlyClientPipeline(code_gen.CodeGenerationPipelineBase):
"""
def __init__(self, language, **kwargs):
super(GapicOnlyClientPipeline, self).__init__(
GapicOnlyTaskFactory(),
GapicOnlyTaskFactory(**kwargs),
language=language,
**kwargs
)
Expand All @@ -88,9 +88,6 @@ class GapicClientPipeline(code_gen.CodeGenerationPipelineBase):
This is intended to be the only command that needs to run to generate
a complete GAPIC.
Exception: In Java, the GrpcClientPipeline must still be
run explicitly.
"""
def __init__(self, language, **kwargs):
super(GapicClientPipeline, self).__init__(
Expand All @@ -99,6 +96,7 @@ def __init__(self, language, **kwargs):
**kwargs
)


class DiscoGapicClientPipeline(code_gen.CodeGenerationPipelineBase):
"""The pipeline for generating a complete GAPIC from a Discovery document.
Expand Down Expand Up @@ -191,9 +189,9 @@ def _get_grpc_codegen_tasks(self, language, **kw):
list: A list of Task subclasses defined by the GRPC task factory.
"""

# Instantiate the GRPC task factory.
grpc_factory = grpc_gen.GRPC_TASK_FACTORY_DICT[language]()
return grpc_factory.get_grpc_codegen_tasks(language=language, **kw)
grpc_factory = grpc_gen.ProtoGenTaskFactory(gen_grpc=True,
language=language, **kw)
return grpc_factory.get_grpc_codegen_tasks(**kw)

def _get_packaging_tasks(self, language, **kw):
"""Return the code generation tasks for packaging
Expand Down Expand Up @@ -284,8 +282,8 @@ def get_invalid_kwargs(self):

class GapicOnlyTaskFactory(GapicTaskFactory):
"""A task factory describing GAPIC_ONLY generation tasks."""
def _get_grpc_codegen_tasks(self, language, **kw):
def _get_grpc_codegen_tasks(self, **kw):
return[]

def _get_packaging_tasks(self, language, **kw):
def _get_packaging_tasks(self, **kw):
return []
Loading

0 comments on commit 8662dfe

Please sign in to comment.