Lint python

This commit is contained in:
Andras Schmelczer 2026-01-25 21:46:02 +00:00
parent a2e4c29839
commit 86690f41f1
7 changed files with 1367 additions and 17 deletions

28
.github/workflows/lint.yml vendored Normal file
View file

@ -0,0 +1,28 @@
name: Lint
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python
run: uv python install
- name: Install dependencies
run: uv sync
- name: Check linting
run: uv run ruff check .
- name: Check formatting
run: uv run ruff format --check .

View file

@ -49,3 +49,9 @@ tasks:
desc: Run production server (serves built frontend) desc: Run production server (serves built frontend)
cmds: cmds:
- uv run fastapi run server/main.py --port 8001 - uv run fastapi run server/main.py --port 8001
lint:
desc: Lint and format Python code
cmds:
- uv run ruff check --fix .
- uv run ruff format .

View file

@ -35,13 +35,16 @@ def download_with_progress(url: str, output_path: Path) -> None:
response.raise_for_status() # pyright: ignore[reportUnusedCallResult] response.raise_for_status() # pyright: ignore[reportUnusedCallResult]
total = int(response.headers.get("content-length", 0)) total = int(response.headers.get("content-length", 0))
with open(output_path, "wb") as f, tqdm( with (
total=total, open(output_path, "wb") as f,
unit="B", tqdm(
unit_scale=True, total=total,
unit_divisor=1024, unit="B",
desc="Downloading", unit_scale=True,
) as pbar: unit_divisor=1024,
desc="Downloading",
) as pbar,
):
for chunk in response.iter_bytes(chunk_size=8192): for chunk in response.iter_bytes(chunk_size=8192):
f.write(chunk) f.write(chunk)
pbar.update(len(chunk)) pbar.update(len(chunk))

View file

@ -32,16 +32,19 @@ def download_with_progress(url: str, output_path: Path) -> None:
follow_redirects=True, follow_redirects=True,
timeout=httpx.Timeout(30.0, read=None), timeout=httpx.Timeout(30.0, read=None),
) as response: ) as response:
response.raise_for_status() # pyright: ignore[reportUnusedCallResult] response.raise_for_status() # pyright: ignore[reportUnusedCallResult]
total = int(response.headers.get("content-length", 0)) total = int(response.headers.get("content-length", 0))
with open(output_path, "wb") as f, tqdm( with (
total=total, open(output_path, "wb") as f,
unit="B", tqdm(
unit_scale=True, total=total,
unit_divisor=1024, unit="B",
desc="Downloading", unit_scale=True,
) as pbar: unit_divisor=1024,
desc="Downloading",
) as pbar,
):
for chunk in response.iter_bytes(chunk_size=8192): for chunk in response.iter_bytes(chunk_size=8192):
f.write(chunk) f.write(chunk)
pbar.update(len(chunk)) pbar.update(len(chunk))

View file

@ -8,7 +8,6 @@
# Run it with: # Run it with:
# uv run generate_tfl_client.py # uv run generate_tfl_client.py
import shutil
import subprocess import subprocess
from pathlib import Path from pathlib import Path
@ -28,7 +27,14 @@ def main() -> None:
# Generate the client # Generate the client
print(f"Generating client from {OPENAPI_SPEC}") print(f"Generating client from {OPENAPI_SPEC}")
result = subprocess.run( result = subprocess.run(
["openapi-python-client", "generate", "--path", str(OPENAPI_SPEC), "--output-path", str(OUTPUT_PATH)], [
"openapi-python-client",
"generate",
"--path",
str(OPENAPI_SPEC),
"--output-path",
str(OUTPUT_PATH),
],
check=True, check=True,
) )

View file

@ -7,7 +7,10 @@ requires-python = ">=3.12"
dependencies = [ dependencies = [
"attrs>=22.2.0", "attrs>=22.2.0",
"httpx>=0.28.1", "httpx>=0.28.1",
"ipywidgets>=8.0.0",
"journey-client", "journey-client",
"jupyter>=1.0.0",
"nest-asyncio>=1.6.0",
"numpy>=1.26.0", "numpy>=1.26.0",
"pandas>=2.0.0", "pandas>=2.0.0",
"plotly>=6.5.2", "plotly>=6.5.2",
@ -20,5 +23,8 @@ dependencies = [
"h3>=3.7.0", "h3>=3.7.0",
] ]
[dependency-groups]
dev = ["ruff>=0.8.0"]
[tool.uv.sources] [tool.uv.sources]
journey-client = { path = "./tfl_journey_client" } journey-client = { path = "./tfl_journey_client" }

1298
uv.lock generated

File diff suppressed because it is too large Load diff