From 5ace43765bdb6b8951004ac041238ed4888b1cfc Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Mon, 7 Nov 2016 08:56:58 -0800 Subject: [PATCH] Allow virtualenv creation with strange setup.cfg. Resolves #425 --- pre_commit/languages/python.py | 2 +- tests/repository_test.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pre_commit/languages/python.py b/pre_commit/languages/python.py index 7eadb8df..d785bbc9 100644 --- a/pre_commit/languages/python.py +++ b/pre_commit/languages/python.py @@ -73,7 +73,7 @@ def install_environment( venv_cmd.extend(['-p', norm_version(version)]) else: venv_cmd.extend(['-p', os.path.realpath(sys.executable)]) - repo_cmd_runner.run(venv_cmd) + repo_cmd_runner.run(venv_cmd, cwd='/') with in_env(repo_cmd_runner, version): helpers.run_setup_cmd( repo_cmd_runner, diff --git a/tests/repository_test.py b/tests/repository_test.py index 0ac2d476..7095bda1 100644 --- a/tests/repository_test.py +++ b/tests/repository_test.py @@ -81,6 +81,20 @@ def test_python_hook_args_with_spaces(tempdir_factory, store): ) +@pytest.mark.integration +def test_python_hook_weird_setup_cfg(tempdir_factory, store): + path = git_dir(tempdir_factory) + with cwd(path): + with io.open('setup.cfg', 'w') as setup_cfg: + setup_cfg.write('[install]\ninstall_scripts=/usr/sbin\n') + + _test_hook_repo( + tempdir_factory, store, 'python_hooks_repo', + 'foo', [os.devnull], + b"['" + five.to_bytes(os.devnull) + b"']\nHello World\n" + ) + + @pytest.mark.integration def test_switch_language_versions_doesnt_clobber(tempdir_factory, store): # We're using the python3 repo because it prints the python version