diff -Nru python-debian-0.1.45/debian/changelog python-debian-0.1.46/debian/changelog --- python-debian-0.1.45/debian/changelog 2022-07-05 15:35:04.000000000 +0000 +++ python-debian-0.1.46/debian/changelog 2022-07-08 16:45:29.000000000 +0000 @@ -1,8 +1,25 @@ +python-debian (0.1.46) unstable; urgency=medium + + * Copyright.add_files_paragraph(): Append after the last existing + files paragraph. + * RTS parser: Fix removing and then re-adding a paragraph. + + -- Jelmer Vernooij Fri, 08 Jul 2022 17:45:29 +0100 + python-debian (0.1.45) unstable; urgency=medium + [ Jelmer Vernooij ] * Add Deb822FileElement.remove method. * RTS parser: don't add trailing whitespace when setting field values that start with a newline. Closes: #1013485 + * RTS parser: Add Deb822FileElement.remove(). + + [ Niels Thykier ] + * RTS parser: minor performance improvements (~5%). + * RTS parser: Stop preserving lack of newlines at EOF. Closes: #998715 + * Add substvars module for handling substvars. + * copyright: Use RTS parser. + * Provide `DpkgArchTable` class as a subset of `Dpkg::Arch`. Closes: #771058 -- Jelmer Vernooij Tue, 05 Jul 2022 16:35:04 +0100 diff -Nru python-debian-0.1.45/lib/debian/copyright.py python-debian-0.1.46/lib/debian/copyright.py --- python-debian-0.1.45/lib/debian/copyright.py 2022-07-05 15:35:04.000000000 +0000 +++ python-debian-0.1.46/lib/debian/copyright.py 2022-07-08 16:45:29.000000000 +0000 @@ -251,7 +251,7 @@ if isinstance(p, FilesParagraph): last_i = i self.__paragraphs.insert(last_i + 1, paragraph) - self.__file.insert(last_i + 1, paragraph._underlying_paragraph) + self.__file.insert(last_i + 2, paragraph._underlying_paragraph) def all_license_paragraphs(self): # type: () -> Iterator[LicenseParagraph] diff -Nru python-debian-0.1.45/lib/debian/_deb822_repro/parsing.py python-debian-0.1.46/lib/debian/_deb822_repro/parsing.py --- python-debian-0.1.45/lib/debian/_deb822_repro/parsing.py 2022-07-05 15:35:04.000000000 +0000 +++ python-debian-0.1.46/lib/debian/_deb822_repro/parsing.py 2022-07-08 16:45:29.000000000 +0000 @@ -2767,29 +2767,26 @@ if tail_element and not isinstance(tail_element, Deb822WhitespaceToken): self._token_and_elements.append(self._set_parent(Deb822WhitespaceToken('\n'))) self._token_and_elements.append(self._set_parent(paragraph)) - paragraph.parent_element = self def remove(self, paragraph): # type: (Deb822ParagraphElement) -> None if paragraph.parent_element is not self: raise ValueError("Paragraph is part of a different file") - it = self._token_and_elements.iter_nodes() - previous_node = None - for node in it: + node = None + for node in self._token_and_elements.iter_nodes(): if node.value is paragraph: break - previous_node = node - else: + if node is None: raise RuntimeError("unable to find paragraph") - self._token_and_elements.remove_node(node) # pylint: disable=undefined-loop-variable - try: - next_node = next(it) - except StopIteration: + previous_node = node.previous_node + next_node = node.next_node + self._token_and_elements.remove_node(node) + if next_node is None: if previous_node and isinstance(previous_node.value, Deb822WhitespaceToken): - previous_node.remove() + self._token_and_elements.remove_node(previous_node) else: if isinstance(next_node.value, Deb822WhitespaceToken): - next_node.remove() + self._token_and_elements.remove_node(next_node) paragraph.parent_element = None def _set_parent(self, t): diff -Nru python-debian-0.1.45/lib/debian/tests/test_copyright.py python-debian-0.1.46/lib/debian/tests/test_copyright.py --- python-debian-0.1.45/lib/debian/tests/test_copyright.py 2022-07-05 15:35:04.000000000 +0000 +++ python-debian-0.1.46/lib/debian/tests/test_copyright.py 2022-07-08 16:45:29.000000000 +0000 @@ -476,11 +476,24 @@ ['bar/*'], 'CompanyB', copyright.License('Apache')) c.add_files_paragraph(files1) c.add_files_paragraph(files2) - self.assertIs(files1, c.find_files_paragraph('foo/bar.cc')) - self.assertIs(files2, c.find_files_paragraph('bar/baz.cc')) + paragraphs = list(c.all_files_paragraphs()) + self.assertIs(paragraphs[0], c.find_files_paragraph('foo/bar.cc')) + self.assertIs(paragraphs[1], c.find_files_paragraph('bar/baz.cc')) self.assertIsNone(c.find_files_paragraph('baz/quux.cc')) self.assertIsNone(c.find_files_paragraph('Makefile')) + self.assertEqual("""\ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ + +Files: foo/* +Copyright: CompanyA +License: ISC + +Files: bar/* +Copyright: CompanyB +License: Apache +""", c.dump()) + def test_all_license_paragraphs(self): # type: () -> None c = copyright.Copyright(sequence=SIMPLE.splitlines(True)) diff -Nru python-debian-0.1.45/lib/debian/tests/test_repro_deb822.py python-debian-0.1.46/lib/debian/tests/test_repro_deb822.py --- python-debian-0.1.45/lib/debian/tests/test_repro_deb822.py 2022-07-05 15:35:04.000000000 +0000 +++ python-debian-0.1.46/lib/debian/tests/test_repro_deb822.py 2022-07-08 16:45:29.000000000 +0000 @@ -853,6 +853,22 @@ "Mutation should have worked while preserving " "comments") + # Verify that we can add another paragraph. + deb822_file.append(Deb822ParagraphElement.from_dict({'Package': 'bloe'})) + + expected = textwrap.dedent('''\ + Source: foo + # Comment for RRR + Rules-Requires-Root: no + + Package: bloe + ''') + + self.assertEqual(expected, deb822_file.convert_to_text(), + "Adding new paragraph should have worked") + + deb822_file.remove(list(deb822_file)[1]) + source_paragraph = list(deb822_file)[0] self.assertEqual('foo', source_paragraph['Source'])