Skip to content

Commit

Permalink
make pylint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
kerrychu committed Jan 23, 2024
1 parent 24a561e commit 3ce1434
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
9 changes: 7 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ disable=
fixme,
cyclic-import,
import-error,
missing-module-docstring
missing-module-docstring,
consider-alternative-union-syntax,
unspecified-encoding,
consider-using-with,
inconsistent-return-statements



[REPORTS]
Expand Down Expand Up @@ -518,7 +523,7 @@ preferred-modules=

# Exceptions that will emit a warning when being caught. Defaults to
# "Exception"
overgeneral-exceptions=Exception
overgeneral-exceptions=builtins.Exception


[TYPING]
Expand Down
8 changes: 6 additions & 2 deletions gpu_jobs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import os
from dotenv import load_dotenv
from utils.subprocess_operations import get_piped_stdout, stdout_to_gpu_records, job_records_to_slack_message
from utils.subprocess_operations import (
get_piped_stdout,
stdout_to_gpu_records,
job_records_to_slack_message,
)
from hooks.slack import send_slack_message

load_dotenv()
Expand All @@ -18,7 +22,7 @@ def monitor():
gpu_jobs = get_gpu_jobs()
gpu_records = stdout_to_gpu_records(gpu_jobs)
header = f"🔉 Currently, there are {len(gpu_records)} running GPU Jobs on Bunya.\n Here are some from our lab.\n\n"
filtered_gpu_records = list(filter(lambda x: x['USER'] in GPU_USERS, gpu_records))
filtered_gpu_records = list(filter(lambda x: x["USER"] in GPU_USERS, gpu_records))
slack_message = job_records_to_slack_message(header, filtered_gpu_records)
send_slack_message(slack_message, SLACK_WEBHOOK)

Expand Down
3 changes: 2 additions & 1 deletion hooks/slack.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import requests
import json

import requests


def send_slack_message(message: str, webhook: str) -> str:
payload = {"text": message}
Expand Down
14 changes: 8 additions & 6 deletions my_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ def monitor_my_jobs():

if last_updated_job_records:
current_jobs_records = list_my_job_records()
current_job_ids = set([record["JOBID"] for record in current_jobs_records])
last_updated_job_ids = set(
[record["JOBID"] for record in last_updated_job_records]
)
current_job_ids = {record["JOBID"] for record in current_jobs_records}
last_updated_job_ids = {record["JOBID"] for record in last_updated_job_records}

if current_job_ids != last_updated_job_ids:
new_job_ids = current_job_ids.difference(last_updated_job_ids)
Expand All @@ -64,15 +62,19 @@ def monitor_my_jobs():
if record["JOBID"] in new_job_ids
]

slack_message = job_records_to_slack_message("🔉 Update: New Jobs\n", new_job_records)
slack_message = job_records_to_slack_message(
"🔉 Update: New Jobs\n", new_job_records
)
send_slack_message(message=slack_message, webhook=SLACK_WEBHOOK)
if finished_job_ids != set():
finished_job_records = [
record
for record in last_updated_job_records
if record["JOBID"] in finished_job_ids
]
slack_message = job_records_to_slack_message("🔉 Update: Complete Jobs\n", finished_job_records)
slack_message = job_records_to_slack_message(
"🔉 Update: Complete Jobs\n", finished_job_records
)
send_slack_message(message=slack_message, webhook=SLACK_WEBHOOK)
write_job_records_to_json(current_jobs_records, JOB_FILE_PATH)
else:
Expand Down
11 changes: 5 additions & 6 deletions utils/subprocess_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def get_cmd_stdout(command: str) -> str:

if result.returncode == 0:
return result.stdout
else:
print(f"Command: {command} failed with error: {result.stderr}")
print(f"Command: {command} failed with error: {result.stderr}")


def get_piped_stdout(main_command: str, piped_command: str) -> Optional[str]:
Expand All @@ -35,10 +34,10 @@ def get_piped_stdout(main_command: str, piped_command: str) -> Optional[str]:

if piped_result.returncode == 0:
return piped_result.stdout
else:
print(
f"Command: {main_command} | {piped_command} failed with error: {initial_command_result.stderr}"
)

print(
f"Command: {main_command} | {piped_command} failed with error: {initial_command_result.stderr}"
)


def strip_spaces(l: list[str]) -> list[str]:
Expand Down

0 comments on commit 3ce1434

Please sign in to comment.