Skip to content

Commit

Permalink
feat(ruff): enable flake8-bandit (#22399)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongbo-miao authored Jan 7, 2025
1 parent a84b25b commit 100cda3
Show file tree
Hide file tree
Showing 40 changed files with 130 additions and 107 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ data-storage/hm-keydb/dump.rdb
data-storage/hm-protobuf/data
data-transformation/dbt/projects/*/dbt_packages
data-transformation/dbt/projects/*/logs
data-visualization/grafana/hm-dashboard/output
data-visualization/grafana/hm-panel-plugin/.config
# data-visualization/metabase/plugins
desktop-qt/CMakeLists.txt.user
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ data-storage/hm-keydb/modules/**/*
data-storage/hm-protobuf/data/**/*
data-transformation/dbt/projects/*/dbt_packages/**/*
data-transformation/dbt/projects/*/logs/**/*
data-visualization/grafana/hm-dashboard/output/**/*
# data-visualization/grafana/hm-panel-plugin/.config/**/*
data-visualization/metabase/plugins/**/*
desktop-qt/CMakeLists.txt.user
Expand Down
1 change: 1 addition & 0 deletions .markdownlint-cli2.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"data-storage/hm-protobuf/data",
"data-transformation/dbt/projects/*/dbt_packages",
"data-transformation/dbt/projects/*/logs",
"data-visualization/grafana/hm-dashboard/output",
"data-visualization/grafana/hm-panel-plugin/.config",
"data-visualization/metabase/plugins",
"desktop-qt/CMakeLists.txt.user",
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ data-storage/hm-keydb/modules
data-storage/hm-protobuf/data
data-transformation/dbt/projects/*/dbt_packages
data-transformation/dbt/projects/*/logs
data-visualization/grafana/hm-dashboard/output
data-visualization/grafana/hm-panel-plugin/.config
data-visualization/metabase/plugins
desktop-qt/CMakeLists.txt.user
Expand Down
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ AllCops:
- 'data-storage/hm-protobuf/data/**/*'
- 'data-transformation/dbt/projects/*/dbt_packages/**/*'
- 'data-transformation/dbt/projects/*/logs/**/*'
- 'data-visualization/grafana/hm-dashboard/output/**/*'
- 'data-visualization/grafana/hm-panel-plugin/.config/**/*'
- 'data-visualization/metabase/plugins/**/*'
- 'desktop-qt/CMakeLists.txt.user'
Expand Down
3 changes: 3 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ exclude = [
"data-storage/hm-protobuf/data",
"data-transformation/dbt/projects/*/dbt_packages",
"data-transformation/dbt/projects/*/logs",
"data-visualization/grafana/hm-dashboard/output",
"data-visualization/grafana/hm-panel-plugin/.config",
"data-visualization/metabase/plugins",
"desktop-qt/CMakeLists.txt.user",
Expand Down Expand Up @@ -188,10 +189,12 @@ select = [
"PGH", # pygrep-hooks
"PL", # Pylint
"RUF", # Ruff
"S", # flake8-bandit
"TRY", # tryceratops
"UP", # pyupgrade
]
ignore = [
"S101",
"D100",
"D101",
"D102",
Expand Down
1 change: 1 addition & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ data-storage/hm-keydb/modules
data-storage/hm-protobuf/data
data-transformation/dbt/projects/*/dbt_packages
data-transformation/dbt/projects/*/logs
data-visualization/grafana/hm-dashboard/output
data-visualization/grafana/hm-panel-plugin/.config
data-visualization/metabase/plugins
desktop-qt/CMakeLists.txt.user
Expand Down
1 change: 1 addition & 0 deletions .sqlfluffignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ data-storage/hm-keydb/modules
data-storage/hm-protobuf/data
data-transformation/dbt/projects/*/dbt_packages
data-transformation/dbt/projects/*/logs
data-visualization/grafana/hm-dashboard/output
data-visualization/grafana/hm-panel-plugin/.config
data-visualization/metabase/plugins
desktop-qt/CMakeLists.txt.user
Expand Down
1 change: 1 addition & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ data-storage/hm-keydb/modules
data-storage/hm-protobuf/data
data-transformation/dbt/projects/*/dbt_packages
data-transformation/dbt/projects/*/logs
data-visualization/grafana/hm-dashboard/output
data-visualization/grafana/hm-panel-plugin/.config
data-visualization/metabase/plugins
desktop-qt/CMakeLists.txt.user
Expand Down
1 change: 1 addition & 0 deletions .textlintignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ data-storage/hm-keydb/modules/**/*
data-storage/hm-protobuf/data/**/*
data-transformation/dbt/projects/*/dbt_packages/**/*
data-transformation/dbt/projects/*/logs/**/*
data-visualization/grafana/hm-dashboard/output/**/*
data-visualization/grafana/hm-panel-plugin/.config/**/*
data-visualization/metabase/plugins/**/*
desktop-qt/CMakeLists.txt.user
Expand Down
1 change: 1 addition & 0 deletions .yamllint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ ignore: |
data-storage/hm-protobuf/data
data-transformation/dbt/projects/*/dbt_packages
data-transformation/dbt/projects/*/logs
data-visualization/grafana/hm-dashboard/output
data-visualization/grafana/hm-panel-plugin/.config
data-visualization/metabase/plugins
desktop-qt/CMakeLists.txt.user
Expand Down
8 changes: 4 additions & 4 deletions api-python/routers/motor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
import json
import random
import secrets
import time
from typing import Annotated

Expand Down Expand Up @@ -28,9 +28,9 @@ async def generate_motor_data(
for _ in range(5):
data = {
"timestamp": time.time() * 1000,
"current": random.uniform(0, 10),
"voltage": random.uniform(0, 20),
"temperature": random.uniform(0, 50) + 25,
"current": secrets.SystemRandom().uniform(0, 10),
"voltage": secrets.SystemRandom().uniform(0, 20),
"temperature": secrets.SystemRandom().uniform(0, 50) + 25,
}
producer.poll(0)
producer.produce(
Expand Down
2 changes: 1 addition & 1 deletion computer-vision/hm-imagebind/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def initialize_database(
{"text": a, "audio_path": str(b), "image_path": str(c)}
for a, b, c in zip(TEXT_LIST, audio_paths, image_paths)
]
db = lancedb.connect("/tmp/lancedb")
db = lancedb.connect("data/lancedb")
self.table = db.create_table(
"imagebind",
schema=MultimodalSearchSchema,
Expand Down
8 changes: 4 additions & 4 deletions computer-vision/hm-supervision/detect-objects/src/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import random
import secrets
from pathlib import Path

import cv2
Expand All @@ -12,9 +12,9 @@


def generate_random_color() -> tuple[int, int, int]:
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
r = secrets.randbelow(256)
g = secrets.randbelow(256)
b = secrets.randbelow(256)
return r, g, b


Expand Down
2 changes: 1 addition & 1 deletion computer-vision/open-clip/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Pets(LanceModel):


def main():
db = lancedb.connect("/tmp/lancedb")
db = lancedb.connect("data/lancedb")

# Create or get the table
if "pets" in db:
Expand Down
2 changes: 1 addition & 1 deletion data-orchestration/hm-airflow/dags/s3_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ def rename_file(file_path: str, new_file_name: str) -> None:
file_name = download_from_s3(
bucket="hm-production-bucket",
key="hm-airflow/taxi.csv",
local_path="/tmp/",
local_path="/tmp/", # noqa: S108
)
rename_file(file_name, "taxi.csv")
12 changes: 6 additions & 6 deletions data-orchestration/hm-prefect/workflows/calculate/src/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import random
import secrets
import time

from prefect import flow, get_run_logger, task
Expand All @@ -11,31 +11,31 @@ class Model(BaseModel):

@task
def expand(n: int) -> list[int]:
time.sleep(random.uniform(0.5, 5))
time.sleep(secrets.SystemRandom().uniform(0.5, 5))
return [*range(n)]


@task
def power(a: int, b: int) -> int:
time.sleep(random.uniform(0.5, 2))
time.sleep(secrets.SystemRandom().uniform(0.5, 2))
return a**b


@task
def multiply(a: int, b: int) -> int:
time.sleep(random.uniform(0.5, 2))
time.sleep(secrets.SystemRandom().uniform(0.5, 2))
return a * b


@task
def add(a: int, b: int) -> int:
time.sleep(random.uniform(0.5, 2))
time.sleep(secrets.SystemRandom().uniform(0.5, 2))
return a + b


@task
def sum_up(nums: list[int]) -> int:
time.sleep(random.uniform(0.5, 2))
time.sleep(secrets.SystemRandom().uniform(0.5, 2))
return sum(nums)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def main():
join te on t0._time = te._time
join tf on t0._time = tf._time
order by _time asc
""",
""", # noqa: S608
)
res = conn.execute(sql_query, {"event_id": event_id})
df = pd.DataFrame(res.fetchall(), columns=res.keys())
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion data-storage/hm-duckdb/query-lance/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ def main(database_path: Path) -> None:
format="%(asctime)s - %(levelname)s - %(message)s",
)

database_path = Path("/tmp/lancedb/products")
database_path = Path("data/lancedb/products")
main(database_path)
2 changes: 1 addition & 1 deletion data-storage/hm-duckdb/query-parquet/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def main(parquet_path: Path) -> None:
query = f"""
select *
from read_parquet('{parquet_path}')
"""
""" # noqa: S608
df = conn.execute(query).pl()
logger.info(df)

Expand Down
Empty file.
2 changes: 1 addition & 1 deletion data-storage/hm-lancedb/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def perform_semantic_search(table: lancedb.table.Table, query: str) -> pl.DataFr
def main():
url = "https://raw.githubusercontent.com/Abhiram970/RickBot/refs/heads/main/Rick_and_Morty.csv"
df = pl.read_csv(url)
db = lancedb.connect("/tmp/lancedb")
db = lancedb.connect("data/lancedb")
table = create_and_populate_table(db, df)

query = "What is the meaning of life?"
Expand Down
15 changes: 8 additions & 7 deletions data-storage/hm-protobuf/src/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import random
import secrets
import struct
import time
from pathlib import Path
Expand Down Expand Up @@ -70,13 +70,14 @@ def generate_motor_data(point_number: int) -> list[motor_pb2.Motor]:
for i in range(point_number):
timestamp_ns: int = start_time_ns + (i * interval_ns)
motor = motor_pb2.Motor()
motor.id = random.choice(motors)
system_random = secrets.SystemRandom()
motor.id = system_random.choice(motors)
motor.timestamp_ns = timestamp_ns
motor.temperature1 = random.uniform(10.0, 100.0)
motor.temperature2 = random.uniform(10.0, 100.0)
motor.temperature3 = random.uniform(10.0, 100.0)
motor.temperature4 = random.uniform(10.0, 100.0)
motor.temperature5 = random.uniform(10.0, 100.0)
motor.temperature1 = system_random.uniform(10.0, 100.0)
motor.temperature2 = system_random.uniform(10.0, 100.0)
motor.temperature3 = system_random.uniform(10.0, 100.0)
motor.temperature4 = system_random.uniform(10.0, 100.0)
motor.temperature5 = system_random.uniform(10.0, 100.0)
data.append(motor)
return data

Expand Down
Empty file.
3 changes: 2 additions & 1 deletion data-storage/lance/src/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from pathlib import Path

import lance
import numpy as np
Expand All @@ -25,7 +26,7 @@ def main() -> None:
vector_table = vec_to_table(vectors)

# Save to Lance dataset
uri = "/tmp/lancedb/vectors.lance"
uri = Path("data/lancedb/vectors.lance")
dataset = lance.write_dataset(vector_table, uri, mode="overwrite")
logger.info(
"Dataset saved to %s with %d vectors of dimension %d",
Expand Down
Empty file.
6 changes: 3 additions & 3 deletions data-visualization/grafana/hm-dashboard/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "1.0.0"
requires-python = "~=3.13.0"
dependencies = [
"grafanalib==0.7.1",
"requests==2.32.3",
"httpx==0.28.1",
]

[dependency-groups]
Expand All @@ -21,5 +21,5 @@ package = false
test = "pytest --verbose --verbose"
test-coverage = "pytest --cov=. --cov-report=xml"

generate-dashboard = "generate-dashboard --output=frontend.json hm.dashboard.py"
upload-dashboard = "python upload_dashboard.py"
generate-dashboard = "generate-dashboard src/hm.dashboard.py --output=output/frontend.json"
upload-dashboard = "python src/upload_dashboard.py"
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pathlib

import config
import requests
import httpx
from grafanalib._gen import DashboardEncoder
from grafanalib.core import Dashboard

Expand All @@ -20,17 +20,17 @@ def upload_to_grafana(dashboard: Dashboard) -> None:
},
cls=DashboardEncoder,
)
res = requests.post(
f"{config.GRAFANA_SERVER_URL}/api/dashboards/db",
data=dashboard_json,
headers={
"Authorization": f"Bearer {config.GRAFANA_SERVICE_ACCOUNT_TOKEN}",
"Content-Type": "application/json",
},
verify=True,
)
logger.info(res.status_code)
logger.info(res.content)
with httpx.Client() as client:
res = client.post(
f"{config.GRAFANA_SERVER_URL}/api/dashboards/db",
content=dashboard_json,
headers={
"Authorization": f"Bearer {config.GRAFANA_SERVICE_ACCOUNT_TOKEN}",
"Content-Type": "application/json",
},
)
logger.info(res.status_code)
logger.info(res.content)


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 100cda3

Please sign in to comment.