def validate(self, fname): """ Run installed jshint against a file. """ with utils.temp_config_file(self.configuration) as config_fname: # https://github.com/jshint/node-jshint/ options = self.extra_options if not "--config" in options: if self.configuration and self.configuration.strip() != "": # Make sure we don't pass empty config file as jshint seems to choke on it options += " --config '%s'" % config_fname # W:100,10:Unused variable' # pylint: disable = W0612 exitcode, output = utils.shell( self.logger, 'node %s "%s" %s' % (self.get_jshint_bin(), fname, options)) if "error" in output: self.reporter.report_unstructured(self.id, output, fname=fname) return False return True
def validate(self, fname): """ Run installed jshint against a file. """ with utils.temp_config_file(self.configuration) as config_fname: # https://github.com/jshint/node-jshint/ options = self.extra_options if not "--config" in options: if self.configuration and self.configuration.strip() != "": # Make sure we don't pass empty config file as jshint seems to choke on it options += " --config '%s'" % config_fname # W:100,10:Unused variable' # pylint: disable = W0612 exitcode, output = utils.shell(self.logger, 'node %s "%s" %s' % (self.get_jshint_bin(), fname, options)) if "error" in output: self.reporter.report_unstructured(self.id, output, fname=fname) return False return True
def run_virtualenv_command(self, cmd, raise_error=False): """ Run cmd under host Python or our own virtualenv """ if self.host_python: return utils.shell(self.logger, cmd, raise_error=raise_error) else: return sysdeps.run_virtualenv_command(self.logger, self.virtualenv, cmd, raise_error=raise_error)
def validate(self, fname): """ Run installed pep8 validator against a file. """ options = self.extra_options if self.pep8_command: exitcode, output = utils.shell(self.logger, '%s %s "%s"' % (self.pep8_command, options, fname)) else: exitcode, output = self.run_virtualenv_command('pep8 %s "%s"' % (options, fname)) if exitcode == 0: return True # Validation ok else: self.reporter.report_unstructured(self.id, output, fname=fname) return False
def validate(self, fname): """ Run installed pylint validator against a file. """ with utils.temp_config_file(self.pylint_configuration) as config_fname: options = self.extra_options if not "--rcfile" in options: options += " --rcfile=%s" % config_fname if self.pylint_command: exitcode, output = utils.shell(self.logger, '%s %s "%s"' % (self.pylint_command, options, fname)) else: exitcode, output = self.run_virtualenv_command('pylint %s "%s"' % (options, fname)) if exitcode == 0: return True # Validation ok else: self.reporter.report_unstructured(self.id, output, fname=fname) return False
def validate(self, fname): """ Run installed pylint validator against a file. """ with utils.temp_config_file(self.pylint_configuration) as config_fname: options = self.extra_options if not "--rcfile" in options: options += " --rcfile=%s" % config_fname if self.pylint_command: exitcode, output = utils.shell( self.logger, '%s %s "%s"' % (self.pylint_command, options, fname)) else: exitcode, output = self.run_virtualenv_command( 'pylint %s "%s"' % (options, fname)) if exitcode == 0: return True # Validation ok else: self.reporter.report_unstructured(self.id, output, fname=fname) return False
def precommit_hook(): """ Run pre-commit hook. Pass all command line options to VVV main process and add filename as the last paramter to these. Validate all files. If any of the files fail then abort the commit. """ logging.basicConfig(level=logging.INFO, stream=sys.stdout, format="%(message)s") logger = logging.getLogger("precommit-hook") # Assume repository root is the single argument if len(sys.argv) < 2: sys.exit("Missing git repository as argument") repo_path = sys.argv[-1] if not os.path.exists(repo_path): sys.exit("Repositoty path does not exist: %s" % repo_path) # Get git diff-index output for the repo with utils.temporary_working_directory(repo_path): exit_code, diff_output = utils.shell(logger, GIT_COMMIT_LIST) if exit_code != 0: print("Failed to execute: %s" % GIT_COMMIT_LIST) print(diff_output) sys.exit(1) # Output is just new line separated list of filenames files = diff_output.split("\0") success = True for f in files: # Empty newline after list if f == "": continue f = os.path.join(repo_path, f) if not os.path.exists(f): # Cannot validate files which do not exist # Git delete list? continue # Pass arguments to VVV + add file from commit list args = sys.argv[1:-1] + [f] # Call VVV for this file result = plac.call(main.main, args) # Validation failed if result != 0: success = False # Signal git that the fecal has hitted the rotatory device etc. if not success: sys.exit("VVV validatoin and linting failed")