Skip to content

Commit 248930f

Browse files
committed
Fix appveyor and windows. Resolves pre-commit#293
1 parent 1cdbe38 commit 248930f

File tree

7 files changed

+60
-34
lines changed

7 files changed

+60
-34
lines changed

appveyor.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ install:
77
- "SET PATH=C:\\Python34;C:\\Python34\\Scripts;%PATH%"
88
- pip install tox
99
- pip install virtualenv --upgrade
10+
- "mkdir -p C:\\Temp"
11+
- "SET TMPDIR=C:\\Temp"
1012

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

18-
# Workaround for http://help.appveyor.com/discussions/problems/1531-having-issues-with-configured-git-bash
19-
test_script: bash -c tox
20+
test_script: tox

pre_commit/languages/python.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@ def in_env(repo_cmd_runner, language_version):
3131

3232

3333
def norm_version(version):
34-
version = os.path.expanduser(version)
3534
if os.name == 'nt': # pragma: no cover (windows)
36-
if not distutils.spawn.find_executable(version):
37-
# expanduser introduces a leading slash
38-
version = version.strip('\\')
39-
# The default place for python on windows is:
40-
# C:\PythonXX\python.exe
41-
version = r'C:\{0}\python.exe'.format(version.replace('.', ''))
42-
return version
35+
# Try looking up by name
36+
if distutils.spawn.find_executable(version):
37+
return version
38+
39+
# If it is in the form pythonx.x search in the default
40+
# place on windows
41+
if version.startswith('python'):
42+
return r'C:\{0}\python.exe'.format(version.replace('.', ''))
43+
44+
# Otherwise assume it is a path
45+
return os.path.expanduser(version)
4346

4447

4548
def install_environment(

pre_commit/output.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
try:
1313
if not os.environ.get('TERM'): # pragma: no cover (dumb terminal)
1414
raise OSError('Cannot determine width without TERM')
15-
COLS = int(
16-
subprocess.Popen(
17-
('tput', 'cols'), stdout=subprocess.PIPE,
18-
).communicate()[0] or
19-
# Default in the case of no terminal
20-
80
21-
)
15+
else: # pragma no cover (windows)
16+
COLS = int(
17+
subprocess.Popen(
18+
('tput', 'cols'), stdout=subprocess.PIPE,
19+
).communicate()[0] or
20+
# Default in the case of no terminal
21+
80
22+
)
2223
except OSError: # pragma: no cover (windows)
2324
COLS = 80
2425

tests/commands/install_uninstall_test.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ def test_install_hooks_directory_not_present(tempdir_factory):
9090

9191

9292
@xfailif_no_symlink
93-
def test_install_hooks_dead_symlink(tempdir_factory):
93+
def test_install_hooks_dead_symlink(
94+
tempdir_factory,
95+
): # pragma: no cover (non-windows)
9496
path = git_dir(tempdir_factory)
9597
os.symlink('/fake/baz', os.path.join(path, '.git', 'hooks', 'pre-commit'))
9698
runner = Runner(path)
@@ -175,6 +177,14 @@ def test_install_idempotent(tempdir_factory):
175177
assert NORMAL_PRE_COMMIT_RUN.match(output)
176178

177179

180+
def _path_without_us():
181+
# Choose a path which *probably* doesn't include us
182+
return os.pathsep.join([
183+
x for x in os.environ['PATH'].split(os.pathsep)
184+
if x.lower() != os.path.dirname(sys.executable).lower()
185+
])
186+
187+
178188
def test_environment_not_sourced(tempdir_factory):
179189
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
180190
with cwd(path):
@@ -193,7 +203,7 @@ def test_environment_not_sourced(tempdir_factory):
193203
)
194204
ret, stdout, stderr = cmd_output(
195205
'git', 'commit', '--allow-empty', '-m', 'foo',
196-
env={'HOME': homedir},
206+
env={'HOME': homedir, 'PATH': _path_without_us()},
197207
retcode=None,
198208
)
199209
assert ret == 1
@@ -422,6 +432,7 @@ def test_installed_from_venv(tempdir_factory):
422432
tempdir_factory,
423433
env_base={
424434
'HOME': os.path.expanduser('~'),
435+
'PATH': _path_without_us(),
425436
'TERM': os.environ.get('TERM', ''),
426437
# Windows needs this to import `random`
427438
'SYSTEMROOT': os.environ.get('SYSTEMROOT', ''),

tests/languages/python_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from __future__ import absolute_import
2+
from __future__ import unicode_literals
3+
4+
import os.path
5+
6+
from pre_commit.languages import python
7+
8+
9+
def test_norm_version_expanduser():
10+
home = os.path.expanduser('~')
11+
if os.name == 'nt': # pragma: no cover (nt)
12+
path = r'~\python343'
13+
expected_path = r'{0}\python343'.format(home)
14+
else: # pragma: no cover (non-nt)
15+
path = '~/.pyenv/versions/3.4.3/bin/python'
16+
expected_path = home + '/.pyenv/versions/3.4.3/bin/python'
17+
result = python.norm_version(path)
18+
assert result == expected_path

tests/repository_test.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,9 @@ def test_additional_python_dependencies_installed(tempdir_factory, store):
342342

343343
@xfailif_windows_no_ruby
344344
@pytest.mark.integration
345-
def test_additional_ruby_dependencies_installed(tempdir_factory, store):
345+
def test_additional_ruby_dependencies_installed(
346+
tempdir_factory, store,
347+
): # pragma: no cover (non-windows)
346348
path = make_repo(tempdir_factory, 'ruby_hooks_repo')
347349
config = make_config_from_repo(path)
348350
config['hooks'][0]['additional_dependencies'] = ['thread_safe']
@@ -355,7 +357,9 @@ def test_additional_ruby_dependencies_installed(tempdir_factory, store):
355357

356358
@xfailif_windows_no_node
357359
@pytest.mark.integration
358-
def test_additional_node_dependencies_installed(tempdir_factory, store):
360+
def test_additional_node_dependencies_installed(
361+
tempdir_factory, store,
362+
): # pragma: no cover (non-windows)
359363
path = make_repo(tempdir_factory, 'node_hooks_repo')
360364
config = make_config_from_repo(path)
361365
# Careful to choose a small package that's not depped by npm
@@ -481,15 +485,3 @@ def test_local_repository():
481485
with pytest.raises(NotImplementedError):
482486
local_repo.manifest
483487
assert len(local_repo.hooks) == 1
484-
485-
486-
def test_norm_version_expanduser(): # pragma: no cover
487-
home = os.path.expanduser('~')
488-
if os.name == 'nt':
489-
path = r'~\python343'
490-
expected_path = r'C:{0}\python343\python.exe'.format(home)
491-
else:
492-
path = '~/.pyenv/versions/3.4.3/bin/python'
493-
expected_path = home + '/.pyenv/versions/3.4.3/bin/python'
494-
result = python.norm_version(path)
495-
assert result == expected_path

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ envlist = py26,py27,py33,py34,pypy
55

66
[testenv]
77
deps = -rrequirements-dev.txt
8-
passenv = HOME HOMEPATH TERM
8+
passenv = HOME HOMEPATH PROGRAMDATA TERM
99
commands =
1010
coverage erase
1111
coverage run -m pytest {posargs:tests}

0 commit comments

Comments
 (0)