56 lines
1.1 KiB
Python
56 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
from pathlib import Path
|
|
from typing import Iterable
|
|
|
|
DEFAULT_SCAN_EXCLUDES = {
|
|
".git",
|
|
".hg",
|
|
".svn",
|
|
".venv",
|
|
"venv",
|
|
"env",
|
|
"node_modules",
|
|
"__pycache__",
|
|
".pytest_cache",
|
|
".mypy_cache",
|
|
".tox",
|
|
".cache",
|
|
".idea",
|
|
".vscode",
|
|
}
|
|
|
|
COMPOSE_FILENAMES = {
|
|
"docker-compose.yml",
|
|
"docker-compose.yaml",
|
|
"compose.yml",
|
|
"compose.yaml",
|
|
}
|
|
|
|
|
|
def find_compose_files(
|
|
root: Path | str,
|
|
excludes: Iterable[str] | None = None,
|
|
) -> list[Path]:
|
|
root_path = Path(root).resolve()
|
|
|
|
exclude_set = set(DEFAULT_SCAN_EXCLUDES)
|
|
if excludes:
|
|
exclude_set.update(x.strip() for x in excludes if x and x.strip())
|
|
|
|
found: set[Path] = set()
|
|
|
|
for current_root, dirnames, filenames in os.walk(root_path, topdown=True):
|
|
dirnames[:] = sorted(
|
|
d for d in dirnames
|
|
if d not in exclude_set
|
|
)
|
|
|
|
current_path = Path(current_root)
|
|
|
|
for filename in filenames:
|
|
if filename in COMPOSE_FILENAMES:
|
|
found.add((current_path / filename).resolve())
|
|
|
|
return sorted(found)
|