import sublime
import sublime_plugin

import os
from os import path

from .src.build import build_yaml_macros

class BuildYamlMacrosCommand(sublime_plugin.WindowCommand):
    def run(self, working_dir=None):
        if working_dir:
            os.chdir(working_dir)

        view = self.window.active_view();
        source_path = view.file_name()

        output_path, extension = path.splitext(source_path)

        if extension != '.yaml-macros': raise "Not a .yaml-macros file!"

        with open(output_path, 'w') as output_file:

            build_yaml_macros(
                view.substr( sublime.Region(0, view.size()) ),
                output_file,
                {
                    "file_path": source_path
                },
            )

import sublime
import sublime_plugin

import os
from os import path

from .src.build import build_yaml_macros

class BuildYamlMacrosCommand(sublime_plugin.WindowCommand):
    def run(self, working_dir=None):
        if working_dir:
            os.chdir(working_dir)

        view = self.window.active_view();
        source_path = view.file_name()

        output_path, extension = path.splitext(source_path)

        if extension != '.yaml-macros': raise "Not a .yaml-macros file!"

        output_file = open(output_path, 'w')

        build_yaml_macros(
            view.substr( sublime.Region(0, view.size()) ),
            output_file,
            {
                "file_path": source_path
            },
        )

--- 
+++ 
@@ -18,12 +18,12 @@
 
         if extension != '.yaml-macros': raise "Not a .yaml-macros file!"
 
-        output_file = open(output_path, 'w')
+        with open(output_path, 'w') as output_file:
 
-        build_yaml_macros(
-            view.substr( sublime.Region(0, view.size()) ),
-            output_file,
-            {
-                "file_path": source_path
-            },
-        )
+            build_yaml_macros(
+                view.substr( sublime.Region(0, view.size()) ),
+                output_file,
+                {
+                    "file_path": source_path
+                },
+            )
Use with context manager to handle file access

Currently, after the build completes the output file is not closed, and so it remains locked and is unable to be edited by other processes.