Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 15 additions & 9 deletions src/damply/utils/find_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@


def find_readme(directory: Path) -> Path | None:
"""Find any README file in the given directory or its 'docs' subdirectory."""

readmes = [
f for f in directory.glob('readme*', case_sensitive=False) if f.is_file()
] + [
f
for f in (directory / 'docs').glob('readme*', case_sensitive=False)
if f.is_file()
]
"""Find any README file in the given directory or its 'docs' subdirectory.

This implementation avoids relying on ``Path.glob(case_sensitive=...)`` which
may not be available in all supported Python versions. Instead, it performs a
case-insensitive check on filenames.
"""

def _collect(dir_path: Path) -> list[Path]:
if not dir_path.exists() or not dir_path.is_dir():
return []
return [
p for p in dir_path.iterdir() if p.is_file() and p.name.lower().startswith('readme')
]

readmes = _collect(directory) + _collect(directory / 'docs')

if not readmes:
return None
Expand Down
31 changes: 31 additions & 0 deletions tests/test_find_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from pathlib import Path

from damply.utils.find_readme import find_readme


def test_find_readme_in_root_case_insensitive(tmp_path: Path) -> None:
# Create a mixed-case README in root
readme = tmp_path / "ReAdMe.MD"
readme.write_text("#DESC: example\n")

found = find_readme(tmp_path)
assert found is not None
assert found.name == readme.name


def test_find_readme_in_docs_case_insensitive(tmp_path: Path) -> None:
# No root README, but one in docs with mixed case
docs = tmp_path / "docs"
docs.mkdir()
readme = docs / "readME.txt"
readme.write_text("#DESC: example\n")

found = find_readme(tmp_path)
assert found is not None
assert found.name == readme.name
assert found.parent == docs


def test_find_readme_none(tmp_path: Path) -> None:
assert find_readme(tmp_path) is None

Loading