<commit_before># Copyright (C) <NAME> <<EMAIL>>
# See LICENSE for details.

from glob import glob
from os import listdir
from os.path import basename, isdir, join

import bottle

from platformio import util


class ProjectGenerator(object):

    def __init__(self, project_dir, ide):
        self.project_dir = project_dir
        self.ide = ide
        self._tplvars = self._gather_tplvars()

    @staticmethod
    def get_supported_ides():
        tpls_dir = join(util.get_source_dir(), "ide", "tpls")
        return [d for d in listdir(tpls_dir)
                if isdir(join(tpls_dir, d))]

    @staticmethod
    def get_project_env():
        data = {}
        config = util.get_project_config()
        for section in config.sections():
            if not section.startswith("env:"):
                continue
            for k, v in config.items(section):
                data[k] = v
        return data

    def get_project_name(self):
        return basename(self.project_dir)

    def get_includes(self):
        return []

    def get_srcfiles(self):
        return []

    def get_tpls(self):
        tpls_dir = join(util.get_source_dir(), "ide", "tpls", self.ide)
        return glob(join(tpls_dir, ".*.tpl")) + glob(join(tpls_dir, "*.tpl"))

    def generate(self):
        for tpl_path in self.get_tpls():
            file_name = basename(tpl_path)[:-4]
            with open(join(self.project_dir, file_name), "w") as f:
                f.write(self._render_tpl(tpl_path).encode("utf8"))

    def _render_tpl(self, tpl_path):
        content = ""
        with open(tpl_path) as f:
            content = f.read()
        return bottle.template(content, **self._tplvars)

    def _gather_tplvars(self):
        data = self.get_project_env()

        data.update({
            "project_name": self.get_project_name(),
            "includes": self.get_includes(),
            "srcfiles": self.get_srcfiles()
        })

        return data<commit_msg>Fix gathering of _tplvars<commit_after># Copyright (C) <NAME> <<EMAIL>>
# See LICENSE for details.

from glob import glob
from os import listdir
from os.path import basename, isdir, join

import bottle

from platformio import util


class ProjectGenerator(object):

    def __init__(self, project_dir, ide):
        self.project_dir = project_dir
        self.ide = ide
        self._tplvars = {}

        self._gather_tplvars()

    @staticmethod
    def get_supported_ides():
        tpls_dir = join(util.get_source_dir(), "ide", "tpls")
        return [d for d in listdir(tpls_dir)
                if isdir(join(tpls_dir, d))]

    @staticmethod
    def get_project_env():
        data = {}
        config = util.get_project_config()
        for section in config.sections():
            if not section.startswith("env:"):
                continue
            for k, v in config.items(section):
                data[k] = v
        return data

    def get_project_name(self):
        return basename(self.project_dir)

    def get_includes(self):
        return []

    def get_srcfiles(self):
        return []

    def get_tpls(self):
        tpls_dir = join(util.get_source_dir(), "ide", "tpls", self.ide)
        return glob(join(tpls_dir, ".*.tpl")) + glob(join(tpls_dir, "*.tpl"))

    def generate(self):
        for tpl_path in self.get_tpls():
            file_name = basename(tpl_path)[:-4]
            with open(join(self.project_dir, file_name), "w") as f:
                f.write(self._render_tpl(tpl_path).encode("utf8"))

    def _render_tpl(self, tpl_path):
        content = ""
        with open(tpl_path) as f:
            content = f.read()
        return bottle.template(content, **self._tplvars)

    def _gather_tplvars(self):
        self._tplvars.update(self.get_project_env())

        self._tplvars.update({
            "project_name": self.get_project_name(),
            "includes": self.get_includes(),
            "srcfiles": self.get_srcfiles()
        })
{'fraction_non_alphanumeric': 0.11794482409516578, 'fraction_numerical': 0.0010124019235636548, 'mean_word_length': 2.3210084033613447, 'pattern_counts': {'":': 6, '<': 9, '<?xml version=': 0, '>': 9, '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': '801223', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1257, 'n_words': 285}