Skip to content

Commit 1803f47

Browse files
committed
manifest: say when there was nothing to do
A run which found everything already current printed nothing and exited 0, which is indistinguishable from one that silently ignored you, the complaint behind both #80 and #108. Report "manifests are up to date" when the operation got through without reporting any work of its own, and pass the verbosity down so -v names each package that was passed over and why. -q stays silent. Resolves: #80 Resolves: #108 Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 1a6cb15 commit 1803f47

3 files changed

Lines changed: 54 additions & 1 deletion

File tree

‎NEWS.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ pkgdev 0.2.17 (unreleased)
1414

1515
**pkgdev manifest:**
1616

17+
- manifest: a run with nothing to do now says so instead of printing nothing
18+
at all, and ``-v`` names each package passed over and why (Arthur Zamarin,
19+
#80, #108)
20+
1721
- manifest: any file inside a package directory now manifests that package,
1822
so ``pkgdev manifest files/some.patch`` works rather than failing to parse
1923
the path as an atom (Arthur Zamarin, #80)

‎src/pkgdev/scripts/pkgdev_manifest.py‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,33 @@ def _manifest_validate(parser, namespace):
127127
namespace.restriction = packages.AndRestriction(*restrictions)
128128

129129

130+
class _ManifestObserver(observer_mod.formatter_output):
131+
"""Observer noting whether the operation reported doing anything."""
132+
133+
def __init__(self, out, verbosity=0):
134+
super().__init__(out)
135+
self.verbosity = verbosity
136+
self.reported = False
137+
138+
def info(self, msg, *args, **kwds):
139+
self.reported = True
140+
super().info(msg, *args, **kwds)
141+
142+
130143
@manifest.bind_main_func
131144
def _manifest(options, out, err):
145+
observer = _ManifestObserver(out, options.verbosity)
132146
failed = options.repo.operations.manifest(
133147
domain=options.domain,
134148
restriction=options.restriction,
135-
observer=observer_mod.formatter_output(out),
149+
observer=observer,
136150
mirrors=options.mirrors,
137151
force=options.force,
138152
distdir=options.distdir,
139153
)
140154

155+
# a silent run is indistinguishable from one which did nothing at all
156+
if not failed and not observer.reported and options.verbosity >= 0:
157+
out.write("manifests are up to date")
158+
141159
return int(any(failed))

‎tests/scripts/test_pkgdev_manifest.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,37 @@ def test_good_manifest(self, capsys, repo):
189189
self.script()
190190
assert excinfo.value.code == 0
191191
out, err = capsys.readouterr()
192+
assert err == ""
193+
assert out.strip() == "manifests are up to date"
194+
195+
def test_target_within_pkgdir(self, capsys, repo):
196+
"""Any file inside a package dir manifests that package."""
197+
repo.create_ebuild("cat/pkg-0")
198+
pkgdir = os.path.dirname(repo.create_ebuild("cat/pkg-1"))
199+
os.makedirs(pjoin(pkgdir, "files"), exist_ok=True)
200+
touch(pjoin(pkgdir, "files", "a.patch"))
201+
for target in ("files/a.patch", "files", "metadata.xml"):
202+
touch(pjoin(pkgdir, "metadata.xml"))
203+
with (
204+
patch("sys.argv", self.args + [target]),
205+
pytest.raises(SystemExit) as excinfo,
206+
chdir(pkgdir),
207+
):
208+
self.script()
209+
assert excinfo.value.code == 0
210+
out, err = capsys.readouterr()
211+
assert err == ""
212+
213+
def test_good_manifest_quiet(self, capsys, repo):
214+
repo.create_ebuild("cat/pkg-0")
215+
with (
216+
patch("sys.argv", self.args + ["-q"]),
217+
pytest.raises(SystemExit) as excinfo,
218+
chdir(repo.location),
219+
):
220+
self.script()
221+
assert excinfo.value.code == 0
222+
out, err = capsys.readouterr()
192223
assert out == err == ""
193224

194225
def test_target_within_pkgdir(self, capsys, repo):

0 commit comments

Comments
 (0)