def build_compiled_library(self, library): import distutils.errors dist = self._dist dist.libraries = [to_dist_compiled_library(library)] bld_cmd, compiler = self._setup_clib() base, filename = os.path.split(self._compiled_library_filename(library.name, compiler)) old_build_clib = bld_cmd.build_clib if base: # workaround for a distutils issue: distutils put all C libraries # in the same directory, and we cannot control the output directory # from the name - we need to hack build_clib directory bld_cmd.build_clib = os.path.join(old_build_clib, base) try: try: # workaround for yet another bug in distutils: distutils f***s up when # building a static library if the target alread exists on at least mac # os x. target = os.path.join(old_build_clib, base, filename) try: os.remove(target) except OSError: e = extract_exception() if e.errno != errno.ENOENT: raise bld_cmd.run() return [relpath(target, self._build_base)] except distutils.errors.DistutilsError: e = extract_exception() raise BuildError(str(e)) finally: bld_cmd.build_clib = old_build_clib
def build_compiled_library(self, library): import distutils.errors bld_cmd = self.clib_bld_cmd compiler = bld_cmd.compiler base, filename = os.path.split(self._compiled_library_filename(library.name, compiler)) old_build_clib = bld_cmd.build_clib if base: # workaround for a distutils issue: distutils put all C libraries # in the same directory, and we cannot control the output directory # from the name - we need to hack build_clib directory bld_cmd.build_clib = os.path.join(old_build_clib, base) try: try: # workaround for yet another bug in distutils: distutils f***s up when # building a static library if the target alread exists on at least mac # os x. target = os.path.join(old_build_clib, base, filename) try: os.remove(target) except OSError: e = extract_exception() if e.errno != errno.ENOENT: raise build_info = {"sources": library.sources, "include_dirs": library.include_dirs} bld_cmd.build_libraries([(library.name, build_info)]) return [relpath(target, self._build_base)] except distutils.errors.DistutilsError: e = extract_exception() raise bento.errors.BuildError(str(e)) finally: bld_cmd.build_clib = old_build_clib
def _run_hooks(hooks): for hook in hooks: local_node = top_node.find_dir(relpath(hook.local_dir, top_node.abspath())) context.pre_recurse(local_node) try: hook(context) finally: context.post_recurse()
def _run_hooks(hook_iter): for hook, local_dir, help_bypass in hook_iter: local_node = top_node.find_dir(relpath(local_dir, top_node.abspath())) ctx.pre_recurse(local_node) try: if not ctx.help: hook(ctx) finally: ctx.post_recurse()
def set_local_ctx(ctx, hook, local_dir): local_node = top.find_dir( relpath(local_dir, top.abspath())) spkg = get_subpackage(local_node) ctx.local_dir = local_dir ctx.local_node = local_node ctx.top_node = top ctx.local_pkg = spkg ctx.pkg = pkg return hook(ctx)
def _recurse(subento, cwd): f = os.path.join(cwd, subento, "bento.info") if not os.path.exists(f): raise ValueError("%s not found !" % f) filenames.append(f) fid = open(f) try: key = relpath(f, source_dir) rdir = relpath(os.path.join(cwd, subento), source_dir) d = raw_parse(fid.read(), f) kw, subentos = raw_to_subpkg_kw(d) subpackages[key] = SubPackageDescription(rdir, **kw) filenames.extend([os.path.join(cwd, subento, h) for h in subpackages[key].hook_files]) for s in subentos: _recurse(s, os.path.join(cwd, subento)) finally: fid.close()
def _recurse(subento, cwd): f = os.path.normpath(os.path.join(cwd, subento, "bento.info")) if not os.path.exists(f): raise ValueError("%s not found !" % f) filenames.append(relpath(f, source_dir)) fid = open(f) try: key = relpath(f, source_dir) rdir = relpath(os.path.join(cwd, subento), source_dir) d = raw_parse(fid.read(), f) kw, subentos = raw_to_subpkg_kw(d) subpackages[key] = SubPackageDescription(rdir, **kw) hooks_as_abspaths = [os.path.normpath(os.path.join(cwd, subento, h)) \ for h in subpackages[key].hook_files] filenames.extend([relpath(f, source_dir) for f in hooks_as_abspaths]) for s in subentos: _recurse(s, os.path.join(cwd, subento)) finally: fid.close()
def iter_data_files(self, top_node): for pkg_name, source_dir, build_dir, files in self.data_files: if files: target_dir = relpath(build_dir, self.build_lib) yield pkg_name, source_dir, op.join("$sitedir", target_dir), files if self.monkey_patch_mode == "setuptools_numpy": if self.dist_data_files: assert len(self.dist_data_files[0]) == 2, "Unhandled data files representation" for source_dir, files in self.dist_data_files: yield _convert_numpy_data_files(top_node, source_dir, files) else: yield "", ".", "$sitedir", self.dist_data_files
def build_extension(self, extension): import distutils.errors dist_extension = toyext_to_distext(extension) bld_cmd = self.ext_bld_cmd try: bld_cmd.build_extension(dist_extension) base, filename = os.path.split(self._extension_filename(dist_extension.name, bld_cmd)) fullname = os.path.join(bld_cmd.build_lib, base, filename) return [relpath(fullname, self._build_base)] except distutils.errors.DistutilsError: e = extract_exception() raise BuildError(str(e))
def iter_data_files(self, top_node): for pkg_name, source_dir, build_dir, files in self.data_files: if files: target_dir = relpath(build_dir, self.build_lib) yield pkg_name, source_dir, op.join("$sitedir", target_dir), files if self.monkey_patch_mode == "setuptools_numpy": if self.dist_data_files: assert len(self.dist_data_files[0] ) == 2, "Unhandled data files representation" for source_dir, files in self.dist_data_files: yield _convert_numpy_data_files(top_node, source_dir, files) else: yield "", ".", "$sitedir", self.dist_data_files
def build_extension(self, extension): import distutils.errors dist = self._dist dist.ext_modules = [toyext_to_distext(extension)] bld_cmd, compiler = self._setup_ext() try: bld_cmd.run() base, filename = os.path.split(self._extension_filename(extension.name, bld_cmd)) fullname = os.path.join(bld_cmd.build_lib, base, filename) return [relpath(fullname, self._build_base)] except distutils.errors.DistutilsError: e = extract_exception() raise BuildError(str(e))
def run_cmd_in_context(global_context, cmd, cmd_name, cmd_argv, context_klass, run_node, top_node, package, package_options): """Run the given Command instance inside its context, including any hook and/or override.""" options_context = global_context.retrieve_options_context(cmd_name) context = context_klass(global_context, cmd_argv, options_context, package, run_node) # FIXME: hack to pass package_options to configure command - most likely # this needs to be known in option context ? context.package_options = package_options if get_command_override(cmd_name): cmd_funcs = get_command_override(cmd_name) else: cmd_funcs = [(cmd.run, top_node.abspath())] try: def _run_hooks(hooks): for hook in hooks: local_node = top_node.find_dir(relpath(hook.local_dir, top_node.abspath())) context.pre_recurse(local_node) try: if not context.help: hook(context) finally: context.post_recurse() pre_hooks = global_context.retrieve_pre_hooks(cmd_name) _run_hooks(pre_hooks) while cmd_funcs: cmd_func, local_dir = cmd_funcs.pop(0) local_node = top_node.find_dir(relpath(local_dir, top_node.abspath())) context.pre_recurse(local_node) try: cmd_func(context) finally: context.post_recurse() post_hooks = global_context.retrieve_post_hooks(cmd_name) _run_hooks(post_hooks) cmd.shutdown(context) finally: context.shutdown() return cmd, context
def run_command_in_context(context, cmd, pre_hooks=None, post_hooks=None): """Run the given command instance with the hooks within its context. """ if pre_hooks is None: pre_hooks = [] if post_hooks is None: post_hooks = [] top_node = context.top_node cmd_funcs = [(cmd.run, top_node.abspath())] def _run_hooks(hooks): for hook in hooks: local_node = top_node.find_dir( relpath(hook.local_dir, top_node.abspath())) context.pre_recurse(local_node) try: if not context.help: hook(context) finally: context.post_recurse() context.init() try: cmd.init(context) _run_hooks(pre_hooks) context.configure() while cmd_funcs: cmd_func, local_dir = cmd_funcs.pop(0) local_node = top_node.find_dir( relpath(local_dir, top_node.abspath())) context.pre_recurse(local_node) try: cmd_func(context) finally: context.post_recurse() _run_hooks(post_hooks) cmd.finish(context) finally: context.finish() return cmd, context
def expand_glob(pattern, ref_dir=None): """Expand list of files matching the given pattern, relatively to ref_dir. If no file is matched, a ValueError is raised. """ validate_glob_pattern(pattern) if ref_dir: glob_pattern = join(ref_dir, pattern) else: glob_pattern = pattern matched = glob.glob(glob_pattern) if len(matched) < 1: raise IOError("no files following pattern %s from %r found" % (pattern, ref_dir)) if ref_dir: return [relpath(i, ref_dir) for i in matched] else: return matched
def run_command_in_context(context, cmd, pre_hooks=None, post_hooks=None): """Run the given command instance with the hooks within its context. """ if pre_hooks is None: pre_hooks = [] if post_hooks is None: post_hooks = [] top_node = context.top_node cmd_funcs = [(cmd.run, top_node.abspath())] def _run_hooks(hooks): for hook in hooks: local_node = top_node.find_dir(relpath(hook.local_dir, top_node.abspath())) context.pre_recurse(local_node) try: if not context.help: hook(context) finally: context.post_recurse() context.init() try: cmd.init(context) _run_hooks(pre_hooks) context.configure() while cmd_funcs: cmd_func, local_dir = cmd_funcs.pop(0) local_node = top_node.find_dir(relpath(local_dir, top_node.abspath())) context.pre_recurse(local_node) try: cmd_func(context) finally: context.post_recurse() _run_hooks(post_hooks) cmd.finish(context) finally: context.finish() return cmd, context
def run_cmd_in_context(cmd_klass, cmd_name, cmd_opts, ctx_klass, run_node, top_node, pkg): """Run the given Command instance inside its context, including any hook and/or override.""" cmd = cmd_klass() options_ctx = OPTIONS_REGISTRY.get_options(cmd_name) ctx = ctx_klass(cmd_opts, options_ctx, pkg, run_node) # FIXME: hack to pass package_options to configure command - most likely # this needs to be known in option context ? ctx.package_options = __get_package_options(top_node) if get_command_override(cmd_name): cmd_funcs = get_command_override(cmd_name) else: cmd_funcs = [(cmd.run, top_node.abspath())] try: def _run_hooks(hook_iter): for hook, local_dir, help_bypass in hook_iter: local_node = top_node.find_dir(relpath(local_dir, top_node.abspath())) ctx.pre_recurse(local_node) try: if not ctx.help: hook(ctx) finally: ctx.post_recurse() _run_hooks(get_pre_hooks(cmd_name)) while cmd_funcs: cmd_func, local_dir = cmd_funcs.pop(0) local_node = top_node.find_dir(relpath(local_dir, top_node.abspath())) ctx.pre_recurse(local_node) try: cmd_func(ctx) finally: ctx.post_recurse() _run_hooks(get_post_hooks(cmd_name)) cmd.shutdown(ctx) finally: ctx.shutdown()