def __init__(self): local_clone = os.environ.get("SYNTHTOOL_GOOGLEAPIS_GEN") if local_clone: self._googleapis_gen = Path(local_clone).expanduser() logger.debug( f"Using local googleapis-gen at {self._googleapis_gen}") else: logger.debug("Cloning googleapis-gen.") self._googleapis_gen = git.clone( git.make_repo_clone_url("googleapis/googleapis-gen"))
# limitations under the License. import getpass from pathlib import Path from typing import List, Mapping, Optional, Union import os import platform import tempfile from synthtool import _tracked_paths from synthtool import log from synthtool import metadata from synthtool import shell from synthtool.sources import git GOOGLEAPIS_URL: str = git.make_repo_clone_url("googleapis/googleapis") GOOGLEAPIS_PRIVATE_URL: str = git.make_repo_clone_url( "googleapis/googleapis-private") LOCAL_GOOGLEAPIS: Optional[str] = os.environ.get("SYNTHTOOL_GOOGLEAPIS") class GAPICMicrogenerator: """A synthtool component that can produce libraries using microgenerators. A microgenerator is any code generator that follows the code generation specification defined at https://aip.dev/client-libraries """ def __init__(self): # Docker on mac by default cannot use the default temp file location # instead use the more standard *nix /tmp location. if platform.system() == "Darwin":
# 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 from typing import Optional, Union import os import shutil import tempfile from synthtool import _tracked_paths, metadata, shell from synthtool.log import logger from synthtool.sources import git GOOGLEAPIS_URL: str = git.make_repo_clone_url("googleapis/googleapis") GOOGLEAPIS_PRIVATE_URL: str = git.make_repo_clone_url("googleapis/googleapis-private") DISCOVERY_ARTIFACT_MANAGER_URL: str = git.make_repo_clone_url( "googleapis/discovery-artifact-manager" ) LOCAL_GOOGLEAPIS: Optional[str] = os.environ.get("SYNTHTOOL_GOOGLEAPIS") LOCAL_DISCOVERY_ARTIFACT_MANAGER: Optional[str] = os.environ.get( "SYNTHTOOL_DISCOVERY_ARTIFACT_MANAGER" ) class GAPICBazel: """A synthtool component that can produce libraries using bazel build. """ def __init__(self):
import os import re import shutil import yaml from copy import deepcopy from pathlib import Path from typing import Dict, List, Optional import jinja2 from synthtool import shell, _tracked_paths from synthtool.languages import node from synthtool.log import logger from synthtool.sources import git, templates PathOrStr = templates.PathOrStr TEMPLATES_URL: str = git.make_repo_clone_url("googleapis/synthtool") DEFAULT_TEMPLATES_PATH = "synthtool/gcp/templates" LOCAL_TEMPLATES: Optional[str] = os.environ.get("SYNTHTOOL_TEMPLATES") class CommonTemplates: def __init__(self, template_path: Optional[Path] = None): if template_path: self._template_root = template_path elif LOCAL_TEMPLATES: logger.debug(f"Using local templates at {LOCAL_TEMPLATES}") self._template_root = Path(LOCAL_TEMPLATES) else: templates_git = git.clone(TEMPLATES_URL) self._template_root = templates_git / DEFAULT_TEMPLATES_PATH
def test_make_repo_clone_url(monkeypatch): monkeypatch.setattr(git, "USE_SSH", True) assert (git.make_repo_clone_url("theacodes/nox") == "[email protected]:theacodes/nox.git")
def test_make_repo_clone_url_https(monkeypatch): monkeypatch.setattr(git, "USE_SSH", False) assert (git.make_repo_clone_url("theacodes/nox") == "https://github.com/theacodes/nox.git")
import synthtool as s import synthtool.gcp as gcp from synthtool.languages import python from synthtool.sources import git API_COMMON_PROTOS_REPO = "googleapis/api-common-protos" GOOGLEAPIS_REPO = "googleapis/googleapis" # ---------------------------------------------------------------------------- # Get api-common-protos # ---------------------------------------------------------------------------- # Clean up api-common-protos shutil.rmtree('api-common-protos', ignore_errors=True) # Clone api-common-protos api_common_protos_url = git.make_repo_clone_url(API_COMMON_PROTOS_REPO) subprocess.run(["git", "clone", api_common_protos_url]) # This is required in order for s.copy() to work s._tracked_paths.add("api-common-protos/google") excludes = [ # Exclude iam protos (they are released in a separate package) "iam/**/*", "**/BUILD.bazel", ] s.copy("api-common-protos/google", "google", excludes=excludes) # Clean up api-common-protos shutil.rmtree('api-common-protos')
"""This script is used to synthesize generated parts of this library.""" import os from pathlib import Path import tempfile from typing import Union import synthtool as s from synthtool.languages import java from synthtool.sources import git from synthtool import logger, shell versions = ['v1'] GOOGLEAPIS_URL = git.make_repo_clone_url("googleapis/googleapis") logger.debug("Cloning googleapis.") googleapis = git.clone(GOOGLEAPIS_URL) def bazel_build(target: str, cwd: Union[Path, str]) -> Path: """Build a bazel target and return the output build directory.""" old_cwd = os.getcwd() os.chdir(str(cwd)) bazel_run_args = [ "bazel", "--max_idle_secs=240", "build", target, ]
import os import synthtool as s import synthtool.gcp as gcp from synthtool import tmp from synthtool.languages import python from synthtool.sources import git API_COMMON_PROTOS_REPO = "googleapis/api-common-protos" # ---------------------------------------------------------------------------- # Get api-common-protos # ---------------------------------------------------------------------------- # Use api-common-protos as a proper synthtool git source api_common_protos_url = git.make_repo_clone_url(API_COMMON_PROTOS_REPO) api_common_protos = git.clone(api_common_protos_url) / "google" excludes = [ # Exclude iam protos (they are released in a separate package) "iam/**/*", "**/BUILD.bazel", ] s.copy(api_common_protos, excludes=excludes) # ---------------------------------------------------------------------------- # Add templated files # ---------------------------------------------------------------------------- common = gcp.CommonTemplates() templated_files = common.py_library()
# 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. from pathlib import Path from synthtool import _tracked_paths from synthtool.gcp import artman from synthtool.log import logger from synthtool.sources import git DISCOVERY_ARTIFACT_MANAGER_URL: str = git.make_repo_clone_url( "googleapis/discovery-artifact-manager") class DiscoGAPICGenerator: def __init__(self): self._clone_discovery_artifact_manager() def py_library(self, service: str, version: str, **kwargs) -> Path: """ Generates the Python Library files using artman/GAPIC returns a `Path` object library: path to library. 'google/cloud/speech' version: version of lib. 'v1' """ return self._generate_code(service, version, "python", **kwargs)
# ---------------------------------------------------------------------------- # Add templated files # ---------------------------------------------------------------------------- templated_files = common.py_library() # Copy kokoro configs. # Docs are excluded as repo docs cannot currently be generated using sphinx. s.move(templated_files / '.kokoro', excludes=['**/docs/*', 'publish-docs.sh']) # Also move issue templates s.move(templated_files / '.github') # ---------------------------------------------------------------------------- # Copy discoveries folder from discovery-artifact-manager repo # ---------------------------------------------------------------------------- discovery_artifact_manager_url = git.make_repo_clone_url(DISCOVERY_ARTIFACT_MANAGER_REPO) discovery_artifacts = git.clone(discovery_artifact_manager_url) / "discoveries" excludes = [ "**/BUILD.bazel", ] s.copy(discovery_artifacts, "googleapiclient/discovery_cache/documents", excludes=excludes) # ---------------------------------------------------------------------------- # Generate docs # ---------------------------------------------------------------------------- s.shell.run(["nox", "-s", "docs"], hide_output=False)