AttributeError in PGPContainer
The testsuite is revealing this in some cases:
============================================================================================= warnings summary =============================================================================================
tests/comparators/test_pgp.py::test_no_differences
tests/comparators/test_pgp.py::test_diff
tests/comparators/test_pgp.py::test_compare_non_existing
tests/comparators/test_pgp.py::test_signed_diff
/usr/lib/python3/dist-packages/_pytest/unraisableexception.py:78: PytestUnraisableExceptionWarning: Exception ignored in: <function Archive.__del__ at 0xf5cbdd18>
Traceback (most recent call last):
File "/build/diffoscope-186/diffoscope/comparators/utils/archive.py", line 47, in __del__
self.close_archive()
File "/build/diffoscope-186/diffoscope/comparators/pgp.py", line 75, in close_archive
self._temp_dir.cleanup()
AttributeError: 'PGPContainer' object has no attribute '_temp_dir'
warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))
-- Docs: https://docs.pytest.org/en/stable/warnings.html
This happens when gpg
is not available in the past, which happens during the debian build, as we install gnupg-utils
for the pgpdump
tool, but not gpg
itself, which is indeed not required during the tests.
I did a light debugging in this. Trying to run it manually reveals this:
% bin/diffoscope --debug tests/data/test1_signed.pgp tests/data/test2_signed.pgp
...
2021-09-26 15:08:42 D: diffoscope.comparators.utils.specialize: Using pgp.PgpFile for tests/data/test1_signed.pgp
...
2021-09-26 15:08:42 D: diffoscope.comparators.utils.specialize: Using pgp.PgpFile for tests/data/test2_signed.pgp
...
2021-09-26 15:08:42 D: diffoscope.comparators.utils.file: Instantiating a pgp.PGPContainer for tests/data/test1_signed.pgp
2021-09-26 15:08:42 D: diffoscope.comparators.utils.file: Cannot instantiate a pgp.PGPContainer; missing tool gpg
Exception ignored in: <function Archive.__del__ at 0xf419d808>
Traceback (most recent call last):
File "/build/diffoscope-186/diffoscope/comparators/utils/archive.py", line 47, in __del__
self.close_archive()
File "/build/diffoscope-186/diffoscope/comparators/pgp.py", line 75, in close_archive
self._temp_dir.cleanup()
AttributeError: 'PGPContainer' object has no attribute '_temp_dir'
2021-09-26 15:08:42 D: diffoscope.presenters.formats: Generating 'text' output at '-'
...
And then diffoscope proceeds to give me the diff coming from pgpdump
.
This particular exception is trivial to fix by simply adding an if self._temp_dir:
to the close_archive()
function, however, I believe that function should not be called at all. As the log says, it directly fails to instantiate the PGPContainer, so reason would tell me that it shouldn't even try to "close" it later. Indeed grepping the code I see plenty of other containers that "destruct" themselves without a check on the existence of their temp dir; I didn't look deep, but just by that I suspect this might be also visible in other comparators.
Right this moment I don't have the time to dig into the plenty of levels of inference between comparators, File
and Archive
, so I'm filing this issue if somebody wants to pick it up.