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

feat: skip README rendering if .repo-metadata.json does not exist #213

Merged
merged 5 commits into from
Mar 27, 2019
Merged
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
11 changes: 10 additions & 1 deletion synthtool/gcp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions synthtool/sources/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down