mirror of
https://github.com/infiniteCable2/opendbc.git
synced 2026-02-18 13:03:52 +08:00
replace natsort with lil function (#3105)
* replace natsort with lil function * sort
This commit is contained in:
2
.github/workflows/update-cars-docs.yml
vendored
2
.github/workflows/update-cars-docs.yml
vendored
@@ -16,7 +16,7 @@ jobs:
|
||||
run: |
|
||||
pip install -e .
|
||||
scons -c && scons -j$(nproc)
|
||||
python -m pip install jinja2==3.1.4 natsort==8.4.0
|
||||
python -m pip install jinja2==3.1.4
|
||||
python opendbc/car/docs.py
|
||||
- uses: stefanzweifel/git-auto-commit-action@8621497c8c39c72f3e2a999a26b4ca1b5058a842
|
||||
with:
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import re
|
||||
import os
|
||||
import jinja2
|
||||
import argparse
|
||||
import unicodedata
|
||||
from typing import get_args
|
||||
|
||||
from collections import defaultdict
|
||||
import jinja2
|
||||
from enum import Enum
|
||||
from natsort import natsorted
|
||||
from collections import defaultdict
|
||||
|
||||
from opendbc.car.common.basedir import BASEDIR
|
||||
from opendbc.car import gen_empty_fingerprint
|
||||
@@ -43,6 +44,12 @@ def get_all_footnotes() -> dict[Enum, int]:
|
||||
return {fn: idx + 1 for idx, fn in enumerate(all_footnotes)}
|
||||
|
||||
|
||||
def _natural_sort_key(s):
|
||||
# NFKD normalization ensures accented characters sort with their base letter (e.g., Š sorts with S)
|
||||
normalized = unicodedata.normalize('NFKD', s)
|
||||
return [int(t) if t.isdigit() else t.lower() for t in re.split(r'(\d+)', normalized) if t]
|
||||
|
||||
|
||||
def build_sorted_car_docs_list(platforms, footnotes=None):
|
||||
collected_car_docs: list[CarDocs | ExtraCarDocs] = []
|
||||
for platform in platforms.values():
|
||||
@@ -60,7 +67,7 @@ def build_sorted_car_docs_list(platforms, footnotes=None):
|
||||
collected_car_docs.append(_car_docs)
|
||||
|
||||
# Sort cars by make and model + year
|
||||
sorted_cars = natsorted(collected_car_docs, key=lambda car: car.name.lower())
|
||||
sorted_cars = sorted(collected_car_docs, key=lambda car: _natural_sort_key(car.name))
|
||||
return sorted_cars
|
||||
|
||||
|
||||
|
||||
@@ -44,7 +44,6 @@ testing = [
|
||||
]
|
||||
docs = [
|
||||
"Jinja2",
|
||||
"natsort",
|
||||
]
|
||||
examples = [
|
||||
"inputs",
|
||||
|
||||
11
uv.lock
generated
11
uv.lock
generated
@@ -520,15 +520,6 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/73/e4/6d6f14b2a759c622f191b2d67e9075a3f56aaccb3be4bb9bb6890030d0a0/matplotlib-3.10.8-pp311-pypy311_pp73-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:1ae029229a57cd1e8fe542485f27e7ca7b23aa9e8944ddb4985d0bc444f1eca2", size = 8713867, upload-time = "2025-12-10T22:56:48.954Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "natsort"
|
||||
version = "8.4.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/e2/a9/a0c57aee75f77794adaf35322f8b6404cbd0f89ad45c87197a937764b7d0/natsort-8.4.0.tar.gz", hash = "sha256:45312c4a0e5507593da193dedd04abb1469253b601ecaf63445ad80f0a1ea581", size = 76575, upload-time = "2023-06-20T04:17:19.925Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/ef/82/7a9d0550484a62c6da82858ee9419f3dd1ccc9aa1c26a1e43da3ecd20b0d/natsort-8.4.0-py3-none-any.whl", hash = "sha256:4732914fb471f56b5cce04d7bae6f164a592c7712e1c85f9ef585e197299521c", size = 38268, upload-time = "2023-06-20T04:17:17.522Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "numpy"
|
||||
version = "2.4.2"
|
||||
@@ -582,7 +573,6 @@ dependencies = [
|
||||
[package.optional-dependencies]
|
||||
docs = [
|
||||
{ name = "jinja2" },
|
||||
{ name = "natsort" },
|
||||
]
|
||||
examples = [
|
||||
{ name = "inputs" },
|
||||
@@ -621,7 +611,6 @@ requires-dist = [
|
||||
{ name = "jinja2", marker = "extra == 'docs'" },
|
||||
{ name = "lefthook", marker = "extra == 'testing'" },
|
||||
{ name = "matplotlib", marker = "extra == 'examples'" },
|
||||
{ name = "natsort", marker = "extra == 'docs'" },
|
||||
{ name = "numpy" },
|
||||
{ name = "parameterized", marker = "extra == 'testing'", specifier = ">=0.8,<0.9" },
|
||||
{ name = "pycapnp", specifier = "==2.1.0" },
|
||||
|
||||
Reference in New Issue
Block a user