我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用distutils.log.error()。
def run(self): if not self.has_npm(): log.error("`npm` unavailable. If you're running this command using sudo, make sure `npm` is available to sudo") else: env = os.environ.copy() env['PATH'] = npm_path log.info("Installing build dependencies with npm. This may take a while...") check_call(["npm", "install"], cwd=jsroot, stdout=sys.stdout, stderr=sys.stderr, **prckws) os.utime(node_modules, None) for t in self.targets: if not os.path.exists(t): msg = "Missing file: %s" % t if not self.has_npm(): msg += "\nnpm is required to build a development version of jupyter-" + name raise ValueError(msg) # update package data in case this created new files update_package_data(self.distribution)
def js_prerelease(command, strict=False): """decorator for building minified js/css prior to another command""" class DecoratedCommand(command): def run(self): jsdeps = self.distribution.get_command_obj('jsdeps') if not is_repo and all(os.path.exists(t) for t in jsdeps.targets): # sdist, nothing to do command.run(self) return try: self.distribution.run_command('jsdeps') except Exception as e: missing = [t for t in jsdeps.targets if not os.path.exists(t)] if strict or missing: log.warn('rebuilding js and css failed') if missing: log.error('missing files: %s' % missing) raise e else: log.warn('rebuilding js and css failed (not a problem)') log.warn(str(e)) command.run(self) update_package_data(self.distribution) return DecoratedCommand
def js_prerelease(command, strict=False): """Decorator for building minified js/css prior to another command.""" class DecoratedCommand(command): def run(self): jsdeps = self.distribution.get_command_obj('jsdeps') if not is_repo and all(os.path.exists(t) for t in jsdeps.targets): # sdist, nothing to do command.run(self) return try: self.distribution.run_command('jsdeps') except Exception as e: missing = [t for t in jsdeps.targets if not os.path.exists(t)] if strict or missing: log.warn('rebuilding js and css failed') if missing: log.error('missing files: %s' % missing) raise e else: log.warn('rebuilding js and css failed (not a problem)') log.warn(str(e)) command.run(self) update_package_data(self.distribution) return DecoratedCommand
def run(self): has_npm = self.has_npm() if not has_npm: log.error("`npm` unavailable. If you're running this command using sudo, make sure `npm` is available to sudo") env = os.environ.copy() env['PATH'] = npm_path if self.should_run_npm_install(): log.info("Installing build dependencies with npm. This may take a while...") npmName = self.get_npm_name(); check_call([npmName, 'install'], cwd=node_root, stdout=sys.stdout, stderr=sys.stderr) os.utime(self.node_modules, None) for t in self.targets: if not os.path.exists(t): msg = 'Missing file: %s' % t if not has_npm: msg += '\nnpm is required to build a development version of a widget extension' raise ValueError(msg) # update package data in case this created new files update_package_data(self.distribution)
def run(self): has_npm = self.has_npm() if not has_npm: log.error("`npm` unavailable. If you're running this command using sudo, make sure `npm` is available to sudo") env = os.environ.copy() env['PATH'] = npm_path if self.should_run_npm_install(): log.info("Installing build dependencies with npm. This may take a while...") npm_name = self.get_npm_name() check_call([npm_name, 'install'], cwd=node_root, stdout=sys.stdout, stderr=sys.stderr) os.utime(self.node_modules, None) for t in self.targets: if not os.path.exists(t): msg = 'Missing file: %s' % t if not has_npm: msg += '\nnpm is required to build a development version of a widget extension' raise ValueError(msg) # update package data in case this created new files update_package_data(self.distribution)
def run(self): has_npm = self.has_npm() if not has_npm: log.error("`npm` unavailable. If you're running this command using sudo, make sure `npm` is available to sudo") env = os.environ.copy() env['PATH'] = npm_path if self.should_run_npm_install(): log.info("Installing build dependencies with npm. This may take a while...") check_call(['npm', 'install'], cwd=node_root, stdout=sys.stdout, stderr=sys.stderr) os.utime(self.node_modules, None) for t in self.targets: if not os.path.exists(t): msg = 'Missing file: %s' % t if not has_npm: msg += '\nnpm is required to build a development version of widgetsnbextension' raise ValueError(msg) # update package data in case this created new files update_package_data(self.distribution)
def get_version(self): """extract version number from the b3.egg-info/PKG-INFO file""" log.info(">>> parse B3 version") pkginfo_file = os.path.join(self.build_exe, 'PKG-INFO') pkginfo_version = re.compile( r'^\s*Version:\s*(?P<version>(?P<numbers>\d+\.\d+(?:\.\d+)?)(?P<pre_release>(?:a|b|dev|d)\d*)?(?P<suffix>.*?))\s*$', re.MULTILINE) with open(pkginfo_file, 'r') as f: match = pkginfo_version.search(f.read()) if not match: log.error("could not find version from %s" % pkginfo_file) sys.exit(1) current_b3_version_part1 = match.group("numbers") current_b3_version_part2 = "" if match.group("pre_release"): current_b3_version_part2 += match.group("pre_release") if match.group("suffix"): current_b3_version_part2 += match.group("suffix") return current_b3_version_part1, current_b3_version_part2
def log_error(self, msg, *args, **kw): log.error(msg, *args)
def run_command_hooks(cmd_obj, hook_kind): """Run hooks registered for that command and phase. *cmd_obj* is a finalized command object; *hook_kind* is either 'pre_hook' or 'post_hook'. """ if hook_kind not in ('pre_hook', 'post_hook'): raise ValueError('invalid hook kind: %r' % hook_kind) hooks = getattr(cmd_obj, hook_kind, None) if hooks is None: return for hook in hooks.values(): if isinstance(hook, str): try: hook_obj = resolve_name(hook) except ImportError: err = sys.exc_info()[1] # For py3k raise DistutilsModuleError('cannot find hook %s: %s' % (hook,err)) else: hook_obj = hook if not hasattr(hook_obj, '__call__'): raise DistutilsOptionError('hook %r is not callable' % hook) log.info('running %s %s for command %s', hook_kind, hook, cmd_obj.get_command_name()) try : hook_obj(cmd_obj) except: e = sys.exc_info()[1] log.error('hook %s raised exception: %s\n' % (hook, e)) log.error(traceback.format_exc()) sys.exit(1)
def parse_config(cls): if not os.path.exists('setup.cfg'): return {} cfg = ConfigParser() try: cfg.read('setup.cfg') except Exception as e: if DEBUG: raise log.error( "Error reading setup.cfg: {0!r}\n{1} will not be " "automatically bootstrapped and package installation may fail." "\n{2}".format(e, PACKAGE_NAME, _err_help_msg)) return {} if not cfg.has_section('ah_bootstrap'): return {} config = {} for option, type_ in CFG_OPTIONS: if not cfg.has_option('ah_bootstrap', option): continue if type_ is bool: value = cfg.getboolean('ah_bootstrap', option) else: value = cfg.get('ah_bootstrap', option) config[option] = value return config
def run_command_hooks(cmd_obj, hook_kind): """Run hooks registered for that command and phase. *cmd_obj* is a finalized command object; *hook_kind* is either 'pre_hook' or 'post_hook'. """ if hook_kind not in ('pre_hook', 'post_hook'): raise ValueError('invalid hook kind: %r' % hook_kind) hooks = getattr(cmd_obj, hook_kind, None) if hooks is None: return for hook in hooks.values(): if isinstance(hook, str): try: hook_obj = resolve_name(hook) except ImportError: err = sys.exc_info()[1] # For py3k raise errors.DistutilsModuleError('cannot find hook %s: %s' % (hook,err)) else: hook_obj = hook if not hasattr(hook_obj, '__call__'): raise errors.DistutilsOptionError('hook %r is not callable' % hook) log.info('running %s %s for command %s', hook_kind, hook, cmd_obj.get_command_name()) try : hook_obj(cmd_obj) except: e = sys.exc_info()[1] log.error('hook %s raised exception: %s\n' % (hook, e)) log.error(traceback.format_exc()) sys.exit(1)
def js_prerelease(command, strict=False): """Build minified JS/CSS prior to performing the command.""" class DecoratedCommand(command): """ Used by ``js_prerelease`` to modify JS/CSS prior to running the command. """ def run(self): jsdeps = self.distribution.get_command_obj("jsdeps") if not os.path.exists(".git") and all(os.path.exists(t) for t in jsdeps.targets): command.run(self) return try: self.distribution.run_command("jsdeps") except Exception as e: missing = [t for t in jsdeps.targets if not os.path.exists(t)] if strict or missing: log.warn("Rebuilding JS/CSS failed") if missing: log.error("Missing files: {}".format(missing)) raise e else: log.warn("Rebuilding JS/CSS failed but continuing...") log.warn(str(e)) command.run(self) update_package_data(self.distribution) return DecoratedCommand
def run(self): has_npm = self.has_npm() if not has_npm: log.error("`npm` unavailable. If you're running this command using sudo, " "make sure `npm` is available to sudo") env = os.environ.copy() env['PATH'] = npm_path vjson = os.path.join(node_root, '.VERSION.json') with open(vjson, 'w') as vjsonfile: vjsonfile.write('{"version":"%s"}\n' % VERSION) if self.should_run_npm_install(): log.info("Installing build dependencies with npm. This may take a while...") check_call(['npm', 'install'], cwd=node_root, stdout=sys.stdout, stderr=sys.stderr) os.utime(self.node_modules, None) # TODO: do this with NPM/webpack, not in python shutil.copy(os.path.join(node_root, 'src', 'nbmolviz.css'), os.path.join(here, 'nbmolviz', 'static', 'nbmolviz.css')) with open(self.verfile_path, 'w') as verfile: verfile.write(VERSION) for t in self.targets: if not os.path.exists(t): msg = 'Missing file: %s' % t if not has_npm: msg += '\nnpm is required to build a development version of nbmolviz-js' raise ValueError(msg) print('Wrote version "%s" to "%s"' % (VERSION, self.verfile_path)) # update package data in case this created new files update_package_data(self.distribution) ################################################################### # Actual setup command # ###################################################################