-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move synthtool templates to
library_generation/owlbot
(#2443)
This PR transfers the java-specific templates from synthtool to `library_geneation/owlbot` There is a new branch in synthtool (googleapis/synthtool#1923) that has the removed templates. The intention is to keep that synthtool branch as parallel until we fully roll out the hermetic build workflows to both HW libraries and the monorepo. ### Approach We add a list of template exclusions to the configuration yaml and call `java.common_templates` with a custom template path (pointing to our OwlBot Java Postprocessor implementation here in `library_generation` plus the template exclusions found in the yaml. The list of exclusions were obtained from owlbot.py files. Since google-cloud-java has the same exclusions for all libraries, we use a repo-level configuration entry. An example of template excludes is: https://github.com/googleapis/sdk-platform-java/blob/b0a57b70d589e2bdc6e5fcb8cf64d08c3496bc57/java-iam/owlbot.py#L26-L37 ### Different approach possible? We could modify all owlbot.py files to use something other than `java.common_templates`. For example ``` from custom_owlbot import common_templates ... common_templates(excludes=[/*preserved excludes*/]) ``` With such approach, we would not have to parse owlbot.py files and take advantage of the fact it's an executable script. ## Follow up? We probably don't want to call `common_templates` twice, so it may be better to modify owlbot.py files to reference our own implementation instead of synthtool. (This is similar to "Different approach possible?" but it is more of a follow up once the scripts are live). --------- Co-authored-by: Joe Wang <[email protected]>
- Loading branch information
1 parent
dba4c10
commit 5c95472
Showing
26 changed files
with
1,273 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
This script parses an owlbot.py file, specifically the call to `java.common_templates` in | ||
order to extract the excluded files so it can be called with a custom template path | ||
pointing to the templates hosted in `sdk-platform-java/library_generation/owlbot/templates`. | ||
Briefly, this wraps the call to synthtool's common templates using a custom template folder. | ||
""" | ||
|
||
import os | ||
import sys | ||
from collections.abc import Sequence | ||
from synthtool.languages.java import common_templates | ||
from pathlib import Path | ||
from library_generation.model.generation_config import from_yaml | ||
|
||
script_dir = os.path.dirname(os.path.realpath(__file__)) | ||
repo_templates_path = os.path.join(script_dir, "..", "templates", "java_library") | ||
|
||
|
||
def apply_repo_templates(configuration_yaml_path: str, monorepo: bool) -> None: | ||
config = from_yaml(configuration_yaml_path) | ||
print(f"repo_templates_path: {repo_templates_path}") | ||
print(f"excludes: {config.template_excludes}") | ||
common_templates( | ||
excludes=config.template_excludes, | ||
template_path=Path(repo_templates_path), | ||
monorepo=monorepo, | ||
) | ||
|
||
|
||
def main(argv: Sequence[str]) -> None: | ||
if len(argv) != 3: | ||
raise ValueError( | ||
"Usage: python apply-repo-templates.py configuration_yaml_path monorepo" | ||
) | ||
|
||
configuration_yaml_path = argv[1] | ||
monorepo = argv[2] | ||
apply_repo_templates(configuration_yaml_path, monorepo.lower() == "true") | ||
|
||
|
||
if __name__ == "__main__": | ||
main(sys.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.