<commit_before>import yaml

from tempfile import NamedTemporaryFile

from hokusai.lib.config import config
from hokusai.lib.config_loader import ConfigLoader
from hokusai.lib.template_renderer import TemplateRenderer

from hokusai.lib.exceptions import HokusaiError

from hokusai.services.ecr import ECR

class KubernetesSpec(object):
  def __init__(self, kubernetes_yaml):
    self.kubernetes_yaml = kubernetes_yaml
    self.ecr = ECR()

  def to_string(self):
    template_config = {
      "project_name": config.project_name,
      "project_repo": self.ecr.project_repo
    }

    if config.template_config_files:
      for template_config_file in config.template_config_files:
        config_loader = ConfigLoader(template_config_file)
        template_config.update(config_loader.load())

    return TemplateRenderer(self.kubernetes_yaml, template_config).render()

  def to_file(self):
    f = NamedTemporaryFile(delete=False)
    f.write(self.to_string())
    f.close()
    return f.name

  def to_list(self):
    return list(yaml.safe_load_all(self.to_string()))<commit_msg>update KubernetesSpec to print out rendered template if DEBUG env var is set<commit_after>import os

import yaml

from tempfile import NamedTemporaryFile

from hokusai.lib.config import config
from hokusai.lib.config_loader import ConfigLoader
from hokusai.lib.template_renderer import TemplateRenderer

from hokusai.lib.exceptions import HokusaiError

from hokusai.services.ecr import ECR

class KubernetesSpec(object):
  def __init__(self, kubernetes_yaml):
    self.kubernetes_yaml = kubernetes_yaml
    self.ecr = ECR()

  def to_string(self):
    template_config = {
      "project_name": config.project_name,
      "project_repo": self.ecr.project_repo
    }

    if config.template_config_files:
      for template_config_file in config.template_config_files:
        config_loader = ConfigLoader(template_config_file)
        template_config.update(config_loader.load())

    rendered_template = TemplateRenderer(self.kubernetes_yaml, template_config).render()

    if os.environ.get('DEBUG'):
      print(rendered_template)

    return rendered_template

  def to_file(self):
    f = NamedTemporaryFile(delete=False)
    f.write(self.to_string())
    f.close()
    return f.name

  def to_list(self):
    return list(yaml.safe_load_all(self.to_string()))
{'fraction_non_alphanumeric': 0.08102345415778252, 'fraction_numerical': 0.0, 'mean_word_length': 4.455813953488372, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5545674', 'n_tokens_mistral': 742, 'n_tokens_neox': 722, 'n_words': 150}