This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-release.git
The following commit(s) were added to refs/heads/main by this push:
new 9b4eabc Use the improved asynchronous path finder consistently
9b4eabc is described below
commit 9b4eabc55f12c9782692e72b4937f6af169fec88
Author: Sean B. Palmer <[email protected]>
AuthorDate: Fri May 2 09:58:31 2025 +0100
Use the improved asynchronous path finder consistently
---
atr/routes/compose.py | 2 +-
atr/routes/download.py | 4 ++--
atr/routes/draft.py | 2 +-
atr/routes/finish.py | 2 +-
atr/routes/revisions.py | 2 +-
atr/tasks/__init__.py | 2 +-
atr/tasks/checks/paths.py | 2 +-
atr/util.py | 42 ++++++++----------------------------------
8 files changed, 16 insertions(+), 42 deletions(-)
diff --git a/atr/routes/compose.py b/atr/routes/compose.py
index 5254361..4fa423b 100644
--- a/atr/routes/compose.py
+++ b/atr/routes/compose.py
@@ -41,7 +41,7 @@ async def check(
form: wtforms.Form | None = None,
) -> response.Response | str:
base_path = util.release_directory(release)
- paths = await util.paths_recursive(base_path)
+ paths = [path async for path in util.paths_recursive(base_path)]
path_templates = {}
path_substitutions = {}
path_artifacts = set()
diff --git a/atr/routes/download.py b/atr/routes/download.py
index 7d13f5a..4a49f1f 100644
--- a/atr/routes/download.py
+++ b/atr/routes/download.py
@@ -102,7 +102,7 @@ async def zip_selected(
base_dir = util.release_directory(release)
files_to_zip = []
try:
- for rel_path in await util.paths_recursive(base_dir):
+ async for rel_path in util.paths_recursive(base_dir):
full_item_path = base_dir / rel_path
if await aiofiles.os.path.isfile(full_item_path):
files_to_zip.append({"file": str(full_item_path), "name":
str(rel_path)})
@@ -158,7 +158,7 @@ async def _download_or_list(project_name: str,
version_name: str, file_path: str
async def _generate_file_url_list(release: models.Release) -> str:
base_dir = util.release_directory(release)
urls = []
- for rel_path in await util.paths_recursive(base_dir):
+ async for rel_path in util.paths_recursive(base_dir):
full_item_path = base_dir / rel_path
if await aiofiles.os.path.isfile(full_item_path):
abs_url = util.as_url(
diff --git a/atr/routes/draft.py b/atr/routes/draft.py
index f5d89e8..7f500c9 100644
--- a/atr/routes/draft.py
+++ b/atr/routes/draft.py
@@ -159,7 +159,7 @@ async def delete_file(session: routes.CommitterSession,
project_name: str, versi
# Check whether the file is an artifact
if analysis.is_artifact(path_in_new_revision):
# If so, delete all associated metadata files in the new
revision
- for p in await
util.paths_recursive(path_in_new_revision.parent):
+ async for p in
util.paths_recursive(path_in_new_revision.parent):
# Construct full path within the new revision
metadata_path_obj = new_revision_dir / p
if p.name.startswith(rel_path_to_delete.name + "."):
diff --git a/atr/routes/finish.py b/atr/routes/finish.py
index b6ad452..0b2cf0a 100644
--- a/atr/routes/finish.py
+++ b/atr/routes/finish.py
@@ -68,7 +68,7 @@ async def selected(session: routes.CommitterSession,
project_name: str, version_
unique_dirs: set[pathlib.Path] = {pathlib.Path(".")}
try:
- for path in await util.paths_recursive(current_revision_dir):
+ async for path in util.paths_recursive(current_revision_dir):
file_paths_rel.append(path)
unique_dirs.add(path.parent)
except FileNotFoundError:
diff --git a/atr/routes/revisions.py b/atr/routes/revisions.py
index ec05203..c18310b 100644
--- a/atr/routes/revisions.py
+++ b/atr/routes/revisions.py
@@ -167,7 +167,7 @@ async def _revisions_process(
) -> tuple[dict, set[pathlib.Path]]:
"""Process a single revision and calculate its diff from the previous."""
current_revision_dir = release_dir / rev_name
- current_revision_files = set(await
util.paths_recursive(current_revision_dir))
+ current_revision_files = {path async for path in
util.paths_recursive(current_revision_dir)}
parent_name = parent_map.get(rev_name)
added_files: set[pathlib.Path] = set()
diff --git a/atr/tasks/__init__.py b/atr/tasks/__init__.py
index deff7d2..43b275e 100644
--- a/atr/tasks/__init__.py
+++ b/atr/tasks/__init__.py
@@ -60,7 +60,7 @@ async def draft_checks(
# Construct path to the specific revision
# We don't have the release object here, so we can't use
util.release_directory
revision_path = util.get_unfinished_dir() / project_name / release_version
/ draft_revision
- relative_paths = await util.paths_recursive(revision_path)
+ relative_paths = [path async for path in
util.paths_recursive(revision_path)]
session_context = db.session() if (caller_data is None) else
contextlib.nullcontext(caller_data)
async with session_context as data:
diff --git a/atr/tasks/checks/paths.py b/atr/tasks/checks/paths.py
index 9f17564..5eb00e4 100644
--- a/atr/tasks/checks/paths.py
+++ b/atr/tasks/checks/paths.py
@@ -65,7 +65,7 @@ async def check(args: checks.FunctionArguments) -> None:
_LOGGER.error("Base release directory does not exist or is not a
directory: %s", base_path)
return
- relative_paths = await util.paths_recursive(base_path)
+ relative_paths = [p async for p in util.paths_recursive(base_path)]
relative_paths_set = set(str(p) for p in relative_paths)
for relative_path in relative_paths:
# Delegate processing of each path to the helper function
diff --git a/atr/util.py b/atr/util.py
index fb77c4c..05f4d3c 100644
--- a/atr/util.py
+++ b/atr/util.py
@@ -198,7 +198,7 @@ async def content_list(
raise ValueError("A revision name is required for release
candidate draft or preview content listing")
if revision_name:
base_path = base_path / revision_name
- for path in await paths_recursive(base_path):
+ async for path in paths_recursive(base_path):
stat = await aiofiles.os.stat(base_path / path)
yield FileStat(
path=str(path),
@@ -342,7 +342,7 @@ async def get_release_stats(release: models.Release) ->
tuple[int, int, str]:
count = 0
total_bytes = 0
try:
- async for rel_path in paths_recursive_async(base_dir):
+ async for rel_path in paths_recursive(base_dir):
full_path = base_dir / rel_path
if await aiofiles.os.path.isfile(full_path):
try:
@@ -398,39 +398,13 @@ async def number_of_release_files(release:
models.Release) -> int:
path = get_finished_dir() / path_project / path_version
case _:
raise ValueError(f"Unknown release phase: {release.phase}")
- return len(await paths_recursive(path))
-
-
-async def paths_recursive(base_path: pathlib.Path, sort: bool = True) ->
list[pathlib.Path]:
- """List all paths recursively in alphabetical order from a given base
path."""
- paths: list[pathlib.Path] = []
-
- async def _recursive_list(current_path: pathlib.Path, relative_path:
pathlib.Path = pathlib.Path()) -> None:
- try:
- entries = await aiofiles.os.listdir(current_path)
- for entry in entries:
- entry_path = current_path / entry
- entry_rel_path = relative_path / entry
-
- try:
- stat_info = await aiofiles.os.stat(entry_path)
- # If the entry is a directory, recurse into it
- if stat_info.st_mode & 0o040000:
- await _recursive_list(entry_path, entry_rel_path)
- else:
- paths.append(entry_rel_path)
- except (FileNotFoundError, PermissionError):
- continue
- except FileNotFoundError:
- pass
-
- await _recursive_list(base_path)
- if sort is True:
- paths.sort()
- return paths
+ count = 0
+ async for _ in paths_recursive(path):
+ count += 1
+ return count
-async def paths_recursive_async(base_path: pathlib.Path) ->
AsyncGenerator[pathlib.Path]:
+async def paths_recursive(base_path: pathlib.Path) ->
AsyncGenerator[pathlib.Path]:
"""Yield all file paths recursively within a base path, relative to the
base path."""
try:
abs_base_path = await asyncio.to_thread(base_path.resolve)
@@ -440,7 +414,7 @@ async def paths_recursive_async(base_path: pathlib.Path) ->
AsyncGenerator[pathl
if entry.is_file():
yield relative_path
elif entry.is_dir():
- async for sub_path in paths_recursive_async(entry_path):
+ async for sub_path in paths_recursive(entry_path):
yield relative_path / sub_path
except FileNotFoundError:
return
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]