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

feat: move new client script #2333

Merged
merged 47 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
df960de
feat: add new-client.py
JoeWang1127 Jan 3, 2024
61f855f
refactor code
JoeWang1127 Jan 3, 2024
1a98967
clone googleapis
JoeWang1127 Jan 3, 2024
f641afc
Merge branch 'main' into feat/move-new-client-script
JoeWang1127 Jan 3, 2024
d16e583
add build parser
JoeWang1127 Jan 4, 2024
d44e1e6
parse inputs from BUILD
JoeWang1127 Jan 4, 2024
f62e9ec
find versioned dir within proto_path
JoeWang1127 Jan 4, 2024
a6b129d
fix postprocessing, use google-java-format
diegomarquezp Jan 5, 2024
12bc62f
migirate shell scripts
JoeWang1127 Jan 5, 2024
d02507b
change depth
JoeWang1127 Jan 5, 2024
01a5bcb
add generate_gapic_bom.sh
JoeWang1127 Jan 5, 2024
e2b2e59
process root pom
JoeWang1127 Jan 5, 2024
81fb67a
only generating gapic-libraries-bom if it already exists
JoeWang1127 Jan 6, 2024
78a2259
add consolidate_config.sh
JoeWang1127 Jan 6, 2024
32a2c95
add generation dir
JoeWang1127 Jan 6, 2024
9c6b987
use variable for script dir
JoeWang1127 Jan 6, 2024
b25abc0
add set_parent_pom.sh
JoeWang1127 Jan 8, 2024
656d771
add apply_current_versions.sh
JoeWang1127 Jan 8, 2024
a3d91eb
add click option for versions.txt
JoeWang1127 Jan 8, 2024
90a56cd
change dir
JoeWang1127 Jan 8, 2024
7408d42
change find command
JoeWang1127 Jan 8, 2024
bf5bc08
add readme_update.sh
JoeWang1127 Jan 8, 2024
cb93c7b
Merge branch 'feat/move-new-client-script' of github.com:googleapis/s…
JoeWang1127 Jan 8, 2024
68a51ac
change script path
JoeWang1127 Jan 8, 2024
bac6008
refactor
JoeWang1127 Jan 9, 2024
4fd8a17
code refactor
JoeWang1127 Jan 10, 2024
828e5bf
add generator version
JoeWang1127 Jan 10, 2024
b199a71
use GitPython to checkout googleapis
JoeWang1127 Jan 10, 2024
b2d6f8a
code refactor
JoeWang1127 Jan 11, 2024
1823077
use versions.txt in the monorepo
JoeWang1127 Jan 11, 2024
a4c49f7
add comments
JoeWang1127 Jan 11, 2024
598caf6
change year
JoeWang1127 Jan 11, 2024
c83e830
change copyright year
JoeWang1127 Jan 22, 2024
d236788
remove apply_current_versions.sh
JoeWang1127 Jan 23, 2024
c4b610e
add __pychche__ to gitignore
JoeWang1127 Jan 23, 2024
46a6b32
parse generator version from WORKSPACE
JoeWang1127 Jan 23, 2024
bda8041
remove readme_update.sh
JoeWang1127 Jan 23, 2024
4f3fccd
remove update_owlbot_postprocessor_config.sh
JoeWang1127 Jan 24, 2024
b33c765
remove delete_non_generated_samples.sh
JoeWang1127 Jan 24, 2024
594177a
remove set_parent_pom.sh
JoeWang1127 Jan 24, 2024
665316c
Merge branch 'main' into feat/move-new-client-script
JoeWang1127 Jan 24, 2024
4874bbd
add destination_name
JoeWang1127 Jan 24, 2024
1d0ca6c
restore format plugin
JoeWang1127 Jan 24, 2024
68c3eab
remove gitignore
JoeWang1127 Jan 24, 2024
f9b9ad5
remove consolidate_config.sh
JoeWang1127 Jan 24, 2024
45f20b3
Merge branch 'main' into feat/move-new-client-script
JoeWang1127 Jan 25, 2024
787a7a1
change output directory
JoeWang1127 Jan 25, 2024
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ target/

*.iml

# Python
**/__pycache__/

# library generation
output/
library_generation/output/
Expand Down
157 changes: 157 additions & 0 deletions library_generation/new_client/client_inputs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#!/usr/bin/env python3
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from pathlib import Path
import re

