Commits

Florian Rathgeber  committed d325cf7

Git hook respects local configuration files

If none of the Git hook default parameters are overridden, do not
pass them in to the StyleGuide to not override the local
configuration.

  • Participants
  • Parent commits 697b409

Comments (0)

Files changed (1)

File flake8/hooks.py

 
     # Returns the exit code, list of files modified, list of error messages
     _, files_modified, _ = run(gitcmd)
+
+    # We only want to pass ignore and max_complexity if they differ from the
+    # defaults so that we don't override a local configuration file
+    options = {}
+    if ignore:
+        options['ignore'] = ignore
+    if complexity > -1:
+        options['max_complexity'] = complexity
+
     files_modified = [f for f in files_modified if f.endswith('.py')]
 
     flake8_style = get_style_guide(
-        config_file=DEFAULT_CONFIG, ignore=ignore, max_complexity=complexity)
+        parse_argv=True,
  1. megies

    This change breaks the git hook for me in 2.1.0. The git hook exits with error:

    Usage: flake8 [options] input ...
    
    flake8: error: input not specified
    
    1. Florian Rathgeber author

      That is only the case if you don't have any configuration file i.e. setup.cfg, tox.ini etc. I hadn't tested for that, apologies. The entire point of this pull request was to make the hook respect the config files, but I hadn't realised it breaks the case where you don't have a config file. I'll need to think how to make it work for both cases.

+        config_file=DEFAULT_CONFIG,
+        **options
+        )
 
     # Copy staged versions to temporary directory
     tmpdir = mkdtemp()
     """
     complexity = ui.config('flake8', 'complexity', default=-1)
     strict = ui.configbool('flake8', 'strict', default=True)
+    ignore = ui.config('flake8', 'ignore', default=None)
     config = ui.config('flake8', 'config', default=True)
     if config is True:
         config = DEFAULT_CONFIG
 
     paths = _get_files(repo, **kwargs)
 
-    flake8_style = get_style_guide(
-        config_file=config, max_complexity=complexity)
+    # We only want to pass ignore and max_complexity if they differ from the
+    # defaults so that we don't override a local configuration file
+    options = {}
+    if ignore:
+        options['ignore'] = ignore
+    if complexity > -1:
+        options['max_complexity'] = complexity
+
+    flake8_style = get_style_guide(parse_argv=True, config_file=config,
+                                   **options)
     report = flake8_style.check_files(paths)
 
     if strict: