From d6b1baf8af69e37f2eb15116952eddd18995847f Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Sat, 19 Nov 2016 18:59:53 -0600 Subject: [PATCH] Display the local paths from the git hook Instead of displaying the path to the temporary directory, as we always have, it's been requested that we instead display the path to the file that was copied to the temporary directory. Closes #244 --- docs/source/release-notes/3.3.0.rst | 5 +++++ src/flake8/main/git.py | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/docs/source/release-notes/3.3.0.rst b/docs/source/release-notes/3.3.0.rst index 2fb0c92..dc07e7b 100644 --- a/docs/source/release-notes/3.3.0.rst +++ b/docs/source/release-notes/3.3.0.rst @@ -8,6 +8,9 @@ You can view the `3.3.0 milestone`_ on GitLab for more details. - Dramatically improve the performance of Flake8 (`GitLab!156`_) +- Display the local file path instead of the temporary file path when + using the git hook (`GitLab#244`_) + - Fix problem where hooks should only check \*.py files. (See also `GitLab#268`_) @@ -17,6 +20,8 @@ You can view the `3.3.0 milestone`_ on GitLab for more details. .. links .. _3.3.0 milestone: https://gitlab.com/pycqa/flake8/milestones/16 +.. _GitLab#244: + https://gitlab.com/pycqa/flake8/issues/244 .. _GitLab#251: https://gitlab.com/pycqa/flake8/issues/251 .. _GitLab#268: diff --git a/src/flake8/main/git.py b/src/flake8/main/git.py index 5eae0d0..31404d8 100644 --- a/src/flake8/main/git.py +++ b/src/flake8/main/git.py @@ -6,6 +6,7 @@ """ import contextlib import os +import os.path import shutil import stat import subprocess @@ -46,6 +47,7 @@ def hook(lazy=False, strict=False): app.options._running_from_vcs = True app.run_checks(filepaths) + update_paths(app.file_checker_manager, tempdir) app.report_errors() if strict: return app.result_count @@ -204,6 +206,16 @@ def update_excludes(exclude_list, temporary_directory_path): ] +def update_paths(checker_manager, temp_prefix): + temp_prefix_length = len(temp_prefix) + for checker in checker_manager.checkers: + filename = checker.display_name + if filename.startswith(temp_prefix): + checker.display_name = os.path.relpath( + filename[temp_prefix_length:] + ) + + _HOOK_TEMPLATE = """#!{executable} import os import sys