From 2df1dc90232ad8e9985718c14025bd6e6738a52b Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Fri, 4 Dec 2015 13:35:24 -0800 Subject: [PATCH] Add python3.5, pypy3, and latest git to travis --- .travis.yml | 16 ++++++++++++++++ latest-git.sh | 7 +++++++ pre_commit/commands/install_uninstall.py | 4 ++-- pre_commit/util.py | 8 ++++++++ setup.py | 1 + tests/commands/install_uninstall_test.py | 15 +++++++++++++-- tox.ini | 2 +- 7 files changed, 48 insertions(+), 5 deletions(-) create mode 100755 latest-git.sh diff --git a/.travis.yml b/.travis.yml index 6d190892..057829d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,10 @@ env: # These should match the tox env list - TOXENV=py27 - TOXENV=py33 - TOXENV=py34 + - TOXENV=py35 - TOXENV=pypy + - TOXENV=pypy3 + - TOXENV=py27 LATEST_GIT=1 install: pip install coveralls tox script: tox # Special snowflake. Our tests depend on making real commits. @@ -13,6 +16,13 @@ before_install: - git config --global user.email "user@example.com" # Our tests inspect some of *our* git history - git fetch --unshallow + - git --version + - | + if [ "$LATEST_GIT" = "1" ]; then + ./latest-git.sh + export PATH="/tmp/git:$PATH" + fi + - git --version after_success: - coveralls sudo: false @@ -20,3 +30,9 @@ cache: directories: - $HOME/.cache/pip - $HOME/.pre-commit +addons: + apt: + sources: + - deadsnakes + packages: + - python3.5-dev diff --git a/latest-git.sh b/latest-git.sh new file mode 100755 index 00000000..c16619eb --- /dev/null +++ b/latest-git.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# This is a script used in travis-ci to have latest git +set -ex +git clone git://github.com/git/git --depth 1 /tmp/git +pushd /tmp/git +make -j 8 +popd diff --git a/pre_commit/commands/install_uninstall.py b/pre_commit/commands/install_uninstall.py index 46d2e6dc..9ab6fc57 100644 --- a/pre_commit/commands/install_uninstall.py +++ b/pre_commit/commands/install_uninstall.py @@ -9,6 +9,7 @@ import stat import sys from pre_commit.logging_handler import LoggingHandler +from pre_commit.util import mkdirp from pre_commit.util import resource_filename @@ -54,8 +55,7 @@ def install(runner, overwrite=False, hooks=False, hook_type='pre-commit'): hook_path = runner.get_hook_path(hook_type) legacy_path = hook_path + '.legacy' - if not os.path.exists(os.path.dirname(hook_path)): - os.makedirs(os.path.dirname(hook_path)) + mkdirp(os.path.dirname(hook_path)) # If we have an existing hook, move it to pre-commit.legacy if ( diff --git a/pre_commit/util.py b/pre_commit/util.py index fd2d0d13..6fae7729 100644 --- a/pre_commit/util.py +++ b/pre_commit/util.py @@ -26,6 +26,14 @@ def cwd(path): os.chdir(original_cwd) +def mkdirp(path): + try: + os.makedirs(path) + except OSError: + if not os.path.exists(path): + raise + + def memoize_by_cwd(func): """Memoize a function call based on os.getcwd().""" @functools.wraps(func) diff --git a/setup.py b/setup.py index 02415185..d58d8f61 100644 --- a/setup.py +++ b/setup.py @@ -23,6 +23,7 @@ setup( 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', ], diff --git a/tests/commands/install_uninstall_test.py b/tests/commands/install_uninstall_test.py index 84c4606a..96d49396 100644 --- a/tests/commands/install_uninstall_test.py +++ b/tests/commands/install_uninstall_test.py @@ -21,6 +21,7 @@ from pre_commit.commands.install_uninstall import uninstall from pre_commit.runner import Runner from pre_commit.util import cmd_output from pre_commit.util import cwd +from pre_commit.util import mkdirp from pre_commit.util import resource_filename from testing.fixtures import git_dir from testing.fixtures import make_consuming_repo @@ -83,7 +84,9 @@ def test_install_pre_commit(tempdir_factory): def test_install_hooks_directory_not_present(tempdir_factory): path = git_dir(tempdir_factory) # Simulate some git clients which don't make .git/hooks #234 - shutil.rmtree(os.path.join(path, '.git', 'hooks')) + hooks = os.path.join(path, '.git', 'hooks') + if os.path.exists(hooks): # pragma: no cover (latest git) + shutil.rmtree(hooks) runner = Runner(path) install(runner) assert os.path.exists(runner.pre_commit_path) @@ -94,8 +97,9 @@ 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) + mkdirp(os.path.dirname(runner.pre_commit_path)) + os.symlink('/fake/baz', os.path.join(path, '.git', 'hooks', 'pre-commit')) install(runner) assert os.path.exists(runner.pre_commit_path) @@ -249,6 +253,7 @@ def test_install_existing_hooks_no_overwrite(tempdir_factory): runner = Runner(path) # Write out an "old" hook + mkdirp(os.path.dirname(runner.pre_commit_path)) with io.open(runner.pre_commit_path, 'w') as hook_file: hook_file.write('#!/usr/bin/env bash\necho "legacy hook"\n') make_executable(runner.pre_commit_path) @@ -274,6 +279,7 @@ def test_install_existing_hook_no_overwrite_idempotent(tempdir_factory): runner = Runner(path) # Write out an "old" hook + mkdirp(os.path.dirname(runner.pre_commit_path)) with io.open(runner.pre_commit_path, 'w') as hook_file: hook_file.write('#!/usr/bin/env bash\necho "legacy hook"\n') make_executable(runner.pre_commit_path) @@ -302,6 +308,7 @@ def test_failing_existing_hook_returns_1(tempdir_factory): runner = Runner(path) # Write out a failing "old" hook + mkdirp(os.path.dirname(runner.pre_commit_path)) with io.open(runner.pre_commit_path, 'w') as hook_file: hook_file.write('#!/usr/bin/env bash\necho "fail!"\nexit 1\n') make_executable(runner.pre_commit_path) @@ -330,6 +337,7 @@ def test_install_overwrite(tempdir_factory): runner = Runner(path) # Write out the "old" hook + mkdirp(os.path.dirname(runner.pre_commit_path)) with io.open(runner.pre_commit_path, 'w') as hook_file: hook_file.write('#!/usr/bin/env bash\necho "legacy hook"\n') make_executable(runner.pre_commit_path) @@ -347,6 +355,7 @@ def test_uninstall_restores_legacy_hooks(tempdir_factory): runner = Runner(path) # Write out an "old" hook + mkdirp(os.path.dirname(runner.pre_commit_path)) with io.open(runner.pre_commit_path, 'w') as hook_file: hook_file.write('#!/usr/bin/env bash\necho "legacy hook"\n') make_executable(runner.pre_commit_path) @@ -374,6 +383,7 @@ def test_replace_old_commit_script(tempdir_factory): IDENTIFYING_HASH, PREVIOUS_IDENTIFYING_HASHES[-1], ) + mkdirp(os.path.dirname(runner.pre_commit_path)) with io.open(runner.pre_commit_path, 'w') as pre_commit_file: pre_commit_file.write(new_contents) make_executable(runner.pre_commit_path) @@ -390,6 +400,7 @@ def test_uninstall_doesnt_remove_not_our_hooks(tempdir_factory): path = git_dir(tempdir_factory) with cwd(path): runner = Runner(path) + mkdirp(os.path.dirname(runner.pre_commit_path)) with io.open(runner.pre_commit_path, 'w') as pre_commit_file: pre_commit_file.write('#!/usr/bin/env bash\necho 1\n') make_executable(runner.pre_commit_path) diff --git a/tox.ini b/tox.ini index b5e89146..b16fb8d8 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] project = pre_commit # These should match the travis env list -envlist = py26,py27,py33,py34,pypy +envlist = py26,py27,py33,py34,py35,pypy,pypy3 [testenv] deps = -rrequirements-dev.txt