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

chore: refactor new-client.py #2422

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import templates
from git import Repo
from client_inputs import parse
from repo_level_post_processor import repo_level_post_process
import shutil


Expand Down Expand Up @@ -156,10 +157,10 @@ def main(ctx):
help="If it exists, link to the RPC Documentation for a service"
)
@click.option(
"--split-repo",
"--is-monorepo",
type=bool,
default=False,
help="Whether generating a library into a split repository"
default=True,
help="Whether generating a library into a monorepo, e.g., google-cloud-java"
)
def generate(
api_shortname,
Expand All @@ -180,7 +181,7 @@ def generate(
googleapis_url,
rest_docs,
rpc_docs,
split_repo,
is_monorepo,
):
cloud_prefix = "cloud-" if cloud_api else ""

Expand All @@ -204,7 +205,7 @@ def generate(
sys.exit("api_shortname is empty")

repo = "googleapis/google-cloud-java"
if split_repo:
if not is_monorepo:
repo = f"{language}-{output_name}"

repo_metadata = {
Expand Down Expand Up @@ -237,7 +238,7 @@ def generate(
"Couldn't create the module because "
f"the module {workdir} already exists. In Java client library "
"generation, a new API version of an existing module does not "
"require new-client.py invocation. "
"require generate_repo.py invocation. "
"See go/yoshi-java-new-client#adding-a-new-service-version-by-owlbot."
)
print(f"Creating a new module {workdir}")
Expand Down Expand Up @@ -301,7 +302,7 @@ def generate(
)
repo_root_dir = Path(f"{sys.path[0]}/../../").resolve()
generator_version = subprocess.check_output(
["library_generation/new_client/get_generator_version_from_workspace.sh"],
["library_generation/repo_generation/get_generator_version_from_workspace.sh"],
cwd=repo_root_dir
).strip()
print(f"Generator version: {generator_version}")
Expand Down Expand Up @@ -344,28 +345,12 @@ def generate(
name_prefix="java-"
)

# Repo level post process
script_dir = "library_generation/repo-level-postprocess"

print("Regenerating root pom.xml")
subprocess.check_call(
[
f"{script_dir}/generate_root_pom.sh",
f"{output_dir}"
],
cwd=repo_root_dir,
repo_level_post_process(
repo_root_dir=repo_root_dir,
output_dir=output_dir,
is_monorepo=is_monorepo
)

if not split_repo:
print("Regenerating the GAPIC BOM")
subprocess.check_call(
[
f"{script_dir}/generate_gapic_bom.sh",
f"{output_dir}"
],
cwd=repo_root_dir,
)

print("Deleting temp files")
subprocess.check_call(
[
Expand Down
49 changes: 49 additions & 0 deletions library_generation/repo_generation/repo_level_post_processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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
#
# https://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.
import subprocess
from pathlib import Path


def repo_level_post_process(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we write unit tests for new Python scripts if possible?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to what @diegomarquezp did in his PR

Copy link
Collaborator Author

@JoeWang1127 JoeWang1127 Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I add unit tests after #2342 is merged since the python unit test infrastructure is setup in that PR.

Also, I still need another PR to refactor generate_repo.py and I'll include more unit tests and integration tests in that PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoeWang1127 I added a few units for ClientInputs in #2342

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I'm moving ClientInputs to library_generation/model since it defines a structural class. Better wait for mine to get merged

repo_root_dir: Path,
output_dir: Path,
is_monorepo: bool = True,
) -> None:
"""
Perform post-processing at the repository level.
:param repo_root_dir: the path to the repository root
:param output_dir: the output path of the post-processing
:param is_monorepo: whether the repository is a monorepo or not
"""
script_dir = "library_generation/repo-level-postprocess"

print("Running post-processing at the repository level...")
print("Regenerating root pom.xml")
subprocess.check_call(
[
f"{script_dir}/generate_root_pom.sh",
f"{output_dir}"
],
cwd=repo_root_dir,
)

if is_monorepo:
print("Regenerating the GAPIC BOM in the monorepo")
subprocess.check_call(
[
f"{script_dir}/generate_gapic_bom.sh",
f"{output_dir}"
],
cwd=repo_root_dir,
)
Loading