Files
wehub-resource-sync bcbd1bdb22
Integ / changes (push) Has been skipped
Pre-commit / pre-commit (push) Failing after 1s
CLI exit codes / changes (push) Has been skipped
Test (Install) / changes (push) Has been skipped
Test (Python) / changes (push) Has been skipped
Test (TypeScript) / changes (push) Has been skipped
CLI exit codes / cli-gate (push) Has been cancelled
Test (Install) / test-install-gate (push) Has been cancelled
Integ / integ-gate (push) Has been cancelled
Test (Python) / test-python-gate (push) Has been cancelled
Test (TypeScript) / test-typescript-gate (push) Has been cancelled
Test (Install) / python-minimal (3.12) (push) Has been cancelled
Test (Install) / python-minimal (3.11) (push) Has been cancelled
Test (Install) / python-extra (agno, mirage.agents.agno) (push) Has been cancelled
Test (Install) / python-extra (chroma, mirage.resource.chroma) (push) Has been cancelled
Test (Install) / python-extra (pdf, mirage.core.filetype.pdf) (push) Has been cancelled
Integ / integ (push) Has been cancelled
Integ / integ-database (push) Has been cancelled
Integ / integ-database-ts (push) Has been cancelled
Integ / integ-data (push) Has been cancelled
Integ / integ-ssh (push) Has been cancelled
Integ / integ-ssh-ts (push) Has been cancelled
Test (Python) / audit (push) Has been cancelled
Test (TypeScript) / test (push) Has been cancelled
Test (TypeScript) / python-fs-shim (push) Has been cancelled
CLI exit codes / Python CLI (push) Has been cancelled
CLI exit codes / TypeScript CLI (push) Has been cancelled
CLI exit codes / Cross-language snapshot interop (push) Has been cancelled
Test (Python) / test (push) Has been cancelled
Test (Python) / import-isolation (deepagents, openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Python) / import-isolation (deepagents, pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Integ / integ-ts (push) Has been cancelled
Integ / integ-fuse (push) Has been cancelled
Test (Install) / python-extra (databricks, mirage.resource.databricks_volume) (push) Has been cancelled
Test (Install) / python-extra (deepagents, mirage.agents.langchain) (push) Has been cancelled
Test (Install) / python-extra (email, mirage.resource.email) (push) Has been cancelled
Test (Install) / python-extra (fuse, mirage.fuse.mount) (push) Has been cancelled
Test (Install) / python-extra (hdf5, mirage.core.filetype.hdf5) (push) Has been cancelled
Test (Install) / python-extra (hf, mirage.resource.hf_buckets) (push) Has been cancelled
Test (Install) / python-extra (lancedb, mirage.resource.lancedb) (push) Has been cancelled
Test (Install) / python-extra (langfuse, mirage.resource.langfuse) (push) Has been cancelled
Test (Install) / python-extra (mongodb, mirage.resource.mongodb) (push) Has been cancelled
Test (Install) / python-extra (nextcloud, mirage.resource.nextcloud) (push) Has been cancelled
Test (Install) / python-extra (openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Install) / python-extra (openhands, mirage.agents.openhands, 3.12) (push) Has been cancelled
Test (Install) / python-extra (parquet, mirage.core.filetype.parquet) (push) Has been cancelled
Test (Install) / python-extra (postgres, mirage.resource.postgres) (push) Has been cancelled
Test (Install) / python-extra (pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Test (Install) / python-extra (qdrant, mirage.resource.qdrant) (push) Has been cancelled
Test (Install) / python-extra (redis, mirage.resource.redis) (push) Has been cancelled
Test (Install) / python-extra (s3, mirage.resource.s3) (push) Has been cancelled
Test (Install) / python-extra (ssh, mirage.resource.ssh) (push) Has been cancelled
Test (Install) / ts-minimal (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:30:44 +08:00

89 lines
3.2 KiB
Python

from functools import partial
from mirage.cache.index import IndexCacheStore
from mirage.commands.builtin.generic.find import find as generic_find
from mirage.commands.builtin.utils.output import format_records
from mirage.commands.builtin.utils.paths import default_paths
from mirage.commands.registry import command
from mirage.commands.spec import SPECS
from mirage.core.dify.find import find as find_core
from mirage.core.dify.glob import resolve_glob
from mirage.core.dify.stat import stat as stat_core
from mirage.core.dify.stat import stat_light
from mirage.io.types import ByteSource, IOResult
from mirage.types import PathSpec
from mirage.utils.key_prefix import mount_prefix_of
def _is_bare_name(texts: tuple[str, ...]) -> bool:
return bool(texts) and not texts[0].startswith("-") and texts[0] not in (
"(", ")", "!")
def _default_name(name: str | None, texts: tuple[str, ...]) -> str | None:
if name is not None:
return name
if _is_bare_name(texts):
return texts[0]
return None
def _expr_texts(texts: tuple[str, ...]) -> tuple[str, ...]:
if _is_bare_name(texts):
return ()
return texts
async def _normalize_find_output(
stdout: ByteSource | None,
search_path: PathSpec,
) -> ByteSource | None:
if stdout is None:
return None
data = stdout if isinstance(stdout, bytes) else b""
root = mount_prefix_of(search_path.virtual,
search_path.resource_path).rstrip("/") or "/"
lines = data.decode().splitlines()
normalized = [root if line == root + "/" else line for line in lines]
return format_records(normalized)
@command("find", resource="dify", spec=SPECS["find"])
async def find(
accessor,
paths: list[PathSpec],
*texts: str,
name: str | None = None,
type: str | None = None,
maxdepth: str | None = None,
size: str | None = None,
mtime: str | None = None,
iname: str | None = None,
path: str | None = None,
mindepth: str | None = None,
index: IndexCacheStore | None = None,
cwd: PathSpec | None = None,
**_extra: object,
) -> tuple[ByteSource | None, IOResult]:
paths = default_paths(paths, cwd)
paths = await resolve_glob(accessor, paths, index)
search_path = paths[0]
stat_fn = (partial(stat_core, accessor, index=index) if mtime is not None
else partial(stat_light, accessor, index=index))
stdout, io = await generic_find(paths,
_expr_texts(texts),
find_core=partial(find_core,
accessor,
index=index),
stat=stat_fn,
name=_default_name(name, texts),
type=type,
size=size,
mtime=mtime,
maxdepth=maxdepth,
iname=iname,
path=path,
mindepth=mindepth)
return await _normalize_find_output(stdout, search_path), io