Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GCE and discogapic to batch gen script #3441

Merged
merged 12 commits into from
Jul 11, 2018
15 changes: 7 additions & 8 deletions utilities/batch_generate_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# (e.g. from https://github.com/googleapis/googleapis):
#
# $ git checkout https://github.com/googleapis/googleapis.git
# $ git checkout https://github.com/googleapis/discovery-artifact-manager
# $ git checkout https://github.com/googleapis/discovery-artifact-manager.git
#
# Run this script:
#
Expand All @@ -32,7 +32,8 @@

def run_gapic_gen(googleapis):
def generate(artman_yaml):
generate_api.run_generate_api(os.path.join(googleapis, artman_yaml), "java_gapic")
generate_api.run_generate_api(os.path.join(googleapis, artman_yaml),
generate_api.JAVA_GAPIC)

# TODO Needs to have java_proto called instead of java_grpc
#generate('google/datastore/artman_datastore.yaml')
Expand Down Expand Up @@ -78,9 +79,7 @@ def run_discogapic_gen(discovery_repo):
def generate(artman_yaml):
# Run java_discogapic task. No proto or grpc libraries are generated.
generate_api.run_generate_api(os.path.join(discovery_repo, artman_yaml),
"java_discogapic",
root_dir=discovery_repo,
has_proto_libs=False)
generate_api.JAVA_DISCOGAPIC)

generate('gapic/google/compute/artman_compute.yaml')

Expand All @@ -89,12 +88,12 @@ def main():
# TODO Make the docker image the default, add --local option
parser = argparse.ArgumentParser(description='Batch generate all APIs.')
parser.add_argument('googleapis', help='The path to the googleapis repo')
parser.add_argument('discovery', help='The path to the discovery-artifact-manager repo')
parser.add_argument('discovery_repo',
help='The path to the discovery-artifact-manager repo')
args = parser.parse_args()

run_gapic_gen(args.googleapis)
run_discogapic_gen(args.discovery)

run_discogapic_gen(args.discovery_repo)

if __name__ == '__main__':
main()
33 changes: 17 additions & 16 deletions utilities/generate_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
# Instructions:
#
# Find the artman config file the describes the API you want to generate a client for.
# Specifiy the artman ARTIFACT_TYPE to generate, e.g. "java_gapic"
#
# $ python utilities/generate_api.py PATH_TO_ARTMAN_CONFIG_FILE java_gapic
# $ python utilities/generate_api.py PATH_TO_ARTMAN_CONFIG_FILE ARTIFACT_TYPE

import argparse
import io
Expand All @@ -35,34 +36,34 @@
'spanner-admin-database': 'google-cloud-spanner'
}

JAVA_GAPIC="java_gapic"
JAVA_DISCOGAPIC="java_discogapic"

def run_generate_api(config_path, artifact_type, root_dir=None, has_proto_libs=True, noisy=False):
def run_generate_api(config_path, artifact_type, noisy=False):
""" Generate an API client library.

:param config_path: (str) Path to directory containing artman config file.
:param artifact_type: (str) artman target, e.g "java_gapic".
:param root_dir: (str) Path to the directory containing the API definitions.
:param has_proto_libs: (bool) if the generated proto and grpc libraries
should replace the existing ones
:param has_proto_libs: (bool) if this target creates proto and grpc libraries

This comment was marked as spam.

This comment was marked as spam.

:param noisy: (bool) if console output should be verbose.

"""
googleapis_index = config_path.rfind('/google/')
if googleapis_index == -1:
raise ValueError('Didn\'t find /googleapis/ in config file path; need absolute path to the artman config file.')
if has_proto_libs:
root_dir = config_path[0:googleapis_index]
api_dir = config_path[googleapis_index+1:]
else:
api_dir = config_path
api_repo_index = config_path.rfind('/google/')
if artifact_type == JAVA_DISCOGAPIC:
api_repo_index = config_path.rfind('/gapic/')
if api_repo_index == -1:
raise ValueError('Didn\'t find the API repo in config file path; need absolute path to the artman config file.')
root_dir = config_path[0:api_repo_index]
api_dir = config_path[api_repo_index+1:]

extra_options = []
if noisy:
extra_options = ['-v']

print("api_dir: "+ api_dir)
print("root_dir: "+ root_dir)
subprocess.check_call(['artman', '--config', api_dir, '--local', '--root-dir', root_dir] + extra_options + ['generate', artifact_type])
subprocess.check_call(
['artman', '--config', api_dir, '--local', '--root-dir', root_dir]
+ extra_options + ['generate', artifact_type])

with io.open(config_path, encoding='UTF-8') as config_file:
artman_config_data = yaml.load(config_file, Loader=yaml.Loader)
Expand All @@ -80,7 +81,7 @@ def run_generate_api(config_path, artifact_type, root_dir=None, has_proto_libs=T
if not os.path.exists(gapic_dir):
raise ValueError('generated gapic dir doesn\'t exist: {}'.format(gapic_dir))

if has_proto_libs:
if artifact_type != JAVA_DISCOGAPIC:
proto_dir = os.path.join('artman-genfiles', 'java', proto_dirname)
grpc_dir = os.path.join('artman-genfiles', 'java', grpc_dirname)

Expand Down