proto_library_pattern = r"""
proto_library_with_info\(
(.*?)
\)
"""
gapic_pattern = r"""
java_gapic_library\(
(.*?)
\)
"""
assembly_pattern = r"""
java_gapic_assembly_gradle_pkg\(
(.*?)
\)
"""
resource_pattern = r"//google/cloud:common_resources_proto"
location_pattern = r"//google/cloud/location:location_proto"
iam_pattern = r"//google/iam/v1:iam_policy_proto"
transport_pattern = r"transport = \"(.*?)\""
rest_pattern = r"rest_numeric_enums = True"
gapic_yaml_pattern = r"gapic_yaml = \"(.*?)\""
service_config_pattern = r"grpc_service_config = \"(.*?)\""
service_yaml_pattern = r"service_yaml = \"(.*?)\""
include_samples_pattern = r"include_samples = True"


class ClientInput:
"""
A data class containing inputs to invoke generate_library.sh to generate
a GAPIC library.
"""
def __init__(
self,
proto_only="true",
additional_protos="google/cloud/common_resources.proto",
transport="",
rest_numeric_enum="",
gapic_yaml="",
service_config="",
service_yaml="",
include_samples="true",
):
self.proto_only = proto_only
self.additional_protos = additional_protos
self.transport = transport
self.rest_numeric_enum = rest_numeric_enum
self.gapic_yaml = gapic_yaml
self.service_config = service_config
self.service_yaml = service_yaml
self.include_samples = include_samples


def parse(
build_path: Path,
versioned_path: str,
) -> ClientInput:
"""
Utility function to parse inputs of generate_library.sh from BUILD.bazel.
:param build_path: the file path of BUILD.bazel
:param versioned_path: a versioned path in googleapis repository, e.g.,
google/cloud/asset/v1.
:return: an ClientInput object.
"""
with open(f"{build_path}/BUILD.bazel") as build:
content = build.read()

proto_library_target = re.compile(
proto_library_pattern, re.DOTALL | re.VERBOSE
).findall(content)[0]
additional_protos = __parse_additional_protos(proto_library_target)
gapic_target = re.compile(gapic_pattern, re.DOTALL | re.VERBOSE)\
.findall(content)
assembly_target = re.compile(assembly_pattern, re.DOTALL | re.VERBOSE)\
.findall(content)
include_samples = __parse_include_samples(assembly_target[0])
if len(gapic_target) == 0:
return ClientInput(
include_samples=include_samples
)

transport = __parse_transport(gapic_target[0])
rest_numeric_enum = __parse_rest_numeric_enums(gapic_target[0])
gapic_yaml = __parse_gapic_yaml(gapic_target[0], versioned_path)
service_config = __parse_service_config(gapic_target[0], versioned_path)
service_yaml = __parse_service_yaml(gapic_target[0], versioned_path)

return ClientInput(
proto_only="false",
additional_protos=additional_protos,
transport=transport,
rest_numeric_enum=rest_numeric_enum,
gapic_yaml=gapic_yaml,
service_config=service_config,
service_yaml=service_yaml,
include_samples=include_samples,
)


def __parse_additional_protos(proto_library_target: str) -> str:
res = [" "]
if len(re.findall(resource_pattern, proto_library_target)) != 0:
res.append("google/cloud/common_resources.proto")
if len(re.findall(location_pattern, proto_library_target)) != 0:
res.append("google/cloud/location/locations.proto")
if len(re.findall(iam_pattern, proto_library_target)) != 0:
res.append("google/iam/v1/iam_policy.proto")
return " ".join(res)


def __parse_transport(gapic_target: str) -> str:
transport = re.findall(transport_pattern, gapic_target)
return transport[0] if len(transport) != 0 else "grpc"


def __parse_rest_numeric_enums(gapic_target: str) -> str:
rest_numeric_enums = re.findall(rest_pattern, gapic_target)
return "true" if len(rest_numeric_enums) != 0 else "false"


def __parse_gapic_yaml(gapic_target: str, versioned_path: str) -> str:
gapic_yaml = re.findall(gapic_yaml_pattern, gapic_target)
return f"{versioned_path}/{gapic_yaml[0]}" if len(gapic_yaml) != 0 else ""


def __parse_service_config(gapic_target: str, versioned_path: str) -> str:
service_config = re.findall(service_config_pattern, gapic_target)
return f"{versioned_path}/{service_config[0]}" if len(service_config) != 0 \
else ""


def __parse_service_yaml(gapic_target: str, versioned_path: str) -> str:
service_yaml = re.findall(service_yaml_pattern, gapic_target)
return f"{versioned_path}/{service_yaml[0]}" if len(service_yaml) != 0 \
else ""


def __parse_include_samples(assembly_target: str) -> str:
include_samples = re.findall(include_samples_pattern, assembly_target)
return "true" if len(include_samples) != 0 else "false"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
curl --silent 'https://raw.githubusercontent.com/googleapis/googleapis/master/WORKSPACE' | perl -nle 'print $1 if m/_gapic_generator_java_version\s+=\s+\"(.+)\"/'
Loading
Loading