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

Commit

Permalink
DiscogapicConfigGen: Use a temporary output directory (#669)
Browse files Browse the repository at this point in the history
DiscogapicConfigGen generates gapic yaml from discovery docs, and therefore the flag gapic_yaml is used as output instead of input (which is the usual case for codegen).

When trying to refresh gapic config for compute artman creates this default artman-genfiles in my local environment while does not drop any output there. Therefore it seems clearer to just use a temporary directory to hold the generated gapic config before moving to the right place.

Also, if user specifies the output_dir flag when invoking artman generate discogapic_config, throw a command line warning saying that the flag is ignored, and output is saved in the directory given by gapic_yaml.
  • Loading branch information
yihanzhen authored Jul 22, 2019
1 parent 68e1ce9 commit 4428698
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions artman/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import pprint
import subprocess
import sys
import tempfile
import traceback

import pkg_resources
Expand All @@ -46,7 +47,7 @@
VERSION = pkg_resources.get_distribution('googleapis-artman').version
ARTMAN_DOCKER_IMAGE = 'googleapis/artman:%s' % VERSION
RUNNING_IN_ARTMAN_DOCKER_TOKEN = 'RUNNING_IN_ARTMAN_DOCKER'

DEFAULT_OUTPUT_DIR = './artman-genfiles'

def main(*args):
"""Main method of artman."""
Expand Down Expand Up @@ -124,9 +125,9 @@ def parse_args(*args):
parser.add_argument(
'--output-dir',
type=str,
default='./artman-genfiles',
default=DEFAULT_OUTPUT_DIR,
help='[Optional] Directory to store output generated by artman. '
'Default to `./artman-genfiles`', )
'Default to `' + DEFAULT_OUTPUT_DIR + '`', )
parser.add_argument(
'--root-dir',
type=str,
Expand Down Expand Up @@ -273,6 +274,10 @@ def normalize_flags(flags, user_config):
elif artifact_type == Artifact.DISCOGAPIC_CONFIG:
pipeline_name = 'DiscoGapicConfigPipeline'
pipeline_args['discovery_doc'] = artifact_config.discovery_doc
if os.path.abspath(flags.output_dir) != os.path.abspath(DEFAULT_OUTPUT_DIR):
logger.warning("`output_dir` is ignored in DiscoGapicConfigGen. "
+ "Yamls are saved at the path specified by `gapic_yaml`.")
pipeline_args['output_dir'] = tempfile.mkdtemp()
elif artifact_type == Artifact.PROTOBUF:
pipeline_name = 'ProtoClientPipeline'
pipeline_args['language'] = language
Expand Down

0 comments on commit 4428698

Please sign in to comment.