Skip to content

Commit

Permalink
Use git ls-files rather than manually globbing for tidy
Browse files Browse the repository at this point in the history
This avoids matching build directories, ignored files, and submodules.
  • Loading branch information
tgross35 committed Feb 12, 2025
1 parent 2831be0 commit 5275b53
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions etc/update-api-list.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@
import subprocess as sp
import sys
from dataclasses import dataclass
from glob import glob, iglob
from glob import glob
from pathlib import Path
from typing import Any, Callable, TypeAlias

SELF_PATH = Path(__file__)
ETC_DIR = SELF_PATH.parent
ROOT_DIR = ETC_DIR.parent

# Loose approximation of what gets checked in to git, without needing `git ls-files`.
DIRECTORIES = [".github", "ci", "crates", "etc", "src"]

# These files do not trigger a retest.
IGNORED_SOURCES = ["src/libm_helper.rs", "src/math/support/float_traits.rs"]

Expand Down Expand Up @@ -190,30 +187,31 @@ def tidy_lists(self) -> None:
"""In each file, check annotations indicating blocks of code should be sorted or should
include all public API.
"""
for dirname in DIRECTORIES:
dir = ROOT_DIR.joinpath(dirname)
for fname in iglob("**", root_dir=dir, recursive=True):
fpath = dir.joinpath(fname)
if fpath.is_dir() or fpath == SELF_PATH:
continue

lines = fpath.read_text().splitlines()

validate_delimited_block(
fpath,
lines,
"verify-sorted-start",
"verify-sorted-end",
ensure_sorted,
)

validate_delimited_block(
fpath,
lines,
"verify-apilist-start",
"verify-apilist-end",
lambda p, n, lines: self.ensure_contains_api(p, n, lines),
)

flist = sp.check_output(["git", "ls-files"], cwd=ROOT_DIR, text=True)

for path in flist.splitlines():
fpath = ROOT_DIR.joinpath(path)
if fpath.is_dir() or fpath == SELF_PATH:
continue

lines = fpath.read_text().splitlines()

validate_delimited_block(
fpath,
lines,
"verify-sorted-start",
"verify-sorted-end",
ensure_sorted,
)

validate_delimited_block(
fpath,
lines,
"verify-apilist-start",
"verify-apilist-end",
lambda p, n, lines: self.ensure_contains_api(p, n, lines),
)

def ensure_contains_api(self, fpath: Path, line_num: int, lines: list[str]):
"""Given a list of strings, ensure that each public function we have is named
Expand Down

0 comments on commit 5275b53

Please sign in to comment.