def _load(self): log.debug("reading `%s'", self.path) sys.path.insert(0, dirname(self.path)) try: source = open(self.path).read() code = compile(source, self.path, 'exec') globs = { '__builtins__': sys.modules['__builtin__'], '__file__': str(self.path), '__name__': splitext(basename(self.path))[0], '_mk_makefile_': self, #TODO: is _mk_ns_ necessary? '_mk_ns_': self.ns, } mod = eval(code, globs) finally: sys.path.remove(dirname(self.path)) self.doc = mod.__doc__ default_tasks = [t for t in self.tasks.values() if t.default] if not default_tasks: self.default_task = None elif len(default_tasks) == 1: self.default_task = default_tasks[0] else: raise IllegalMakefileError("more than one default task: %s" % ', '.join(map(str, default_tasks)))
def include(makefile_path, ns=None): # Makefile loading places some state on the module at '_mk_*_' # attributes. f = sys._getframe(1) parent = f.f_globals["_mk_makefile_"] # If the included path is relative it must be relative to the # including Makefile. if not isabs(makefile_path): parent_makefile_dir = dirname(f.f_code.co_filename) makefile_path = normpath(join(relpath(parent_makefile_dir), makefile_path)) ns_str = ns and " (ns=%r)" % ns or "" log.debug("include makefile `%s'%s", makefile_path, ns_str) #TODO: not sure what todo about config_file_path_override (defer) ns_list = (parent.ns or []) + (ns and [ns] or []) makefile = Makefile(makefile_path, parent.master, ns=ns_list, parent=parent) parent.includes.append(makefile)
def include(makefile_path, ns=None): # Makefile loading places some state on the module at '_mk_*_' # attributes. f = sys._getframe(1) parent = f.f_globals["_mk_makefile_"] # If the included path is relative it must be relative to the # including Makefile. if not isabs(makefile_path): parent_makefile_dir = dirname(f.f_code.co_filename) makefile_path = normpath( join(relpath(parent_makefile_dir), makefile_path)) ns_str = ns and " (ns=%r)" % ns or "" log.debug("include makefile `%s'%s", makefile_path, ns_str) #TODO: not sure what todo about config_file_path_override (defer) ns_list = (parent.ns or []) + (ns and [ns] or []) makefile = Makefile(makefile_path, parent.master, ns=ns_list, parent=parent) parent.includes.append(makefile)