Skip to content

Commit efc6472

Browse files
authored
Adding repo niceities (hearsaycorp#65)
* Adding repo niceities * Adjusting pylint config * Adjusting pylint config * Adjusting * Adjusting pre-commit * Adding pr template * Updating makefile
1 parent 68bf751 commit efc6472

9 files changed

Lines changed: 368 additions & 1 deletion

File tree

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Description
2+
3+
Jira Ticket: https://yexttest.atlassian.net/browse/[ TICKET_NUMBER ]
4+
5+
<!--Please include a summary of the changes and the related issue. Please also include relevant motivation and context. If fixing a bug, be explicit about why these changes address the issue at hand and detail the root cause if possible. If you have modified any configuration files, explain the context. List any dependencies that are required for this change. -->
6+
7+
# Screenshots/GIFS
8+
9+
<!-- If the change is a bugfix or modification of existing behavior, include before and after screenshots/gifs/videos. If it is net new functionality, include a screenshot/gif/video of the new UI. -->
10+
11+
# Checklist
12+
13+
<!-- Remove any that don't apply -->
14+
15+
- [ ] My code follows the style guidelines of this project
16+
- [ ] I have performed a self-review of my code
17+
- [ ] I have made corresponding changes to any relevant documentation
18+
- [ ] I have added tests that prove my fix is effective or that my feature works
19+
- [ ] New and existing unit tests pass locally with my changes
20+
- [ ] Any dependent changes have been merged and published in downstream modules

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ nosetests.xml
3737

3838
# Virtualenv
3939
.venv
40+
41+
# Other
42+
.pypirc
43+
.git

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Contributors
88
| `Akshay Shah <http://github.com/akshayjshah>`_
99
| `Dale Hui <http://github.com/dhui>`_
1010
| `Istvan Nemeth <http://github.com/archiezgg>`_
11+
| `Lachlan Imel <http://github.com/limelator>`_
1112
| `Robert MacCloy <http://github.com/rbm>`_
1213
| `Sam Vilain <http://github.com/samv>`_
1314
| `Wyatt Paul <http://github.com/wyguy444>`_

Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
REPO = $(shell git rev-parse --show-toplevel)
2+
POETRY = poetry
3+
4+
hooks:
5+
${REPO}/githooks/update_githooks.sh
6+
7+
install-build:
8+
${POETRY} install --only=main
9+
10+
install-dev:
11+
${POETRY} install
12+
13+
poetry:
14+
curl -sSL https://install.python-poetry.org | POETRY_VERSION=2.1.3 python3 -
15+
poetry cache clear pypi --all
16+
poetry config virtualenvs.in-project true
17+
18+
quickstart: poetry install-dev hooks
19+
20+
quickstart-build: poetry install-build hooks
21+
22+
clean:
23+
# Delete all .pyc and .pyo files.
24+
find ${REPO} \( -name "*~" -o -name "*.py[co]" -o -name ".#*" -o -name "#*#" \) -exec rm '{}' +
25+
rm -rf .pytest_cache
26+
27+
lint: clean
28+
${POETRY} run flake8 --config=${REPO}/.flake8 ${REPO}/src/richenum
29+
${POETRY} run pylint --rcfile=${REPO}/pylint.rc ${REPO}/src/richenum
30+
31+
test: clean
32+
${POETRY} run pytest
33+
34+
build:
35+
${POETRY} build

githooks/pre-commit

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env bash
2+
3+
# Pre-commit linting.
4+
#
5+
# To skip any of these checks touch any of these bypass_* files in the
6+
# project root.
7+
# bypass_flake8
8+
# bypass_tabs
9+
#
10+
# To bypass Flake8 checking for a particular line, add '# noqa' as an
11+
# inline comment.
12+
13+
REPO_ROOT=$(git rev-parse --show-toplevel)
14+
15+
function get_temp_file {
16+
export TMPDIR=/tmp # OSX compat
17+
echo `mktemp tmp.pre-commit.XXXXXXXXXX`
18+
}
19+
20+
function flake8_check {
21+
local temp_file
22+
temp_file=$1
23+
poetry run flake8 --config="${REPO_ROOT}/.flake8" "$temp_file"
24+
return $?
25+
}
26+
27+
function tab_check {
28+
local temp_file
29+
temp_file=$1
30+
if grep -q $'\t' $temp_file; then
31+
return 1
32+
else
33+
return 0
34+
fi
35+
}
36+
37+
function run_check {
38+
local run_type
39+
local display_name
40+
local file_ext
41+
local callback
42+
run_type=$1
43+
display_name=$2
44+
file_ext=$3 # the file extension to check against
45+
callback=$4 # callback should take the (temporary) file to check
46+
47+
if [ -e $REPO_ROOT/bypass_$run_type ]; then
48+
echo "Bypassed $display_name check."
49+
rm $REPO_ROOT/bypass_$run_type 2> /dev/null # don't bypass the check next time.
50+
else
51+
# Only check staged files that match the extension.
52+
# The --diff-filter option matches everything except for (D)eleted files.
53+
echo "Running $display_name checker..."
54+
local files
55+
files=`git diff --staged --name-only --diff-filter=ACMRTUXB | grep "\.${file_ext}\$"`
56+
for file in $files; do
57+
local temp_file
58+
temp_file=$(get_temp_file)
59+
git show :0:$file > $temp_file # check the staged version of the file
60+
61+
local ret
62+
$callback $temp_file
63+
ret=$?
64+
65+
rm $temp_file # clean up the temp file, the callback should never exit
66+
if [ $ret -ne 0 ]
67+
then
68+
echo "Not committing since there are ${display_name} errors in $file."
69+
exit 1
70+
fi
71+
done
72+
fi
73+
}
74+
75+
# Flake8 checks for tab indentation in Python.
76+
run_check flake8 Flake8 py flake8_check
77+
run_check tabs TabCharacter sh tab_check

githooks/update_githooks.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
# Update our githooks.
3+
4+
REPO_ROOT=$(git rev-parse --show-toplevel)
5+
src_dir="${REPO_ROOT}/githooks/"
6+
dest_dir="${REPO_ROOT}/.git/hooks"
7+
8+
cp $src_dir/* $dest_dir

0 commit comments

Comments
 (0)