Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 782628a

Browse files
committed
Use git ls-files rather than manually globbing for tidy
This avoids matching build directories, ignored files, and submodules.
1 parent bbdaf29 commit 782628a

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

libm/etc/update-api-list.py

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@
1212
import subprocess as sp
1313
import sys
1414
from dataclasses import dataclass
15-
from glob import glob, iglob
15+
from glob import glob
1616
from pathlib import Path
1717
from typing import Any, Callable, TypeAlias
1818

1919
SELF_PATH = Path(__file__)
2020
ETC_DIR = SELF_PATH.parent
2121
ROOT_DIR = ETC_DIR.parent
2222

23-
# Loose approximation of what gets checked in to git, without needing `git ls-files`.
24-
DIRECTORIES = [".github", "ci", "crates", "etc", "src"]
25-
2623
# These files do not trigger a retest.
2724
IGNORED_SOURCES = ["src/libm_helper.rs", "src/math/support/float_traits.rs"]
2825

@@ -190,30 +187,31 @@ def tidy_lists(self) -> None:
190187
"""In each file, check annotations indicating blocks of code should be sorted or should
191188
include all public API.
192189
"""
193-
for dirname in DIRECTORIES:
194-
dir = ROOT_DIR.joinpath(dirname)
195-
for fname in iglob("**", root_dir=dir, recursive=True):
196-
fpath = dir.joinpath(fname)
197-
if fpath.is_dir() or fpath == SELF_PATH:
198-
continue
199-
200-
lines = fpath.read_text().splitlines()
201-
202-
validate_delimited_block(
203-
fpath,
204-
lines,
205-
"verify-sorted-start",
206-
"verify-sorted-end",
207-
ensure_sorted,
208-
)
209-
210-
validate_delimited_block(
211-
fpath,
212-
lines,
213-
"verify-apilist-start",
214-
"verify-apilist-end",
215-
lambda p, n, lines: self.ensure_contains_api(p, n, lines),
216-
)
190+
191+
flist = sp.check_output(["git", "ls-files"], cwd=ROOT_DIR, text=True)
192+
193+
for path in flist.splitlines():
194+
fpath = ROOT_DIR.joinpath(path)
195+
if fpath.is_dir() or fpath == SELF_PATH:
196+
continue
197+
198+
lines = fpath.read_text().splitlines()
199+
200+
validate_delimited_block(
201+
fpath,
202+
lines,
203+
"verify-sorted-start",
204+
"verify-sorted-end",
205+
ensure_sorted,
206+
)
207+
208+
validate_delimited_block(
209+
fpath,
210+
lines,
211+
"verify-apilist-start",
212+
"verify-apilist-end",
213+
lambda p, n, lines: self.ensure_contains_api(p, n, lines),
214+
)
217215

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

0 commit comments

Comments
 (0)