Skip to content

Commit 4158414

Browse files
committed
fix(readme): include src field in dfetch.yaml snippet for monorepo components
_generate_readme now emits a `src: <subpath>` line when the manifest has a non-None subpath, matching the frontend's existing behaviour in buildSnipHtml/buildEntry. The local checkout name (ext/<name>) also uses the subpath instead of the repo name, so the snippet is correct for monorepo components. Three new tests cover src-line presence, correct local name selection, and absence of src when subpath is None. https://claude.ai/code/session_01TM31h9vfpQCdpBw4TyNC8T
1 parent b516235 commit 4158414

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

dfetch_hub/catalog/writer.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,21 @@ def _generate_readme(manifest: BaseManifest, repo: str, url: str) -> str:
277277
"""Generate a minimal installation README for a package.
278278
279279
Args:
280-
manifest: Package metadata supplying name, description, and version.
281-
repo: Repository name used as the local checkout directory name.
280+
manifest: Package metadata supplying name, description, version, and
281+
optional subpath (for monorepo components).
282+
repo: Repository name used as the local checkout directory name
283+
when *manifest.subpath* is not set.
282284
url: Full VCS URL to embed in the dfetch.yaml snippet.
283285
284286
Returns:
285287
A Markdown string with a package heading, description, and dfetch
286-
installation snippet.
288+
installation snippet. Monorepo components (those with a non-``None``
289+
``manifest.subpath``) include a ``src:`` line that selects the correct
290+
subdirectory, and use the subpath name as the local checkout name.
287291
288292
"""
293+
local_name = manifest.subpath or repo
294+
src_line = f"\n src: {manifest.subpath}" if manifest.subpath else ""
289295
version_line = f"\n tag: {manifest.version}" if manifest.version else ""
290296
return (
291297
f"# {manifest.package_name}\n\n"
@@ -294,11 +300,11 @@ def _generate_readme(manifest: BaseManifest, repo: str, url: str) -> str:
294300
"Add to your `dfetch.yaml`:\n\n"
295301
"```yaml\n"
296302
"projects:\n"
297-
f" - name: ext/{repo}\n"
298-
f" url: {url}{version_line}\n"
303+
f" - name: ext/{local_name}\n"
304+
f" url: {url}{src_line}{version_line}\n"
299305
"```\n\n"
300306
"## Usage\n\n"
301-
f"After running `dfetch update`, the library will be available at `ext/{repo}/`.\n"
307+
f"After running `dfetch update`, the library will be available at `ext/{local_name}/`.\n"
302308
)
303309

304310

test/test_catalog_writer.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,27 @@ def test_generate_readme_uses_provided_url() -> None:
424424
assert "https://gitlab.com/myorg/myrepo" in readme
425425

426426

427+
def test_generate_readme_monorepo_includes_src_line() -> None:
428+
"""Monorepo components include a 'src:' line with the subpath."""
429+
m = _manifest(subpath="mylib")
430+
readme = _generate_readme(m, "mymonorepo", "https://github.com/org/mymonorepo")
431+
assert "src: mylib" in readme
432+
433+
434+
def test_generate_readme_monorepo_uses_subpath_as_local_name() -> None:
435+
"""The local checkout name (ext/<name>) uses subpath, not the repo name."""
436+
m = _manifest(subpath="mylib")
437+
readme = _generate_readme(m, "mymonorepo", "https://github.com/org/mymonorepo")
438+
assert "ext/mylib" in readme
439+
assert "ext/mymonorepo" not in readme
440+
441+
442+
def test_generate_readme_no_subpath_no_src_line() -> None:
443+
"""Packages without a subpath do not emit a 'src:' line."""
444+
readme = _generate_readme(_manifest(), "abseil-cpp", "https://github.com/abseil/abseil-cpp")
445+
assert "src:" not in readme
446+
447+
427448
# ---------------------------------------------------------------------------
428449
# _fetch_upstream_tags
429450
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)