Skip to content

Commit 5e4e86c

Browse files
committed
fix: type fixes, be more strict
1 parent e9156b3 commit 5e4e86c

File tree

5 files changed

+54
-45
lines changed

5 files changed

+54
-45
lines changed

backend/nebula/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def hash_data(data: SerializableValue) -> str:
3232

3333
def create_hash() -> str:
3434
"""Create a pseudo-random hash (used as and access token)."""
35-
return hash_data([time.time(), random.random()])
35+
return hash_data([time.time(), random.random()]) # noqa: S311
3636

3737

3838
def sql_list(lst: list[Any], t: Literal["int", "str"] = "int") -> str:

backend/nebula/objects/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
def hash_password(password: str) -> str:
21-
if config.password_hashing == "legacy":
21+
if config.password_hashing == "legacy": # noqa: S105
2222
return hashlib.sha256(password.encode("ascii")).hexdigest()
2323
raise NotImplementedException("Hashing method not available")
2424

backend/nebula/redis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async def incr(cls, namespace: str, key: str) -> int:
8989
"""Increment a value in Redis"""
9090
if not cls.connected:
9191
await cls.connect()
92-
res = await cls.redis_pool.incr(f"{namespace}-{key}")
92+
res: int = await cls.redis_pool.incr(f"{namespace}-{key}")
9393
return res
9494

9595
@classmethod

backend/pyproject.toml

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@ description = "Open source broadcast automation system"
55
authors = ["Nebula Broadcast <[email protected]>"]
66
requires-python = ">=3.11,<3.13"
77
dependencies = [
8-
"aiofiles >=24.1.0",
9-
"asyncpg >=0.29.0",
10-
"email-validator >=2.1.1",
11-
"fastapi >=0.115.0",
12-
"geoip2 >=4.8.0",
13-
"granian >=1.6.0",
14-
"gunicorn >=22.0.0",
15-
"httpx >=0.27.2",
16-
"mistune >=3.0.1",
17-
"nxtools >=1.6",
18-
"pydantic >=2.9.2",
19-
"python-dotenv >=1.0.1",
20-
"redis >=5.1.0",
21-
"requests >=2.32.3",
22-
"rich >=13.8.0",
23-
"shortuuid >=1.0.12",
24-
"user-agents >=2.2.0",
25-
"uvicorn[standard] >=0.31.0"
8+
"aiofiles >=24.1.0",
9+
"asyncpg >=0.29.0",
10+
"email-validator >=2.1.1",
11+
"fastapi >=0.115.0",
12+
"geoip2 >=4.8.0",
13+
"granian >=1.6.0",
14+
"gunicorn >=22.0.0",
15+
"httpx >=0.27.2",
16+
"mistune >=3.0.1",
17+
"nxtools >=1.6",
18+
"pydantic >=2.9.2",
19+
"python-dotenv >=1.0.1",
20+
"redis >=5.1.0",
21+
"requests >=2.32.3",
22+
"rich >=13.8.0",
23+
"shortuuid >=1.0.12",
24+
"user-agents >=2.2.0",
25+
"uvicorn[standard] >=0.31.0",
2626
]
2727

2828
[dependency-groups]
2929
dev = [
30-
"asyncpg-stubs >=0.29.1",
31-
"mypy >=1.11",
32-
"pytest >=8.0",
33-
"pytest-asyncio >=0.20.3",
34-
"ruff >=0.6.8",
35-
"types-aiofiles >=23.2.0.20240311",
36-
"types-requests >=2.31.0.20240311",
30+
"asyncpg-stubs >=0.29.1",
31+
"mypy >=1.11",
32+
"pytest >=8.0",
33+
"pytest-asyncio >=0.20.3",
34+
"ruff >=0.6.8",
35+
"types-aiofiles >=23.2.0.20240311",
36+
"types-requests >=2.31.0.20240311",
3737
]
3838

3939
#
@@ -63,24 +63,23 @@ select = [
6363
"ASYNC", # flake8-async
6464
"SIM", # flake8-simplify
6565
"ISC", # flake8-implicit-str-concat
66-
# "ANN", # flake8-annotations
66+
"S", # flake8-bandit
67+
"Q", # flake8-quotes
68+
# "FBT", # flake8-boolean-trap (nope)
69+
# "ANN", # flake8-annotations (disallows Any :-( )
6770
# "N", # pep8-naming
6871
# "D", # pydocstyle
69-
# "S", # flake8-bandit
7072
]
7173

7274
ignore = [
73-
"ISC001",
74-
"B008", # do not perform function calls in argument defaults
75-
"C901", # too complex. C'mon - this is a complex project
76-
"ASYNC110", # let us sleep
75+
"S101", # asserts - slowly removing
76+
"S608", # string-based SQL query construction
77+
"S307", # eval (used somewhere)
7778
]
7879

7980
[tool.mypy]
8081
plugins = ["pydantic.mypy"]
81-
82-
#follow_imports = "silent"
83-
#strict = true
82+
# strict = true
8483
warn_redundant_casts = true
8584
warn_unused_ignores = true
8685
disallow_any_generics = true
@@ -89,10 +88,10 @@ disallow_untyped_defs = true
8988
no_implicit_reexport = true
9089
explicit_package_bases = true
9190
strict_optional = true
92-
exclude = "tests/|venv/"
91+
exclude = "tests/|.venv/"
9392

9493
[[tool.mypy.overrides]]
95-
module = ["nxtools", "user_agents", "tomllib"]
94+
module = ["nxtools", "user_agents"]
9695
ignore_errors = true
9796
follow_imports = "skip"
9897
ignore_missing_imports = true

backend/server/storage_monitor.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import asyncio
22
import contextlib
33
import os
4-
import subprocess
54
import time
65
from typing import Any
76

@@ -12,11 +11,22 @@
1211

1312

1413
async def exec_mount(cmd: str) -> bool:
15-
# TODO: use asyncio.subprocess
16-
proc = subprocess.Popen(cmd, shell=True) # noqa
17-
while proc.poll() is None:
18-
await asyncio.sleep(0.1)
19-
return not proc.returncode
14+
"""Execute a mount command asynchronously.
15+
16+
Returns:
17+
bool: True if the command executed successfully, False otherwise.
18+
"""
19+
proc = await asyncio.create_subprocess_shell(
20+
cmd,
21+
stdout=asyncio.subprocess.PIPE,
22+
stderr=asyncio.subprocess.PIPE,
23+
)
24+
stdout, stderr = await proc.communicate()
25+
if proc.returncode != 0:
26+
nebula.log.error(f"Mount failed with return code {proc.returncode}")
27+
nebula.log.error(f"stderr: {stderr.decode()}")
28+
return False
29+
return True
2030

2131

2232
# def handle_nfs_storage(storage: Storage):

0 commit comments

Comments
 (0)