Giter VIP home page Giter VIP logo

captainhook's People

Contributors

alexcouper avatar browniebroke avatar cleder avatar friz-zy avatar jambonrose avatar koddsson avatar mknecht avatar nanorepublica avatar oddbloke avatar ulope avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

captainhook's Issues

License?

As #84 was asking: Any chance you can add an open source license?

isort checker ignores isort config

isort looks for its config files in the parent directories of the files being checked (rather than the directory in which the isort process is running). This means that the isort checkers doesn't obey a project's .isort.cfg files because it doesn't find it in the temporary directory structure we copy to.

I propose defining an EXTRA_FILES attribute on checker modules, which will contain the names of files which should be copied across to the temporary directory (if they exist in the repo). @alexcouper, what do you reckon?

(I've opened PyCQA/isort#166 to work out what the expected isort behaviour might be)

git commit -p pain

I performed a rather complex and tedious partial commit, once I had finished splitting and editing the chunks I got commit rejected.

I wonder if there's a way of saving the partial layout.

Or alternatively detecting that it's partial and giving an option to go for it anyway.

Drop Python 3.2 Support

The TravisCI config file specifies testing environments for Python 2.7 and 3.4, but the tox config runs against 2.7, 3.2, and 3.4.

When tox is run, the Python 3.2 environment fails because behave no longer supports Python 3.2.

I am under the impression that captainhook no longer supports Python 3.2, and that tox should no longer be checking Python 3.2.

Note that tox is not actually in the requirements.txt or test_requirements.txt files, and that I am not actually sure tox is the recommended way to test captainhook.

Some way of running the checks on everything

So that I can be sure that my CI jobs and my pre-commit hook are checking the same thing
As a captainhook user
I want to be able to run my captainhook checks on my entire codebase.

(If I write it as a story, it feels less like slacking)

Typo in `captainhook/checkers/isort_checker.py`

On line 8, the error reads:

NO_ISORT_MSG = ("isort is required for the flake8 plugin.\n

I believe that should read "isort is required for the isort plugin."

I will have a PR for you shortly.

No such file or directory when installing

Minor issue, I tried to setup captainhook in my project, and had the following error:

> captainhook install
Installing captainhook-0.8.5
Installing pre_commit.py to /path/to/my/project/.git
cp: /path/to/my/project/.git/hooks/pre-commit: No such file or directory
chmod: /path/to/my/project/.git/hooks/pre-commit: No such file or directory
Traceback (most recent call last):
  File "/usr/local/bin/captainhook", line 150, in <module>
    install_checkers(git_location)
  File "/usr/local/bin/captainhook", line 61, in install_checkers
    os.mkdir(dest_checker_folder)
OSError: [Errno 2] No such file or directory: '/path/to/my/project/.git/hooks/checkers'

I applied the following workaround:

mkdir -p .git/hooks/checkers

And then it worked. Easy to workaround, but I think that would be nicer to have captainhook handling the creation itself, sounds reasonable?

Add a version command

It would be nice to be able to check the version installed:

a) version of captainhook installed in venv
b) version of captainhook checks installed in the git repo.

Also, when upgrading/installing captainhook - if there was a way that it could auto install at the end of the pip install that would be incredibly useful.

Running captainhook in child directory causes errors

When I install captainhook via pip, running captainhook run in a child directory causes the following error.

$ # in a child directory (child of the project root)
$ pwd
project/src
$ captainhook run
Traceback (most recent call last):
  File "project/.git/hooks/pre-commit", line 127, in <module>
    exit_code = main(commit_only=not args.all)
  File "project/.git/hooks/pre-commit", line 107, in main
    errors = mod.run(files, TEMP_FOLDER)
  File "project/.git/hooks/checkers/flake8_checker.py", line 39, in run
    py_files = filter_python_files(files)
  File "project/.git/hooks/checkers/utils.py", line 106, in filter_python_files
    elif 'python' in open(f, 'r').readline():
