Skip to content
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

Ruff everything #54

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Lint

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install dependencies
run: |
pip install ruff

- name: Run Ruff check
run: |
ruff check .
11 changes: 11 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
line-length = 110 # ideally I want this to be less than 100 but don't wanna test and change the sql stuff
target-version = "py310"
lint.select = [
"E", # pycodestyle errors
"F", # pyflakes
"I", # isort
"B", # flake8-bugbear
"C", # mccabe
"W", # pycodestyle warnings
]
lint.ignore = []
14 changes: 8 additions & 6 deletions scripts/flush_db.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#!/usr/bin/env python3

import os

import psycopg2
from psycopg2 import Error
from dotenv import load_dotenv
import os
from psycopg2 import Error


def flush_database():
# Load environment variables
load_dotenv()

DATABASE_URL = os.getenv('DATABASE_URL')

if DATABASE_URL is None:
print(f"❌ Missing DATABASE_URL environment variable")
print("❌ Missing DATABASE_URL environment variable")
return

try:
Expand Down Expand Up @@ -47,4 +49,4 @@ def flush_database():
print("🔌 Database connection closed")

if __name__ == "__main__":
flush_database()
flush_database()
114 changes: 0 additions & 114 deletions scripts/github-only-bot.py

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/modal-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ async def run_pytorch_script_on_modal():
if __name__ == "__main__":
with modal_app.run():
result = run_pytorch_script_on_modal.remote()
print(result)
print(result)
31 changes: 16 additions & 15 deletions src/discord-cluster-manager/bot.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import discord
from discord import app_commands
from discord.ext import commands
import argparse
from utils import setup_logging
from cogs.misc_cog import BotManagerCog
from datetime import datetime

import discord
from cogs.github_cog import GitHubCog
from cogs.leaderboard_cog import LeaderboardCog
from cogs.misc_cog import BotManagerCog
from cogs.modal_cog import ModalCog
from cogs.verify_run_cog import VerifyRunCog
from consts import (
init_environment,
DISCORD_TOKEN,
DISCORD_DEBUG_TOKEN,
DISCORD_CLUSTER_STAGING_ID,
DISCORD_DEBUG_CLUSTER_STAGING_ID,
POSTGRES_USER,
POSTGRES_PASSWORD,
DISCORD_DEBUG_TOKEN,
DISCORD_TOKEN,
POSTGRES_DATABASE,
POSTGRES_HOST,
POSTGRES_PASSWORD,
POSTGRES_PORT,
POSTGRES_DATABASE,
POSTGRES_USER,
init_environment,
)
from cogs.modal_cog import ModalCog
from cogs.github_cog import GitHubCog
from cogs.leaderboard_cog import LeaderboardCog
from discord import app_commands
from discord.ext import commands
from leaderboard_db import LeaderboardDB
from cogs.verify_run_cog import VerifyRunCog
from utils import setup_logging

logger = setup_logging()

Expand Down
29 changes: 16 additions & 13 deletions src/discord-cluster-manager/cogs/github_cog.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import asyncio
import os
import zipfile
from datetime import datetime, timedelta, timezone

import discord
import requests
from consts import GITHUB_REPO, GITHUB_TOKEN, GPUType
from discord import app_commands
from discord.ext import commands
from datetime import datetime, timezone, timedelta
import asyncio
import requests
import zipfile
import os
from github import Github
from utils import setup_logging, get_github_branch_name
from consts import GPUType, GITHUB_TOKEN, GITHUB_REPO
from leaderboard_eval import py_eval, cu_eval
from leaderboard_eval import cu_eval, py_eval
from utils import get_github_branch_name, setup_logging

logger = setup_logging()

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

return thread

except Exception as e:
logger.error(f"Error processing request: {str(e)}", exc_info=True)
await thread.send(f"Error processing request: {str(e)}")

finally:
return thread
if thread:
await thread.send(f"Error processing request: {str(e)}")
raise

async def trigger_github_action(
self,
Expand Down Expand Up @@ -175,7 +177,8 @@ async def check_workflow_status(self, run_id, thread):
if elapsed_time > timeout:
try:
run.cancel()
# Wait briefly to ensure cancellation is processed and Verify the run was actually cancelled
# Wait briefly to ensure cancellation is processed
# And Verify the run was actually cancelled
await asyncio.sleep(5)
run = repo.get_workflow_run(run_id)
if run.status != "completed":
Expand Down
21 changes: 11 additions & 10 deletions src/discord-cluster-manager/cogs/leaderboard_cog.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import discord
from discord import app_commands
from discord.ext import commands
import random
from datetime import datetime

from typing import TYPE_CHECKING
import discord
from consts import GitHubGPU, ModalGPU
from discord import app_commands
from discord.ext import commands
from utils import extract_score, get_user_from_id

import random


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

modal_command = modal_cog.run_modal

# Compute eval or submission score, call runner here.
score = random.random()

Expand All @@ -83,7 +79,10 @@ async def submit_modal(
})

await interaction.response.send_message(
f"Ran on Modal. Leaderboard '{leaderboard_name}'. Submission title: {script.filename}. Submission user: {interaction.user.id}. Runtime: {score} ms",
f"Ran on Modal. Leaderboard '{leaderboard_name}'.\n"
+ f"Submission title: {script.filename}.\n"
+ f"Submission user: {interaction.user.id}.\n"
+ f"Runtime: {score} ms",
ephemeral=True,
)
except ValueError:
Expand Down Expand Up @@ -270,7 +269,9 @@ async def leaderboard_create(
})

await interaction.response.send_message(
f"Leaderboard '{leaderboard_name}'. Reference code: {reference_code}. Submission deadline: {date_value}",
f"Leaderboard '{leaderboard_name}' created.\n"
+ f"Reference code: {reference_code}.\n"
+ f"Submission deadline: {date_value}",
ephemeral=True,
)
except ValueError:
Expand Down
4 changes: 2 additions & 2 deletions src/discord-cluster-manager/cogs/misc_cog.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import discord
import psycopg2
from consts import DATABASE_URL
from discord import app_commands
from discord.ext import commands
import psycopg2
from utils import setup_logging
from consts import DATABASE_URL

logger = setup_logging()

Expand Down
Loading
Loading