Skip to content

Commit 47d621b

Browse files
authored
Ruff everything (#54)
1 parent b2cfa1a commit 47d621b

File tree

16 files changed

+153
-216
lines changed

16 files changed

+153
-216
lines changed

.github/workflows/lint.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: '3.10'
19+
20+
- name: Install dependencies
21+
run: |
22+
pip install ruff
23+
24+
- name: Run Ruff check
25+
run: |
26+
ruff check .

.ruff.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
line-length = 110 # ideally I want this to be less than 100 but don't wanna test and change the sql stuff
2+
target-version = "py310"
3+
lint.select = [
4+
"E", # pycodestyle errors
5+
"F", # pyflakes
6+
"I", # isort
7+
"B", # flake8-bugbear
8+
"C", # mccabe
9+
"W", # pycodestyle warnings
10+
]
11+
lint.ignore = []

scripts/flush_db.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
#!/usr/bin/env python3
22

3+
import os
4+
35
import psycopg2
4-
from psycopg2 import Error
56
from dotenv import load_dotenv
6-
import os
7+
from psycopg2 import Error
8+
79

810
def flush_database():
911
# Load environment variables
1012
load_dotenv()
11-
13+
1214
DATABASE_URL = os.getenv('DATABASE_URL')
13-
15+
1416
if DATABASE_URL is None:
15-
print(f"❌ Missing DATABASE_URL environment variable")
17+
print("❌ Missing DATABASE_URL environment variable")
1618
return
1719

1820
try:
@@ -47,4 +49,4 @@ def flush_database():
4749
print("🔌 Database connection closed")
4850

4951
if __name__ == "__main__":
50-
flush_database()
52+
flush_database()

scripts/github-only-bot.py

Lines changed: 0 additions & 114 deletions
This file was deleted.

scripts/modal-test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ async def run_pytorch_script_on_modal():
4444
if __name__ == "__main__":
4545
with modal_app.run():
4646
result = run_pytorch_script_on_modal.remote()
47-
print(result)
47+
print(result)

src/discord-cluster-manager/bot.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
import discord
2-
from discord import app_commands
3-
from discord.ext import commands
41
import argparse
5-
from utils import setup_logging
6-
from cogs.misc_cog import BotManagerCog
72
from datetime import datetime
3+
4+
import discord
5+
from cogs.github_cog import GitHubCog
6+
from cogs.leaderboard_cog import LeaderboardCog
7+
from cogs.misc_cog import BotManagerCog
8+
from cogs.modal_cog import ModalCog
9+
from cogs.verify_run_cog import VerifyRunCog
810
from consts import (
9-
init_environment,
10-
DISCORD_TOKEN,
11-
DISCORD_DEBUG_TOKEN,
1211
DISCORD_CLUSTER_STAGING_ID,
1312
DISCORD_DEBUG_CLUSTER_STAGING_ID,
14-
POSTGRES_USER,
15-
POSTGRES_PASSWORD,
13+
DISCORD_DEBUG_TOKEN,
14+
DISCORD_TOKEN,
15+
POSTGRES_DATABASE,
1616
POSTGRES_HOST,
17+
POSTGRES_PASSWORD,
1718
POSTGRES_PORT,
18-
POSTGRES_DATABASE,
19+
POSTGRES_USER,
20+
init_environment,
1921
)
20-
from cogs.modal_cog import ModalCog
21-
from cogs.github_cog import GitHubCog
22-
from cogs.leaderboard_cog import LeaderboardCog
22+
from discord import app_commands
23+
from discord.ext import commands
2324
from leaderboard_db import LeaderboardDB
24-
from cogs.verify_run_cog import VerifyRunCog
25+
from utils import setup_logging
2526

2627
logger = setup_logging()
2728

src/discord-cluster-manager/cogs/github_cog.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
import asyncio
2+
import os
3+
import zipfile
4+
from datetime import datetime, timedelta, timezone
5+
16
import discord
7+
import requests
8+
from consts import GITHUB_REPO, GITHUB_TOKEN, GPUType
29
from discord import app_commands
310
from discord.ext import commands
4-
from datetime import datetime, timezone, timedelta
5-
import asyncio
6-
import requests
7-
import zipfile
8-
import os
911
from github import Github
10-
from utils import setup_logging, get_github_branch_name
11-
from consts import GPUType, GITHUB_TOKEN, GITHUB_REPO
12-
from leaderboard_eval import py_eval, cu_eval
12+
from leaderboard_eval import cu_eval, py_eval
13+
from utils import get_github_branch_name, setup_logging
1314

1415
logger = setup_logging()
1516

@@ -100,12 +101,13 @@ async def run_github(
100101
"Failed to trigger GitHub Action. Please check the configuration."
101102
)
102103

104+
return thread
105+
103106
except Exception as e:
104107
logger.error(f"Error processing request: {str(e)}", exc_info=True)
105-
await thread.send(f"Error processing request: {str(e)}")
106-
107-
finally:
108-
return thread
108+
if thread:
109+
await thread.send(f"Error processing request: {str(e)}")
110+
raise
109111

110112
async def trigger_github_action(
111113
self,
@@ -175,7 +177,8 @@ async def check_workflow_status(self, run_id, thread):
175177
if elapsed_time > timeout:
176178
try:
177179
run.cancel()
178-
# Wait briefly to ensure cancellation is processed and Verify the run was actually cancelled
180+
# Wait briefly to ensure cancellation is processed
181+
# And Verify the run was actually cancelled
179182
await asyncio.sleep(5)
180183
run = repo.get_workflow_run(run_id)
181184
if run.status != "completed":

src/discord-cluster-manager/cogs/leaderboard_cog.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import discord
2-
from discord import app_commands
3-
from discord.ext import commands
1+
import random
42
from datetime import datetime
53

6-
from typing import TYPE_CHECKING
4+
import discord
75
from consts import GitHubGPU, ModalGPU
6+
from discord import app_commands
7+
from discord.ext import commands
88
from utils import extract_score, get_user_from_id
99

10-
import random
11-
1210

1311
class LeaderboardSubmitCog(app_commands.Group):
1412
def __init__(
@@ -67,8 +65,6 @@ async def submit_modal(
6765
await interaction.response.send_message("❌ Required cogs not found!")
6866
return
6967

70-
modal_command = modal_cog.run_modal
71-
7268
# Compute eval or submission score, call runner here.
7369
score = random.random()
7470

@@ -83,7 +79,10 @@ async def submit_modal(
8379
})
8480

8581
await interaction.response.send_message(
86-
f"Ran on Modal. Leaderboard '{leaderboard_name}'. Submission title: {script.filename}. Submission user: {interaction.user.id}. Runtime: {score} ms",
82+
f"Ran on Modal. Leaderboard '{leaderboard_name}'.\n"
83+
+ f"Submission title: {script.filename}.\n"
84+
+ f"Submission user: {interaction.user.id}.\n"
85+
+ f"Runtime: {score} ms",
8786
ephemeral=True,
8887
)
8988
except ValueError:
@@ -270,7 +269,9 @@ async def leaderboard_create(
270269
})
271270

272271
await interaction.response.send_message(
273-
f"Leaderboard '{leaderboard_name}'. Reference code: {reference_code}. Submission deadline: {date_value}",
272+
f"Leaderboard '{leaderboard_name}' created.\n"
273+
+ f"Reference code: {reference_code}.\n"
274+
+ f"Submission deadline: {date_value}",
274275
ephemeral=True,
275276
)
276277
except ValueError:

src/discord-cluster-manager/cogs/misc_cog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import discord
2+
import psycopg2
3+
from consts import DATABASE_URL
24
from discord import app_commands
35
from discord.ext import commands
4-
import psycopg2
56
from utils import setup_logging
6-
from consts import DATABASE_URL
77

88
logger = setup_logging()
99

0 commit comments

Comments
 (0)