FileNotFoundError: [Errno 2] No such file or directory: '.gitignore'

This is likely because of the command "git ls-tree --name-only --full-tree -r HEAD" in captainhook/checkers/utils.py.

In the development version of the code (which appears to be different?) the command fails silently.

$ git ci
===============================================================================
Checking isort
===============================================================================
--- src/test.py:before  2015-08-15 09:22:34
+++ src/test.py:after   2015-08-15 09:22:35.491702
@@ -1,5 +1,5 @@
+import os
+
 import django

-import os
-
 boo()

===============================================================================
Rejecting commit
===============================================================================
$ captainhook run
$ # no output!

Doesn't work with "git commit --all"

git (apparently) doesn't stage the files for commit when --all is used, so python_files_for_commit() doesn't return any files to examine.

We could try (for example) falling back to just running it on anything that's changed.

Better, however, would be to (ab)use the commit-msg hook instead of the pre-commit hook; the files are properly staged at that point.

(Thanks to jast in #git on Freenode for that advice)

Flake8 config file is ignored

Hi,

Using captainhook 0.8.6.

I like to keep my flake8 settings in ~/.config/flake8. It works fine if I run flake8 standalone, but when captainhook invokes it, my flake8 config file seems to be disregarded.

Arbitrary grep checker

Sometimes there are project-specific things that shouldn't be left lying around (the example at Onetouchteam is the @wip tag on our customer tests).

It would be good to be able to configure (multiple) grep commands for captainhook to run.

Bonus points if there's a way of specifying the files it should apply to (in the above example, we only need to check files matching customer_tests/*.feature).

Fix output of captainhook

if the script fails to install (due to other pre-commit hook) it should fail at that point, before installing checkers

Errors when unstashing stop commit from happening

I'm hitting problems when I edit a hunk during an add -p; the stash that captainhook stores will fail to apply on pop (because it refers to a tree which won't exist after the commit happens).

This stops the commit from happening and it screws up my carefully crafted commit (I just spent a minute using very salty language; appropriate for captainhook) by causing a merge conflict.

I think we should output the stash pop error, but still commit if that's the only problem we have.

Improve Documentation

The integration with Travis CI is not mentioned in the docs, nor is there a link to PyPI. What's more, there is no mention of the new frosted checker.

Question for you Alex: Would you like a license on this? I'm partial to 2-clause BSD license.

ubuntu 14.10 python3.4

pre-commit is autodecting python with /usr/bin/env python and returns python2.7

i hardcoded #!/usr/bin/python3 in pre-commit file

run captainhook run shows nothing. no errors. with python2.7 it shows errors about import errors

looks like it does not work with python3.4

pep8radius checker

Would like to contribute a pep8radius checker.

It's just so much more pragmatic to not have to fix the entire 1000 flake8 errors in that legacy file — but still ensure you cleaned up the piece of code you worked on.

PR coming.

Python files without extension (e.g. scripts) aren't checked

We have a couple of flake8 errors in the captainhook script which we haven't noticed because we only look at files matching "*.py".

file works out that it's Python, so there should be something relatively easy we can do:

$ file scripts/captainhook
scripts/captainhook: Python script, ASCII text executable

Contributing Documentation

There is currently no section in the Read Me about how to contribute to the project. Most noticeably, there is nothing about how to properly test the project to ensure that pull-requests aren't introducing problems.

As far as I can tell, nosetests and behave are meant to be used.

The tests work just fine (13 tests pass on Python 3.4). The feature checks do not (on my machine):

$ behave
0 features passed, 5 failed, 0 skipped
0 scenarios passed, 5 failed, 0 skipped
5 steps passed, 5 failed, 29 skipped, 0 undefined
Took 0m0.292s

I am not familiar with behave and perhaps the error is with my environment. Without any documentation to inform me what my development environment should be, it's hard to tell.

isort for irrelivant files on commit not python file

