Skip to content

Commit

Permalink
black jupyter support
Browse files Browse the repository at this point in the history
  • Loading branch information
chadsr committed Dec 9, 2021
1 parent 2de44fd commit 52431db
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 3 deletions.
6 changes: 3 additions & 3 deletions entrypoint.sh
Expand Up @@ -17,7 +17,7 @@ wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/instal

if [[ "$(which black)" == "" ]]; then
echo "[action-black] Installing black package..."
python -m pip install --upgrade black
python -m pip install --upgrade black[jupyter]
fi

# Run black with reviewdog
Expand Down Expand Up @@ -54,7 +54,7 @@ else
fi

# Throw error if an error occurred and fail_on_error is true
if [[ "${INPUT_FAIL_ON_ERROR}" = 'true' && ("${black_exit_val}" -ne '0' || \
if [[ "${INPUT_FAIL_ON_ERROR}" = 'true' && ("${black_exit_val}" -ne '0' ||
"${reviewdog_exit_val}" -eq "1") ]]; then
if [[ "${black_exit_val}" -eq "123" ]]; then
# NOTE: Done since syntax errors are already handled by reviewdog (see
Expand All @@ -70,4 +70,4 @@ if [[ "${INPUT_FAIL_ON_ERROR}" = 'true' && ("${black_exit_val}" -ne '0' || \
fi

echo "[action-black] Clean up reviewdog..."
rm /tmp/reviewdog
rm /tmp/reviewdog
70 changes: 70 additions & 0 deletions testdata/num_guess.ipynb
@@ -0,0 +1,70 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\"\"\"Small test script taken from https://wiki.python.org/moin/SimplePrograms\"\"\"\n",
"\n",
"import random\n",
"import sys # F401 'os' imported but unused\n",
"import os # F401 'os' imported but unused\n",
"\n",
"### E265 block comment should start with '# '\n",
"print(\"Hello from reviewdog!\")\n",
"print(\"Let's play a small number guessing game to test the flake8 github action.\")\n",
"print(\"This game is taken from https://wiki.python.org/moin/SimplePrograms.\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"guesses_made = 0\n",
"\n",
"name = input(\"Hello! What is your name?\\n\")\n",
"\n",
"number = random.randint(1, 20)\n",
"print(\"Well, {0}, I am thinking of a number between 1 and 20.\".format(name)) # E501 line too long (80 > 79 characters)\n",
"\n",
"while guesses_made < 6:\n",
"\n",
" guess = int(input(\"Take a guess: \"))\n",
"\n",
" guesses_made += 1\n",
"\n",
" if guess < number:\n",
" print(\"Your guess is too low.\")\n",
"\n",
" if guess > number:\n",
" print(\"Your guess is too high.\")\n",
"\n",
" if guess == number:\n",
" break\n",
"\n",
"if guess == number:\n",
" print(\n",
" \"Good job, {0}! You guessed my number in {1} guesses!\".format(\n",
" name, guesses_made\n",
" )\n",
" )\n",
"else:\n",
" print(\"Nope. The number I was thinking of was {0}\".format(number))\n",
"\n",
"import itertools # E402 module level import not at top of file"
]
}
],
"metadata": {
"language_info": {
"name": "python"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
67 changes: 67 additions & 0 deletions testdata/subfolder/queen_problem.ipynb
@@ -0,0 +1,67 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\"\"\"Small test script taken from https://wiki.python.org/moin/SimplePrograms\"\"\"\n",
"\n",
"import pwd # F401 'os' imported but unused\n",
"import grp # F401 'os' imported but unused\n",
"\n",
"BOARD_SIZE = 8\n",
"\n",
"### E265 block comment should start with '# '\n",
"print(\"Hello from reviewdog!\")\n",
"print(\"Let's play a small queen problem game to test the flake8 github action.\")\n",
"print(\"This game is taken from https://wiki.python.org/moin/SimplePrograms.\")\n",
"\n",
"class BailOut(Exception):\n",
" pass\n",
"\n",
"def validate(queens):\n",
" left = right = col = queens[-1] # E501 line too long (80 > 79 characters). Long description text\n",
" for r in reversed(queens[:-1]):\n",
" left, right = left-1, right+1\n",
" if r in (left, col, right):\n",
" raise BailOut\n",
"\n",
"def add_queen(queens):\n",
" for i in range(BOARD_SIZE):\n",
" test_queens = queens + [i]\n",
" try:\n",
" validate(test_queens)\n",
" if len(test_queens) == BOARD_SIZE:\n",
" return test_queens\n",
" else:\n",
" return add_queen(test_queens)\n",
" except BailOut:\n",
" pass\n",
" raise BailOut"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"queens = add_queen([])\n",
"print (queens)\n",
"print (\"\\n\".join(\". \"*q + \"Q \" + \". \"*(BOARD_SIZE-q-1) for q in queens))\n",
"\n",
"import dis # E402 module level import not at top of file"
]
}
],
"metadata": {
"language_info": {
"name": "python"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 52431db

Please sign in to comment.