@cryptotaxi247 / infra-1 / commits / 09914a34

Add `ruff-check`

`ruff` complained about a few issues in our codebase. I've addressed them.

Jeremy Fleischman committed Oct 30, 2024 at 02:13 UTC 09914a3413f2b8afdc810e9eea5f08dfa398a13d
5 files changed +12 -16
build/datadog/hydra.py
+2 -4
@@ -1,12 +1,10 @@
1 #! /usr/bin/env python
2 -from checks import *
3 -import os
4 -import subprocess
2 +import checks
3 import requests
4 import json
5
6
9 -class HydraCheck(AgentCheck):
7 +class HydraCheck(checks.AgentCheck):
8 def check(self, instance):
9 r = requests.get(
10 "http://localhost:3000/status", headers={"Content-Type": "application/json"}
build/pluto/prometheus/exporters/channel-exporter.py
+1 -1
@@ -2,7 +2,7 @@
2
3 import requests
4 from dateutil.parser import parse
5 -from prometheus_client import Counter, Histogram, Gauge, start_http_server, REGISTRY
5 +from prometheus_client import Counter, Histogram, Gauge, start_http_server
6 import time
7 import sys
8 import logging
build/pluto/prometheus/exporters/hydra-queue-runner-reexporter.py
+2 -3
@@ -4,8 +4,7 @@
4 import requests
5 import json
6 from prometheus_client.core import GaugeMetricFamily, CounterMetricFamily
7 -from prometheus_client import CollectorRegistry, generate_latest, start_http_server
8 -from pprint import pprint
7 +from prometheus_client import CollectorRegistry, start_http_server
8 import time
9
10
@@ -21,7 +20,7 @@ class EvaporatingDict:
20 def preserving_read(self, key):
21 val = self._state[key]
22
24 - if type(val) is dict:
23 + if isinstance(val, dict):
24 return EvaporatingDict(val)
25 else:
26 return val
formatter/flake-module.nix
+1
@@ -14,6 +14,7 @@
14 programs.nixfmt.enable = true;
15 programs.nixfmt.package = pkgs.nixfmt-rfc-style;
16 programs.ruff-format.enable = true;
17 + programs.ruff-check.enable = true;
18
19 # TODO: fix shellcheck errors in a follow up pr
20 #programs.shellcheck.enable = true;
hydra-packet-importer/import.py
+6 -8
@@ -3,10 +3,8 @@
3 import json
4 import packet # type: ignore
5 import base64
6 -from pprint import pprint
7 -import subprocess
6 import sys
9 -from typing import Union, Dict, Any, List, Optional
7 +from typing import Dict, Any, List, Optional
8 from typing import TypedDict
9
10 DeviceKeys = List[Dict[str, Any]]
@@ -103,7 +101,7 @@ def get_remote_builder_info(manager, device_id: str) -> Optional[RemoteBuilder]:
101 events_url = "devices/{}/events?per_page=50".format(device_id)
102 debug(events_url)
103 data = manager.call_api(events_url)
106 - except:
104 + except Exception:
105 # 404 probably
106 return None
107
@@ -122,9 +120,9 @@ def get_remote_builder_info(manager, device_id: str) -> Optional[RemoteBuilder]:
120 # If we receive a LOT of spam (> 50 spams!) like that, we
121 # will return None because we never reach this message.
122 if host_key is not None:
125 - key = strip_ssh_key_comment(host_key["key"])
126 - if key is not None and metadata is not None:
127 - return {"metadata": metadata, "ssh_key": key}
123 + ssh_key = strip_ssh_key_comment(host_key["key"])
124 + if ssh_key is not None and metadata is not None:
125 + return {"metadata": metadata, "ssh_key": ssh_key}
126 return None
127 if event["type"] == "user.1001":
128 try:
@@ -132,7 +130,7 @@ def get_remote_builder_info(manager, device_id: str) -> Optional[RemoteBuilder]:
130 key for key in json.loads(event["body"]) if key["port"] == 22
131 ]
132 host_key = host_keys[0]
135 - except:
133 + except Exception:
134 pass
135 if event["type"] == "user.1002":
136 metadata = json.loads(event["body"])