issue of captainhook/captainhook/checkers/isort_checker.py

When i commit not python file for instance "settings.cfg" the plugin executes "isort -df --quiet" the check all my project.

The behavior should be just commit without running the isort

flake8 not reporting errors

The redirection of stdout and stderr in the flake8 checker is not working as expected.

with change_folder(temp_folder):
        flake8_style = get_style_guide(config_file=DEFAULT_CONFIG)
        out, err = StringIO(), StringIO()
        with redirected(out, err):
            flake8_style.check_files(py_files)

Without the redirection, I see that flake8 is correctly detecting errors in files.
With the redirection it appears that nothing is actually written to the StringIO objects.

Requires some investigation.

isort check fails for valid files with isort >=4.1.0

isort considers the file valid, but the check fails because no output is expected — but isort now always displays a logo in the command-line.

The changelog entry:

Added the isort logo to the command line interface

Example run of captainhook without errors, but still rejecting the commit:

$ captainhook run
===============================================================================
Checking isort
===============================================================================
/#######################################################################\

     `sMMy`
     .yyyy-                                                      `
    ##soos##                                                    ./o.
          `     ``..-..`         ``...`.``         `   ```` ``-ssso```
     .s:-y-   .+osssssso/.     ./ossss+:so+:`    :+o-`/osso:+sssssssso/
     .s::y-   osss+.``.``     -ssss+-.`-ossso`   ssssso/::..::+ssss:::.
     .s::y-   /ssss+//:-.`   `ssss+     `ssss+   sssso`       :ssss`
     .s::y-   `-/+oossssso/  `ssss/      sssso   ssss/        :ssss`
     .y-/y-       ````:ssss`  ossso.    :ssss:   ssss/        :ssss.
     `/so:`    `-//::/osss+   `+ssss+-/ossso:    /sso-        `osssso/.
       \/      `-/oooo++/-      .:/++:/++/-`      ..           `://++/.


         isort your Python imports for you so you don't have to

                            VERSION 4.1.2

\########################################################################/

===============================================================================
Rejecting commit
===============================================================================

Two solutions:

  • Add -q when calling isort. Requires isort >=4.1.1, as the quiet option was introduced to remove the logo again. ^^
  • Require isort <4.1

I'd favor the first, tested it locally, and would open a PR, if needed.

Make it easy to write your own on the fly.

We want to be able to just add a file to the checkers module and be on our way.

