Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
16 changes: 1 addition & 15 deletions .github/workflows/verify_library_generation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,8 @@ jobs:
set -ex
pushd library_generation
pip install -r requirements.txt
pip install .
popd
- name: install synthtool
shell: bash
run: |
set -ex
mkdir -p /tmp/synthtool
pushd /tmp/synthtool
if [ ! -d "synthtool" ]; then
git clone https://github.com/googleapis/synthtool.git
fi
pushd "synthtool"

git reset --hard origin/no-java-templates

python3 -m pip install -e .
python3 -m pip install -r requirements.in
- name: Run shell unit tests
run: |
set -x
Expand Down
2 changes: 0 additions & 2 deletions library_generation/owlbot/synthtool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

"""Synthtool synthesizes libraries from disparate sources."""

import sys

from synthtool.transforms import (
move,
replace,
Expand Down
15 changes: 4 additions & 11 deletions library_generation/owlbot/synthtool/gcp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,17 @@

import json
import os
import re
import sys
import shutil
import yaml
from pathlib import Path
from typing import Dict, List, Optional
import jinja2
import logging

from synthtool import _tracked_paths
from synthtool.sources import templates

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)


DEFAULT_TEMPLATES_PATH = "synthtool/gcp/templates"
LOCAL_TEMPLATES: Optional[str] = os.environ.get("SYNTHTOOL_TEMPLATES")

# Originally brought from gcp/partials.py.
# These are the default locations to look up
_DEFAULT_PARTIAL_FILES = [
Expand All @@ -44,11 +36,12 @@

class CommonTemplates:
def __init__(self, template_path: Optional[Path] = None):
if LOCAL_TEMPLATES is None:
local_templates = os.environ.get("SYNTHTOOL_TEMPLATES")
if local_templates is None:
logger.error("env var SYNTHTOOL_TEMPLATES must be set")
sys.exit(1)
logger.debug(f"Using local templates at {LOCAL_TEMPLATES}")
self._template_root = Path(LOCAL_TEMPLATES)
logger.debug(f"Using local templates at {local_templates}")
self._template_root = Path(local_templates)
self._templates = templates.Templates(self._template_root)
self.excludes = [] # type: List[str]

Expand Down
75 changes: 0 additions & 75 deletions library_generation/owlbot/synthtool/languages/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import glob
import os
import xml.etree.ElementTree as ET
import re
Expand Down Expand Up @@ -166,80 +165,6 @@ def version_from_maven_metadata(metadata: str) -> Optional[str]:
return None


def _common_generation(
service: str,
version: str,
library: Path,
package_pattern: str,
suffix: str = "",
destination_name: str = None,
cloud_api: bool = True,
diregapic: bool = False,
preserve_gapic: bool = False,
):
"""Helper function to execution the common generation cleanup actions.

Fixes headers for protobuf classes and generated gRPC stub services. Copies
code and samples to their final destinations by convention. Runs the code
formatter on the generated code.

Args:
service (str): Name of the service.
version (str): Service API version.
library (Path): Path to the temp directory with the generated library.
package_pattern (str): Package name template for fixing file headers.
suffix (str, optional): Suffix that the generated library folder. The
artman output differs from bazel's output directory. Defaults to "".
destination_name (str, optional): Override the service name for the
destination of the output code. Defaults to the service name.
preserve_gapic (bool, optional): Whether to preserve the gapic directory
prefix. Default False.
"""

if destination_name is None:
destination_name = service

cloud_prefix = "cloud-" if cloud_api else ""
package_name = package_pattern.format(service=service, version=version)
proto_library_name = f"proto-google-{cloud_prefix}{service}-{version}"
grpc_library_name = f"grpc-google-{cloud_prefix}{service}-{version}"
gapic_library_name = f"gapic-google-{cloud_prefix}{service}-{version}"
fix_proto_headers(library / f"{proto_library_name}{suffix}")
fix_grpc_headers(library / f"{grpc_library_name}{suffix}", package_name)

if preserve_gapic:
s.copy(
[library / f"{gapic_library_name}{suffix}/src"],
f"{gapic_library_name}/src",
required=True,
)
else:
s.copy(
[library / f"{gapic_library_name}{suffix}/src"],
f"google-{cloud_prefix}{destination_name}/src",
required=True,
)

s.copy(
[library / f"{grpc_library_name}{suffix}/src"],
f"{grpc_library_name}/src",
# For REST-only clients, like java-compute, gRPC artifact does not exist
required=(not diregapic),
)
s.copy(
[library / f"{proto_library_name}{suffix}/src"],
f"{proto_library_name}/src",
required=True,
)

if preserve_gapic:
format_code(f"{gapic_library_name}/src")
else:
format_code(f"google-{cloud_prefix}{destination_name}/src")
format_code(f"{grpc_library_name}/src")
format_code(f"{proto_library_name}/src")


def _merge_release_please(destination_text: str):
handle_gh_release_key = "handleGHRelease"
branches_key = "branches"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:
schedule:
- cron: '0 2 * * *'
workflow_dispatch:

{% raw %}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't want to render ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}, use raw to ignore the variable.

jobs:
update-generation-config:
runs-on: ubuntu-22.04
Expand All @@ -40,3 +40,4 @@ jobs:
--repo ${{ github.repository }}
env:
GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
{% endraw %}
1 change: 1 addition & 0 deletions library_generation/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ jinja2==3.1.4
# a list where typing extensions is pinned to >=4.0.1. This will produce an error saying "all requirements
# must have their versions pinned with ==". The following line pins the dependency to a specific version via ==
typing-extensions==4.0.1
requests-mock # used in owlbot unit tests
Loading