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.

Comments (0)

Files changed (1)

 
     # 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.

      1. Florent Xicluna

        Why do you believe that parse_argv is required in the first place? What happens if you remove it?

        I saw your MP on pep8.py, I try to understand the use case.

+        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:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.