From 6e47055a0b578bbea3ae9bab6a95c046fb666332 Mon Sep 17 00:00:00 2001 From: Mateusz Starzyk Date: Wed, 24 Mar 2021 12:13:33 +0100 Subject: [PATCH 1/6] Allow changelog entries to have URLs exceeding 80 char limit. Signed-off-by: Mateusz Starzyk --- scripts/assemble_changelog.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/assemble_changelog.py b/scripts/assemble_changelog.py index 39632aabf..147bae063 100755 --- a/scripts/assemble_changelog.py +++ b/scripts/assemble_changelog.py @@ -220,7 +220,8 @@ class ChangeLog: body_split = category.body.splitlines() for line_number, line in enumerate(body_split, 1): - if len(line) > MAX_LINE_LENGTH: + if not re.match('.*http[s]?://.*', line.decode('utf-8')) and \ + len(line) > MAX_LINE_LENGTH: raise InputFormatError(filename, category.body_line + line_number, 'Line is longer than allowed: Length {} (Max {})', From 9ee816614862e48df2fef2275a4959c53b144b8c Mon Sep 17 00:00:00 2001 From: Mateusz Starzyk Date: Wed, 24 Mar 2021 12:51:15 +0100 Subject: [PATCH 2/6] Compile URL matching regex before using it in the loop. Signed-off-by: Mateusz Starzyk --- scripts/assemble_changelog.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/assemble_changelog.py b/scripts/assemble_changelog.py index 147bae063..09d9dce73 100755 --- a/scripts/assemble_changelog.py +++ b/scripts/assemble_changelog.py @@ -219,8 +219,9 @@ class ChangeLog: category.name.decode('utf8')) body_split = category.body.splitlines() + re_has_url = re.compile('.*http[s]?://.*') for line_number, line in enumerate(body_split, 1): - if not re.match('.*http[s]?://.*', line.decode('utf-8')) and \ + if not re_has_url.match(line.decode('utf-8')) and \ len(line) > MAX_LINE_LENGTH: raise InputFormatError(filename, category.body_line + line_number, From c8f4489fa5643215fe6820e3ac4a351f59d4a210 Mon Sep 17 00:00:00 2001 From: Mateusz Starzyk Date: Thu, 25 Mar 2021 14:06:50 +0100 Subject: [PATCH 3/6] Use raw string + binary matching for URL regex. Long URLs are allowed only if they are alone on their lines. Signed-off-by: Mateusz Starzyk --- scripts/assemble_changelog.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/assemble_changelog.py b/scripts/assemble_changelog.py index 09d9dce73..e8a1c2179 100755 --- a/scripts/assemble_changelog.py +++ b/scripts/assemble_changelog.py @@ -201,6 +201,8 @@ class ChangeLog: # a version that is not yet released. Something like "3.1a" is accepted. _version_number_re = re.compile(br'[0-9]+\.[0-9A-Za-z.]+') _incomplete_version_number_re = re.compile(br'.*\.[A-Za-z]') + _only_url_re = re.compile(br'^\s*\w+://\S+\s*$') + _has_url_re = re.compile(br'.*://.*') def add_categories_from_text(self, filename, line_offset, text, allow_unknown_category): @@ -219,14 +221,18 @@ class ChangeLog: category.name.decode('utf8')) body_split = category.body.splitlines() - re_has_url = re.compile('.*http[s]?://.*') for line_number, line in enumerate(body_split, 1): - if not re_has_url.match(line.decode('utf-8')) and \ + if not self.__class__._only_url_re.match(line) and \ len(line) > MAX_LINE_LENGTH: + long_url_msg = '. URL exceeding length limit must be ' \ + 'alone in it\'s line.' if \ + self.__class__._has_url_re.match(line) else "" raise InputFormatError(filename, category.body_line + line_number, - 'Line is longer than allowed: Length {} (Max {})', - len(line), MAX_LINE_LENGTH) + 'Line is longer than allowed: ' + 'Length {} (Max {}){}', + len(line), MAX_LINE_LENGTH, + long_url_msg) self.categories[category.name] += category.body From 5172605c492ccb833772a8669640a1c35b025a9c Mon Sep 17 00:00:00 2001 From: Mateusz Starzyk Date: Thu, 25 Mar 2021 14:49:57 +0100 Subject: [PATCH 4/6] Move URL matching regex to method definition. Signed-off-by: Mateusz Starzyk --- scripts/assemble_changelog.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/assemble_changelog.py b/scripts/assemble_changelog.py index e8a1c2179..0428dddb3 100755 --- a/scripts/assemble_changelog.py +++ b/scripts/assemble_changelog.py @@ -201,8 +201,6 @@ class ChangeLog: # a version that is not yet released. Something like "3.1a" is accepted. _version_number_re = re.compile(br'[0-9]+\.[0-9A-Za-z.]+') _incomplete_version_number_re = re.compile(br'.*\.[A-Za-z]') - _only_url_re = re.compile(br'^\s*\w+://\S+\s*$') - _has_url_re = re.compile(br'.*://.*') def add_categories_from_text(self, filename, line_offset, text, allow_unknown_category): @@ -221,12 +219,14 @@ class ChangeLog: category.name.decode('utf8')) body_split = category.body.splitlines() + _only_url_re = re.compile(br'^\s*\w+://\S+\s*$') + _has_url_re = re.compile(br'.*://.*') for line_number, line in enumerate(body_split, 1): - if not self.__class__._only_url_re.match(line) and \ + if not _only_url_re.match(line) and \ len(line) > MAX_LINE_LENGTH: long_url_msg = '. URL exceeding length limit must be ' \ - 'alone in it\'s line.' if \ - self.__class__._has_url_re.match(line) else "" + 'alone in it\'s line.' if _has_url_re.match(line) \ + else "" raise InputFormatError(filename, category.body_line + line_number, 'Line is longer than allowed: ' From 3cfed58227cc570a1670f5777143b1670d7653cc Mon Sep 17 00:00:00 2001 From: Mateusz Starzyk Date: Wed, 31 Mar 2021 11:09:21 +0200 Subject: [PATCH 5/6] Move URL regexes to class scope. Refer to URL regexes by 'self' argument. Signed-off-by: Mateusz Starzyk --- scripts/assemble_changelog.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/assemble_changelog.py b/scripts/assemble_changelog.py index 0428dddb3..a7477aa8e 100755 --- a/scripts/assemble_changelog.py +++ b/scripts/assemble_changelog.py @@ -201,6 +201,8 @@ class ChangeLog: # a version that is not yet released. Something like "3.1a" is accepted. _version_number_re = re.compile(br'[0-9]+\.[0-9A-Za-z.]+') _incomplete_version_number_re = re.compile(br'.*\.[A-Za-z]') + _only_url_re = re.compile(br'^\s*\w+://\S+\s*$') + _has_url_re = re.compile(br'.*://.*') def add_categories_from_text(self, filename, line_offset, text, allow_unknown_category): @@ -219,13 +221,12 @@ class ChangeLog: category.name.decode('utf8')) body_split = category.body.splitlines() - _only_url_re = re.compile(br'^\s*\w+://\S+\s*$') - _has_url_re = re.compile(br'.*://.*') + for line_number, line in enumerate(body_split, 1): - if not _only_url_re.match(line) and \ + if not self._only_url_re.match(line) and \ len(line) > MAX_LINE_LENGTH: long_url_msg = '. URL exceeding length limit must be ' \ - 'alone in it\'s line.' if _has_url_re.match(line) \ + 'alone in it\'s line.' if self._has_url_re.match(line) \ else "" raise InputFormatError(filename, category.body_line + line_number, From 9b31ad64bbec40383063f1b26e5b7954bb074e0e Mon Sep 17 00:00:00 2001 From: Mateusz Starzyk Date: Wed, 31 Mar 2021 11:18:28 +0200 Subject: [PATCH 6/6] Fix error message for long lines with URLs. Fix typo. Remove line break in string's code formatting, to enable searching the code for particular string. Signed-off-by: Mateusz Starzyk --- scripts/assemble_changelog.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/assemble_changelog.py b/scripts/assemble_changelog.py index a7477aa8e..56d6c37e1 100755 --- a/scripts/assemble_changelog.py +++ b/scripts/assemble_changelog.py @@ -225,9 +225,8 @@ class ChangeLog: for line_number, line in enumerate(body_split, 1): if not self._only_url_re.match(line) and \ len(line) > MAX_LINE_LENGTH: - long_url_msg = '. URL exceeding length limit must be ' \ - 'alone in it\'s line.' if self._has_url_re.match(line) \ - else "" + long_url_msg = '. URL exceeding length limit must be alone in its line.' \ + if self._has_url_re.match(line) else "" raise InputFormatError(filename, category.body_line + line_number, 'Line is longer than allowed: '