This will involve:

  • choosing a standard way of running a checker (run()?) inside the module.
  • getting all modules of the checker package and running any that (aren't set to off in tox.ini) and have a run method.

Weird error on one project...

git commit -a
Traceback (most recent call last):
  File ".git/hooks/pre-commit", line 127, in <module>
    exit_code = main(commit_only=not args.all)
  File ".git/hooks/pre-commit", line 96, in main
    for name, mod in checks():
  File ".git/hooks/pre-commit", line 49, in checks
    mod = importlib.import_module("checkers.{0}".format(name))
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/alex/Work/gvs/coredata1.4/.git/hooks/checkers/flake8.py", line 4, in <module>
ImportError: cannot import name python_files_for_commit

Check files changed by commits in a rebase

As rebasing can modify files without a pre-commit hook being called, having the same checks run post-rebase could be useful.

The post-rewrite hook would probably do the trick, by iterating through the new commits to build up a list of files to check.

It would have to be informational only, though I can't really imagine something that stops a rebase being particularly user-friendly anyway...

Support for isort

isort is a cool thing which I've been wanting to include in my git pre-commit hook for a while.

Probably worth waiting until PyCQA/isort#156 has been resolved (see the notes there for what would be involved otherwise).

`flake8` checkers overrides tox.ini defaults

We (unsurprisingly) don't care about our migrations passing flake8.

Unfortunately, in passing a list of files to flake8, the checker overrides our tox.ini settings (as it's running e.g. flake8 ott/team/migrations/0014_auto__add_field_teammemberabsence_working_days_absent.py ott/team/models.py).

Might it be worth hooking directly in to the flake8 git hook?

Fix behavioral tests

I seem to have some trouble running the behavioral tests

λ bubblegum captainhook → λ git master* → lettuce features

Feature: pdb checker                                                                 # features/pdb_checker.feature:1

  Background:
Died with The step r"Given that I am in a git repository" is not defined
Traceback (most recent call last):
  File "/home/koddsson/.virtualenvs/captainhook/local/lib/python2.7/site-packages/lettuce/__init__.py", line 164, in run
    failfast=self.failfast))
  File "/home/koddsson/.virtualenvs/captainhook/local/lib/python2.7/site-packages/lettuce/core.py", line 1186, in run
    scenarios_ran.extend(scenario.run(ignore_case, failfast=failfast))
  File "/home/koddsson/.virtualenvs/captainhook/local/lib/python2.7/site-packages/lettuce/core.py", line 726, in run
    results.append(run_scenario(self, run_callbacks=True))
  File "/home/koddsson/.virtualenvs/captainhook/local/lib/python2.7/site-packages/lettuce/core.py", line 697, in run_scenario
    self.background.run(ignore_case)
  File "/home/koddsson/.virtualenvs/captainhook/local/lib/python2.7/site-packages/lettuce/core.py", line 858, in run
    matched, step_definition = step.pre_run(ignore_case)
  File "/home/koddsson/.virtualenvs/captainhook/local/lib/python2.7/site-packages/lettuce/core.py", line 355, in pre_run
    raise NoDefinitionFound(self)
NoDefinitionFound: The step r"Given that I am in a git repository" is not defined

0 feature (0 passed)
0 scenario (0 passed)
0 step (0 passed)
λ bubblegum captainhook → λ git master* → 

Determining if there are changes to stash fails if there is unicode in the stashable diff

This looks like it's actually a problem with bash though:

Traceback (most recent call last):
  File ".git/hooks/pre-commit", line 122, in <module>
    exit_code = main(stash=not args.nostash)
  File ".git/hooks/pre-commit", line 97, in main
    with gitstash(stash):
  File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File ".git/hooks/pre-commit", line 75, in gitstash
    if stash and not changes_to_stash():
  File ".git/hooks/pre-commit", line 64, in changes_to_stash
    return bool(bash('git diff'))
  File "/home/daniel/dev/ott/.git/hooks/checkers/utils.py", line 34, in __nonzero__
    return self.__bool__()
  File "/home/daniel/dev/ott/.git/hooks/checkers/utils.py", line 37, in __bool__
    return bool(str(self))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 2487: ordinal not in range(128)

Behave tests

Should error if a bash() step fails.

Eg in #47 the issue was that there was no hooks folder, but this was swallowed up by the behave tests.

Related, we should force create the hooks folder if it doesn't exist.

To replicate this issue add this to .gitconfig:

[init]
        templatedir = ~/.git_template_dir

Checkers aren't cleared out of hooks directory on install

To hook in to the flake8 Python code, I obviously need to import from flake8 which we shadow. On renaming the check, the old files were left hanging around.

We should probably be able to clear out that entire directory every time we reinstall the hook...

Check files in a merge

I've just run git merge --no-ff <branch> without the pre-commit hook being triggered.

It would probably be helpful to run the checkers in the post-merge hook to inform users if they've just merged code that won't pass their checks.

Traceback without a tox.ini

Up until now, I've been running captainhook (successfully) without a tox.ini. After installing 0.8, I get this:

