Skip to content

Commit

Permalink
Add pylint and isort, include code_checks.sh for consistency sake.
Browse files Browse the repository at this point in the history
  • Loading branch information
itsTheFae committed Jan 30, 2024
1 parent 4f3151d commit f17e5cd
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 8 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/py-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r ./requirements.dev.txt
pip install black flake8 flake8-type-checking mypy
- name: Check with black
run: |
VERNUM=${{ matrix.python-version }}
TARGETV="py${VERNUM/./}"
python -m black -t $TARGETV --diff --color --check ./
- name: Check imports with isort (black)
run: |
python -m isort --profile=black --check --diff --color ./
- name: Check with flake8
run: |
python -m flake8 ./
- name: Check with MyPy
run: |
mypy --python-version 3.8 --warn-unused-ignores ./*.py
- name: Check with Pylint
run: |
pylint --recursive=y .
52 changes: 52 additions & 0 deletions code_checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

DO_FORMAT=0
if [ "$1" == "format" ]; then
DO_FORMAT=1
fi

echo "Black on py38:"
if [ "$DO_FORMAT" == "0" ]; then
python -m black . --diff --color --check -t py38
else
python -m black . -t py38
fi
echo "----"
echo ""

echo "isort imports:"
if [ "$DO_FORMAT" == "0" ]; then
isort . --check --diff --color --profile black
else
isort . --profile black
fi
echo "----"
echo ""

echo "Flake8:"
python -m flake8
echo "----"
echo ""

echo "MyPy:"
mypy --python-version 3.8 --warn-unused-ignores ./*.py
echo "----"
echo ""

echo "pylint:"
pylint --recursive=y .
echo "----"
echo ""



#echo "Checking for i18n data missing from source base..."
#python ./tests/test_missing_i18n.py
#echo "----"

#echo "Bandit:"
#bandit -r .
#echo "----"



19 changes: 13 additions & 6 deletions musicbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ def __init__(
load_opus_lib()
try:
sys.stdout.write(f"\x1b]2;MusicBot {BOTVERSION}\x07")
except Exception:
# TODO: what does this raise and when would it raise it?
except Exception: # pylint: disable=broad-exception-caught
log.warning(
"Failed to set terminal Title via escape sequences.", exc_info=True
)
Expand Down Expand Up @@ -341,7 +342,9 @@ async def _join_startup_channels(
if not player.playlist.entries:
await self.on_player_finished_playing(player)

except Exception:
# TODO: drill down through the above code and find what exceptions
# we actually want to be handling here.
except Exception: # pylint: disable=broad-exception-caught
log.debug(
"Error joining %s/%s",
channel.guild.name,
Expand Down Expand Up @@ -1410,9 +1413,10 @@ async def on_ready(self) -> None:
mute_discord_console_log()
log.debug("Connection established, ready to go.")

# Set the handler name if we have it. I don't know why, but we do.
if self.ws._keep_alive: # pylint: disable=protected-access
self.ws._keep_alive.name = (
"Gateway Keepalive" # pylint: disable=protected-access
self.ws._keep_alive.name = ( # pylint: disable=protected-access
"Gateway Keepalive"
)
else:
log.error(
Expand Down Expand Up @@ -3274,6 +3278,8 @@ def check(reply: discord.Message) -> bool:
delete_after=30,
)
else:
# patch for loop-defined cell variable.
res_msg_ids = []
# Original code
for entry in entries:
result_message = await self.safe_send_message(
Expand All @@ -3287,12 +3293,13 @@ def check(reply: discord.Message) -> bool:
if not result_message:
continue

res_msg_ids.append(result_message.id)

def check_react(
reaction: discord.Reaction, user: discord.Member
) -> bool:
return (
user == message.author
and reaction.message.id == result_message.id
user == message.author and reaction.message.id in res_msg_ids
) # why can't these objs be compared directly?

reactions = ["\u2705", "\U0001F6AB", "\U0001F3C1"]
Expand Down
5 changes: 4 additions & 1 deletion requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ yt-dlp
colorlog
cffi --only-binary all; sys_platform == 'win32'
certifi
objgraph
pymediainfo # included for coverage, could be removed later.

objgraph
flake8
flake8-type-checking
black
isort
mypy
pylint

0 comments on commit f17e5cd

Please sign in to comment.