Skip to content

Commit

Permalink
chore: simplify hiding samples
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Apr 2, 2019
1 parent 1b57231 commit 6428220
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions synthtool/gcp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ 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"])
# if no samples were found, don't attempt to render a
# samples/README.md.
if not kwargs["metadata"]["samples"]:
self.excludes.append("samples/README.md")

t = templates.TemplateGroup(_TEMPLATES_DIR / directory, self.excludes)
result = t.render(**kwargs)
Expand All @@ -61,8 +57,7 @@ def node_library(self, **kwargs) -> Path:
# .repo-metadata.json, or excluding README.md, we can remove this.
if not os.path.exists("./.repo-metadata.json"):
self.excludes.append("README.md")
if "samples/README.md" not in self.excludes:
self.excludes.append("samples/README.md")
self.excludes.append("samples/README.md")

kwargs["metadata"] = node.read_metadata()
kwargs["publish_token"] = node.get_publish_token(kwargs["metadata"]["name"])
Expand Down Expand Up @@ -95,7 +90,7 @@ def _load_samples(self, metadata: Dict):
"file": "requesterPays.js"
}
"""
metadata["samples"] = []
samples = []
samples_dir = Path(os.getcwd()) / "samples"
if os.path.exists(samples_dir):
files = os.listdir(samples_dir)
Expand All @@ -107,9 +102,9 @@ def _load_samples(self, metadata: Dict):
# only add quickstart file to samples list if code sample is found.
if file == "quickstart.js" and not metadata.get("quickstart", None):
continue
metadata["samples"].append(
{"name": decamelize(file[:-3]), "file": file}
)
samples.append({"name": decamelize(file[:-3]), "file": file})
if samples:
metadata["samples"] = samples

def _read_quickstart(self, samples_dir: Path) -> str:
"""
Expand Down

0 comments on commit 6428220

Please sign in to comment.