mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
Fix appveyor and windows. Resolves #293
This commit is contained in:
parent
1cdbe38b5f
commit
248930f6dc
7 changed files with 60 additions and 34 deletions
|
|
@ -7,6 +7,8 @@ install:
|
||||||
- "SET PATH=C:\\Python34;C:\\Python34\\Scripts;%PATH%"
|
- "SET PATH=C:\\Python34;C:\\Python34\\Scripts;%PATH%"
|
||||||
- pip install tox
|
- pip install tox
|
||||||
- pip install virtualenv --upgrade
|
- pip install virtualenv --upgrade
|
||||||
|
- "mkdir -p C:\\Temp"
|
||||||
|
- "SET TMPDIR=C:\\Temp"
|
||||||
|
|
||||||
# Not a C# project
|
# Not a C# project
|
||||||
build: false
|
build: false
|
||||||
|
|
@ -15,5 +17,4 @@ before_test:
|
||||||
- git config --global user.name "AppVeyor CI"
|
- git config --global user.name "AppVeyor CI"
|
||||||
- git config --global user.email "user@example.com"
|
- 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: tox
|
||||||
test_script: bash -c tox
|
|
||||||
|
|
|
||||||
|
|
@ -31,15 +31,18 @@ def in_env(repo_cmd_runner, language_version):
|
||||||
|
|
||||||
|
|
||||||
def norm_version(version):
|
def norm_version(version):
|
||||||
version = os.path.expanduser(version)
|
|
||||||
if os.name == 'nt': # pragma: no cover (windows)
|
if os.name == 'nt': # pragma: no cover (windows)
|
||||||
if not distutils.spawn.find_executable(version):
|
# Try looking up by name
|
||||||
# expanduser introduces a leading slash
|
if distutils.spawn.find_executable(version):
|
||||||
version = version.strip('\\')
|
return version
|
||||||
# The default place for python on windows is:
|
|
||||||
# C:\PythonXX\python.exe
|
# If it is in the form pythonx.x search in the default
|
||||||
version = r'C:\{0}\python.exe'.format(version.replace('.', ''))
|
# place on windows
|
||||||
return version
|
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(
|
def install_environment(
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,14 @@ from pre_commit import five
|
||||||
try:
|
try:
|
||||||
if not os.environ.get('TERM'): # pragma: no cover (dumb terminal)
|
if not os.environ.get('TERM'): # pragma: no cover (dumb terminal)
|
||||||
raise OSError('Cannot determine width without TERM')
|
raise OSError('Cannot determine width without TERM')
|
||||||
COLS = int(
|
else: # pragma no cover (windows)
|
||||||
subprocess.Popen(
|
COLS = int(
|
||||||
('tput', 'cols'), stdout=subprocess.PIPE,
|
subprocess.Popen(
|
||||||
).communicate()[0] or
|
('tput', 'cols'), stdout=subprocess.PIPE,
|
||||||
# Default in the case of no terminal
|
).communicate()[0] or
|
||||||
80
|
# Default in the case of no terminal
|
||||||
)
|
80
|
||||||
|
)
|
||||||
except OSError: # pragma: no cover (windows)
|
except OSError: # pragma: no cover (windows)
|
||||||
COLS = 80
|
COLS = 80
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,9 @@ def test_install_hooks_directory_not_present(tempdir_factory):
|
||||||
|
|
||||||
|
|
||||||
@xfailif_no_symlink
|
@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)
|
path = git_dir(tempdir_factory)
|
||||||
os.symlink('/fake/baz', os.path.join(path, '.git', 'hooks', 'pre-commit'))
|
os.symlink('/fake/baz', os.path.join(path, '.git', 'hooks', 'pre-commit'))
|
||||||
runner = Runner(path)
|
runner = Runner(path)
|
||||||
|
|
@ -175,6 +177,14 @@ def test_install_idempotent(tempdir_factory):
|
||||||
assert NORMAL_PRE_COMMIT_RUN.match(output)
|
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):
|
def test_environment_not_sourced(tempdir_factory):
|
||||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||||
with cwd(path):
|
with cwd(path):
|
||||||
|
|
@ -193,7 +203,7 @@ def test_environment_not_sourced(tempdir_factory):
|
||||||
)
|
)
|
||||||
ret, stdout, stderr = cmd_output(
|
ret, stdout, stderr = cmd_output(
|
||||||
'git', 'commit', '--allow-empty', '-m', 'foo',
|
'git', 'commit', '--allow-empty', '-m', 'foo',
|
||||||
env={'HOME': homedir},
|
env={'HOME': homedir, 'PATH': _path_without_us()},
|
||||||
retcode=None,
|
retcode=None,
|
||||||
)
|
)
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
|
|
@ -422,6 +432,7 @@ def test_installed_from_venv(tempdir_factory):
|
||||||
tempdir_factory,
|
tempdir_factory,
|
||||||
env_base={
|
env_base={
|
||||||
'HOME': os.path.expanduser('~'),
|
'HOME': os.path.expanduser('~'),
|
||||||
|
'PATH': _path_without_us(),
|
||||||
'TERM': os.environ.get('TERM', ''),
|
'TERM': os.environ.get('TERM', ''),
|
||||||
# Windows needs this to import `random`
|
# Windows needs this to import `random`
|
||||||
'SYSTEMROOT': os.environ.get('SYSTEMROOT', ''),
|
'SYSTEMROOT': os.environ.get('SYSTEMROOT', ''),
|
||||||
|
|
|
||||||
18
tests/languages/python_test.py
Normal file
18
tests/languages/python_test.py
Normal file
|
|
@ -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
|
||||||
|
|
@ -342,7 +342,9 @@ def test_additional_python_dependencies_installed(tempdir_factory, store):
|
||||||
|
|
||||||
@xfailif_windows_no_ruby
|
@xfailif_windows_no_ruby
|
||||||
@pytest.mark.integration
|
@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')
|
path = make_repo(tempdir_factory, 'ruby_hooks_repo')
|
||||||
config = make_config_from_repo(path)
|
config = make_config_from_repo(path)
|
||||||
config['hooks'][0]['additional_dependencies'] = ['thread_safe']
|
config['hooks'][0]['additional_dependencies'] = ['thread_safe']
|
||||||
|
|
@ -355,7 +357,9 @@ def test_additional_ruby_dependencies_installed(tempdir_factory, store):
|
||||||
|
|
||||||
@xfailif_windows_no_node
|
@xfailif_windows_no_node
|
||||||
@pytest.mark.integration
|
@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')
|
path = make_repo(tempdir_factory, 'node_hooks_repo')
|
||||||
config = make_config_from_repo(path)
|
config = make_config_from_repo(path)
|
||||||
# Careful to choose a small package that's not depped by npm
|
# Careful to choose a small package that's not depped by npm
|
||||||
|
|
@ -481,15 +485,3 @@ def test_local_repository():
|
||||||
with pytest.raises(NotImplementedError):
|
with pytest.raises(NotImplementedError):
|
||||||
local_repo.manifest
|
local_repo.manifest
|
||||||
assert len(local_repo.hooks) == 1
|
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
tox.ini
2
tox.ini
|
|
@ -5,7 +5,7 @@ envlist = py26,py27,py33,py34,pypy
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
deps = -rrequirements-dev.txt
|
deps = -rrequirements-dev.txt
|
||||||
passenv = HOME HOMEPATH TERM
|
passenv = HOME HOMEPATH PROGRAMDATA TERM
|
||||||
commands =
|
commands =
|
||||||
coverage erase
|
coverage erase
|
||||||
coverage run -m pytest {posargs:tests}
|
coverage run -m pytest {posargs:tests}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue