-
Notifications
You must be signed in to change notification settings - Fork 615
Add hooks for running linters and tests #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -42,3 +42,12 @@ Next, use `pip` to install the source code in "editable" mode. This means that P | |||
`$ pip install -e ./local/path/to/src` | |||
|
|||
You'll find that the `capa.exe` (Windows) or `capa` (Linux) executables in your path now invoke the capa binary from this directory. | |||
|
|||
### 4. Setup hooks [optional] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be a good idea to create a CONTRIBUTING file which includes this (and maybe the whole 3 section). 🤔 Although not necessarily something for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, thanks! this will hold us over before we go public.
Add the `scripts/setup-hooks.sh` script which sets the following hooks up: - The `post-commit` hook runs the linter after every `git commit`, letting you know if there are code style or rule linter offenses you need to fix. - The `pre-push` hook runs the linter and the tests and block the `git push` if they do not succeed. This way you realise if everything is alright without the need of sending a PR.
# After that append `scripts/hooks/$arg` and ensure they can be run | ||
create_hook() { | ||
if [[ ! -e .git/hooks/$1 ]]; then | ||
echo '#!/bin/sh' > .git/hooks/$1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even better: #!/usr/bin/env sh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recommend also adding set -euo pipefail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even better:
#!/usr/bin/env sh
I think that #!/usr/bin/env bash
is prefered vs #!/usr/bin/bash
, as #!/usr/bin/bash
doesn't always exist. However, #!/bin/sh
should exist.
I am anyway using some bash specific features (Bashism), so we could use bash instead
if [[ ! -e .git/hooks/$1 ]]; then | ||
echo '#!/bin/sh' > .git/hooks/$1 | ||
fi | ||
cat scripts/hooks/$1 >> .git/hooks/$1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
careful to surround variables with double quotes to support filenames with whitespace:
".git/hooks/$1"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but hook names never have whitespaces
pip install pycodestyle | ||
pytest-sugar | ||
pip install https://github.com/williballenthin/vivisect/zipball/master | ||
python setup.py develop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this makes assumptions about where the script is run.
i'd recommend that this script be thoroughly documented with some examples and leave it be, rather than making this script bulletproof.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it changes to the root git directory, so you can run it everywhere inside the git repo:
GIT_DIR=`git rev-parse --show-toplevel`
cd $GIT_DIR
} | ||
|
||
# Run style checker and print state | ||
pycodestyle --config=./ci/tox.ini ./capa/ > style-checker-output.log 2>&1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this make assumptions about where the script is being invoked from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as long as it is run from inside the git directory, it is always run from the root of the git directory
updated master branch
Add the
scripts/setup-hooks.sh
script which sets the following hooks up:post-commit
hook runs the linter after everygit commit
, letting you know if there are code style or rule linter offenses you need to fix.pre-push
hook runs the linter and the tests and block thegit push
if they do not succeed. This way you realise if everything is alright without the need of sending a PR.git commit
when the linter failsgit push
in process with uncommited changesBe careful if you are using git 2.24 as there is a bug affecting
git stash pop
: https://www.spinics.net/lists/git/msg369520.html It is fixed in the last git version.