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

Commit

Permalink
Add --generator_args to pass a string of args to gapic-generator (#523)
Browse files Browse the repository at this point in the history
* Add --generator_args to pass a string of args to gapic-generator

I have not been able to figure out how to make the parser accept everything after a "-- " as arguments. I can do it on a standalone example, but I thing the generate subcommand does not interact well with it.

This includes tests.

* PR comment: s/--generator_args/--generator-args/
  • Loading branch information
vchudnov-g authored Nov 13, 2018
1 parent b0f78fe commit 8c236b4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
9 changes: 8 additions & 1 deletion artman/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@ def parse_args(*args):
'--image',
default=ARTMAN_DOCKER_IMAGE,
help=('[Optional] Specify docker image used by artman when running in '
'a Docker instance. Default to `%s`' % ARTMAN_DOCKER_IMAGE)),
'a Docker instance. Default to `%s`' % ARTMAN_DOCKER_IMAGE))
parser.add_argument(
'--generator-args',
type=str,
default=None,
help='Additional arguments to pass to gapic-generator')


# Add sub-commands.
subparsers = parser.add_subparsers(
Expand Down Expand Up @@ -222,6 +228,7 @@ def normalize_flags(flags, user_config):
# toolkit on his or her machine.
pipeline_args['root_dir'] = root_dir
pipeline_args['toolkit_path'] = user_config.local.toolkit
pipeline_args['generator_args'] = flags.generator_args

artman_config_path = flags.config
if not os.path.isfile(artman_config_path):
Expand Down
7 changes: 5 additions & 2 deletions artman/tasks/gapic_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def execute(self, toolkit_path, descriptor_set, service_yaml,
api_full_name + '_gapic.yaml')
args = [
'--descriptor_set=' + os.path.abspath(descriptor_set),
'--output=' + os.path.abspath(config_gen_path)
'--output=' + os.path.abspath(config_gen_path),
]
if service_yaml:
args = args + ['--service_yaml=' + os.path.abspath(service_yaml)]
Expand Down 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,
gapic_code_dir, api_name, api_version, organization_name,
aspect):
aspect, generator_args):
existing = glob.glob('%s/*' % gapic_code_dir)
if existing:
self.exec_command(['rm', '-r'] + existing)
Expand All @@ -118,6 +118,9 @@ def execute(self, language, toolkit_path, descriptor_set, service_yaml,
args = args + ['--service_yaml=' + os.path.abspath(service_yaml)]
args = args + gapic_args

if generator_args:
args = args + generator_args.split(' ')

gapic_artifact = ''
if aspect == 'ALL':
gapic_artifact = 'LEGACY_GAPIC_AND_PACKAGE'
Expand Down
2 changes: 2 additions & 0 deletions test/cli/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def setUp(self):
github_username='test', github_token='testtoken',
artifact_name='python_gapic',
aspect=None,
generator_args=["--dev_samples --other"],
output_dir='./artman-genfiles',
dry_run=False,
local_repo_dir=None,
Expand All @@ -73,3 +74,4 @@ def test_basic_args(self):
assert args['gapic_yaml'].endswith('test_gapic.yaml')
assert args['toolkit_path']
assert args['language'] == 'python'
assert args['generator_args'] == ['--dev_samples --other']
2 changes: 2 additions & 0 deletions test/tasks/test_gapic.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ 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'
)
expected_cmds = [
' '.join(['java -cp',
Expand All @@ -167,6 +168,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',
'--extra_args'
])
]
assert_calls_equal(exec_command.mock_calls, expected_cmds)
Expand Down

0 comments on commit 8c236b4

Please sign in to comment.