Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ install:
- "SET PATH=C:\\Python34;C:\\Python34\\Scripts;%PATH%"
- pip install tox
- pip install virtualenv --upgrade
- "mkdir -p C:\\Temp"
- "SET TMPDIR=C:\\Temp"

# Not a C# project
build: false
Expand All @@ -15,5 +17,4 @@ before_test:
- git config --global user.name "AppVeyor CI"
- git config --global user.email "user@example.com"

# Workaround for http://help.appveyor.com/discussions/problems/1531-having-issues-with-configured-git-bash
test_script: bash -c tox
test_script: tox
19 changes: 11 additions & 8 deletions pre_commit/languages/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,18 @@ def in_env(repo_cmd_runner, language_version):


def norm_version(version):
version = os.path.expanduser(version)
if os.name == 'nt': # pragma: no cover (windows)
if not distutils.spawn.find_executable(version):
# expanduser introduces a leading slash
version = version.strip('\\')
# The default place for python on windows is:
# C:\PythonXX\python.exe
version = r'C:\{0}\python.exe'.format(version.replace('.', ''))
return version
# Try looking up by name
if distutils.spawn.find_executable(version):
return version

# If it is in the form pythonx.x search in the default
# place on windows
if version.startswith('python'):
return r'C:\{0}\python.exe'.format(version.replace('.', ''))

# Otherwise assume it is a path
return os.path.expanduser(version)


def install_environment(
Expand Down
15 changes: 8 additions & 7 deletions pre_commit/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
try:
if not os.environ.get('TERM'): # pragma: no cover (dumb terminal)
raise OSError('Cannot determine width without TERM')
COLS = int(
subprocess.Popen(
('tput', 'cols'), stdout=subprocess.PIPE,
).communicate()[0] or
# Default in the case of no terminal
80
)
else: # pragma no cover (windows)
COLS = int(
subprocess.Popen(
('tput', 'cols'), stdout=subprocess.PIPE,
).communicate()[0] or
# Default in the case of no terminal
80
)
except OSError: # pragma: no cover (windows)
COLS = 80

Expand Down
15 changes: 13 additions & 2 deletions tests/commands/install_uninstall_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ def test_install_hooks_directory_not_present(tempdir_factory):


@xfailif_no_symlink
def test_install_hooks_dead_symlink(tempdir_factory):
def test_install_hooks_dead_symlink(
tempdir_factory,
): # pragma: no cover (non-windows)
path = git_dir(tempdir_factory)
os.symlink('/fake/baz', os.path.join(path, '.git', 'hooks', 'pre-commit'))
runner = Runner(path)
Expand Down Expand Up @@ -175,6 +177,14 @@ def test_install_idempotent(tempdir_factory):
assert NORMAL_PRE_COMMIT_RUN.match(output)


def _path_without_us():
# Choose a path which *probably* doesn't include us
return os.pathsep.join([
x for x in os.environ['PATH'].split(os.pathsep)
if x.lower() != os.path.dirname(sys.executable).lower()
])


def test_environment_not_sourced(tempdir_factory):
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
with cwd(path):
Expand All @@ -193,7 +203,7 @@ def test_environment_not_sourced(tempdir_factory):
)
ret, stdout, stderr = cmd_output(
'git', 'commit', '--allow-empty', '-m', 'foo',
env={'HOME': homedir},
env={'HOME': homedir, 'PATH': _path_without_us()},
retcode=None,
)
assert ret == 1
Expand Down Expand Up @@ -422,6 +432,7 @@ def test_installed_from_venv(tempdir_factory):
tempdir_factory,
env_base={
'HOME': os.path.expanduser('~'),
'PATH': _path_without_us(),
'TERM': os.environ.get('TERM', ''),
# Windows needs this to import `random`
'SYSTEMROOT': os.environ.get('SYSTEMROOT', ''),
Expand Down
18 changes: 18 additions & 0 deletions tests/languages/python_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import absolute_import
from __future__ import unicode_literals

import os.path

from pre_commit.languages import python


def test_norm_version_expanduser():
home = os.path.expanduser('~')
if os.name == 'nt': # pragma: no cover (nt)
path = r'~\python343'
expected_path = r'{0}\python343'.format(home)
else: # pragma: no cover (non-nt)
path = '~/.pyenv/versions/3.4.3/bin/python'
expected_path = home + '/.pyenv/versions/3.4.3/bin/python'
result = python.norm_version(path)
assert result == expected_path
20 changes: 6 additions & 14 deletions tests/repository_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ def test_additional_python_dependencies_installed(tempdir_factory, store):

@xfailif_windows_no_ruby
@pytest.mark.integration
def test_additional_ruby_dependencies_installed(tempdir_factory, store):
def test_additional_ruby_dependencies_installed(
tempdir_factory, store,
): # pragma: no cover (non-windows)
path = make_repo(tempdir_factory, 'ruby_hooks_repo')
config = make_config_from_repo(path)
config['hooks'][0]['additional_dependencies'] = ['thread_safe']
Expand All @@ -355,7 +357,9 @@ def test_additional_ruby_dependencies_installed(tempdir_factory, store):

@xfailif_windows_no_node
@pytest.mark.integration
def test_additional_node_dependencies_installed(tempdir_factory, store):
def test_additional_node_dependencies_installed(
tempdir_factory, store,
): # pragma: no cover (non-windows)
path = make_repo(tempdir_factory, 'node_hooks_repo')
config = make_config_from_repo(path)
# Careful to choose a small package that's not depped by npm
Expand Down Expand Up @@ -481,15 +485,3 @@ def test_local_repository():
with pytest.raises(NotImplementedError):
local_repo.manifest
assert len(local_repo.hooks) == 1


def test_norm_version_expanduser(): # pragma: no cover
home = os.path.expanduser('~')
if os.name == 'nt':
path = r'~\python343'
expected_path = r'C:{0}\python343\python.exe'.format(home)
else:
path = '~/.pyenv/versions/3.4.3/bin/python'
expected_path = home + '/.pyenv/versions/3.4.3/bin/python'
result = python.norm_version(path)
assert result == expected_path
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ envlist = py26,py27,py33,py34,pypy

[testenv]
deps = -rrequirements-dev.txt
passenv = HOME HOMEPATH TERM
passenv = HOME HOMEPATH PROGRAMDATA TERM
commands =
coverage erase
coverage run -m pytest {posargs:tests}
Expand Down