def inject(self): for file in recursive_path_iterate(self.path, "*"): with open(file) as file_pointer: content = file_pointer.read() template = DottedTemplate(content) with open(file, "w") as file_pointer: file_pointer.write(template.substitute(self.config))
def create(self, directory): setup_py_template = DottedTemplate(SETUP_PY_TEMPLATE) setup_py = setup_py_template.substitute(self.config) additional_options = self._get_additional_options() setup_py = setup_py.format(additional_options=additional_options) with open(os.path.join(directory, PythonSetupPyCreator.FILE_NAME), "w") as setup_py_pointer: setup_py_pointer.write(setup_py)
def test_transform_dictionary(): my_dict = {"key1": "value", "key1.key2": "value2", "key1.key2.key3": "value3"} expected_dict = {"${key1}": "value", "${key1.key2}": "value2", "${key1.key2.key3}": "value3"} transformed_dict = DottedTemplate.transform_dictionary(my_dict) assert expected_dict == transformed_dict
def test_transform_dictionary(): my_dict = { "key1": "value", "key1.key2": "value2", "key1.key2.key3": "value3" } expected_dict = { "${key1}": "value", "${key1.key2}": "value2", "${key1.key2.key3}": "value3" } transformed_dict = DottedTemplate.transform_dictionary(my_dict) assert expected_dict == transformed_dict
def _set_references(config): for key, value in config.items(): if isinstance(value, str): value_template = DottedTemplate(value) value = value_template.substitute(config) config[key] = value
def test_dotted_template(): template = DottedTemplate("Hello ${project.name}.") result = template.substitute({"project.name": "World"}) assert "Hello World." == result
def test_multiple_dots(): template = DottedTemplate("Hello ${base.project.name}.") result = template.substitute({"base.project.name": "World"}) assert "Hello World." == result
def create(self, directory): setup_cfg_template = DottedTemplate(SETUP_CFG_TEMPLATE) with open(os.path.join(directory, "setup.cfg"), "w") as setup_cfg_pointer: setup_cfg_pointer.write(setup_cfg_template.substitute(self.config))