diff --git a/synthtool/gcp/common.py b/synthtool/gcp/common.py index 80300b003..9b3fb893a 100644 --- a/synthtool/gcp/common.py +++ b/synthtool/gcp/common.py @@ -17,6 +17,7 @@ import re import yaml from pathlib import Path +from typing import List from synthtool.languages import node from synthtool.sources import templates @@ -33,11 +34,14 @@ class CommonTemplates: def __init__(self): self._templates = templates.Templates(_TEMPLATES_DIR) + self.excludes = [] # type: List[str] def _generic_library(self, directory: str, **kwargs) -> Path: + # load common repo meta information (metadata that's not language specific). if "metadata" in kwargs: self._load_generic_metadata(kwargs["metadata"]) - t = templates.TemplateGroup(_TEMPLATES_DIR / directory) + + t = templates.TemplateGroup(_TEMPLATES_DIR / directory, self.excludes) result = t.render(**kwargs) _tracked_paths.add(result) metadata.add_template_source( @@ -49,6 +53,11 @@ def py_library(self, **kwargs) -> Path: return self._generic_library("python_library", **kwargs) def node_library(self, **kwargs) -> Path: + # TODO: once we've migrated all Node.js repos to either having + # .repo-metadata.json, or excluding README.md, we can remove this. + if not os.path.exists("./.repo-metadata.json"): + self.excludes.append("README.md") + kwargs["metadata"] = node.read_metadata() kwargs["publish_token"] = node.get_publish_token(kwargs["metadata"]["name"]) return self._generic_library("node_library", **kwargs) diff --git a/synthtool/sources/templates.py b/synthtool/sources/templates.py index a9a94cb07..e9ee5a0a5 100644 --- a/synthtool/sources/templates.py +++ b/synthtool/sources/templates.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Union +from typing import Union, List from pathlib import Path import jinja2 @@ -69,14 +69,18 @@ def render(self, template_name: str, **kwargs) -> Path: class TemplateGroup: - def __init__(self, location: PathOrStr) -> None: + def __init__(self, location: PathOrStr, excludes: List[str] = []) -> None: self.env = _make_env(location) self.dir = tmp.tmpdir() + self.excludes = excludes def render(self, **kwargs) -> Path: for template_name in self.env.list_templates(): - print(template_name) - _render_to_path(self.env, template_name, self.dir, kwargs) + if template_name not in self.excludes: + print(template_name) + _render_to_path(self.env, template_name, self.dir, kwargs) + else: + print(f"Skipping: {template_name}") return self.dir