Traceback (most recent call last):
  File ".git/hooks/pre-commit", line 119, in <module>
    exit_code = main(stash=not args.nostash)
  File ".git/hooks/pre-commit", line 97, in main
    if hook_checks.is_enabled(name, default=default):
  File "/home/daniel/dev/ott/.git/hooks/checkers/utils.py", line 68, in is_enabled
    setting = self.configuration(plugin)[0]
  File "/home/daniel/dev/ott/.git/hooks/checkers/utils.py", line 80, in configuration
    conf = self.config.get(plugin, "default;").split(';')
  File "/home/daniel/dev/ott/.git/hooks/checkers/utils.py", line 63, in config
    c.readfp(self.get_file())
  File "/home/daniel/dev/ott/.git/hooks/checkers/utils.py", line 57, in get_file
    return open(self.config_filename)
IOError: [Errno 2] No such file or directory: 'tox.ini'

I assume that this is intentional behaviour (as the code suggests that we now default to off for checks), but a nicer error message ("captainhook looks at your project's tox.ini to know what checks to run; see ... for more information." or similar) would probably be a nicer user experience.

Bug with pyflakes checker.

Traceback (most recent call last):
  File ".git/hooks/pre-commit", line 122, in <module>
    exit_code = main(commit_only=not args.all)
  File ".git/hooks/pre-commit", line 103, in main
    errors = mod.run(files)
  File "/Users/alex/Work/pretenders/ployst/.git/hooks/checkers/flake8_checker.py", line 45, in run
    flake8_style.check_files(py_files)
  File "/Users/alex/.virtualenvs/ployst/lib/python2.7/site-packages/pep8.py", line 1624, in check_files
    runner(path)
  File "/Users/alex/.virtualenvs/ployst/lib/python2.7/site-packages/flake8/engine.py", line 73, in input_file
    return fchecker.check_all(expected=expected, line_offset=line_offset)
  File "/Users/alex/.virtualenvs/ployst/lib/python2.7/site-packages/pep8.py", line 1366, in check_all
    self.check_ast()
  File "/Users/alex/.virtualenvs/ployst/lib/python2.7/site-packages/pep8.py", line 1345, in check_ast
    checker = cls(tree, self.filename)
  File "/Users/alex/.virtualenvs/ployst/lib/python2.7/site-packages/pyflakes/checker.py", line 253, in __init__
    self.handleChildren(tree)
  File "/Users/alex/.virtualenvs/ployst/lib/python2.7/site-packages/pyflakes/checker.py", line 520, in handleChildren
    self.handleNode(node, tree)
  File "/Users/alex/.virtualenvs/ployst/lib/python2.7/site-packages/pyflakes/checker.py", line 555, in handleNode
    handler(node)
  File "/Users/alex/.virtualenvs/ployst/lib/python2.7/site-packages/pyflakes/checker.py", line 702, in FUNCTIONDEF
    self.LAMBDA(node)
  File "/Users/alex/.virtualenvs/ployst/lib/python2.7/site-packages/pyflakes/checker.py", line 722, in LAMBDA
    for arg in node.args.args + node.args.kwonlyargs:
AttributeError: 'arguments' object has no attribute 'kwonlyargs'

Tox.ini

[captainhook]
pdb=on
flake8=on

python3 issues

$ git commit -a
Traceback (most recent call last):
  File ".git/hooks/pre-commit", line 200, in <module>
    main(stash=not args.nostash)
  File ".git/hooks/pre-commit", line 183, in main
    errors = func()
  File ".git/hooks/pre-commit", line 82, in python3
    return "\n".join(errors)
TypeError: sequence item 0: expected str instance, bytes found

isort does not support skip parameter

I have Docker file that starts with "from python:3.5".
The utils.filter_python_files doesn't care about such files that just have python in it's first line. The isort_checker simple assumes: this is Python file.

Should be a way to tell isort_checker to skip files.

--version failure

$ bin/captainhook --version
Traceback (most recent call last):
  File "bin/captainhook", line 140, in <module>
    print("Environment version: {}".format(captainhook.__version__))
ValueError: zero length field name in format

Allow use of setup.cfg

Enhancement request: it would be nice if we had the choice to use setup.cfg on top of tox.ini.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.