From 82efd188c4fe612b6179b687a7538462c8e1e893 Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Wed, 30 Apr 2025 15:38:44 +0530 Subject: [PATCH] Fix pep8 issues from the last commit --- tools/release_converter.py | 309 ++++++++++++++++++++++++++----------- 1 file changed, 218 insertions(+), 91 deletions(-) diff --git a/tools/release_converter.py b/tools/release_converter.py index c8345bea3..e3913b722 100644 --- a/tools/release_converter.py +++ b/tools/release_converter.py @@ -32,13 +32,15 @@ Examples: python release_converter.py path/to/notes.rst --output-email-html email.html """ -import re import argparse -import sys import html +import re +import sys # --- PARSING FUNCTION (parse_rst_release_note) --- + + def parse_rst_release_note(rst_text): """Parses the RST release note text to extract key information.""" data = { @@ -67,10 +69,13 @@ def parse_rst_release_note(rst_text): for i, line_raw in enumerate(lines): line_stripped = line_raw.strip() if i > 0: - prev_line_stripped = lines[i-1].strip() - if len(prev_line_stripped) > 3 and all(c == '*' for c in prev_line_stripped): + prev_line_stripped = lines[i - 1].strip() + # Check if the previous line looks like an RST section underline + if len(prev_line_stripped) > 3 and \ + all(c == '*' for c in prev_line_stripped): if i > 1: - header_text_line = lines[i-2].strip().lower() + # Header text is two lines above the current line + header_text_line = lines[i - 2].strip().lower() if "new features" in header_text_line: current_section_list = data['features'] elif "bug fixes" in header_text_line: @@ -78,42 +83,56 @@ def parse_rst_release_note(rst_text): elif "housekeeping" in header_text_line: current_section_list = data['housekeeping'] else: - pass + # Not a section we track, keep previous section active + pass + # Skip the (usually blank) line after the underline continue + # Parse items only if we are within a known section if current_section_list is not None and line_stripped.startswith('|'): line_to_parse = line_stripped - item_match = re.match(r'\|\s*`Issue\s+#(\d+)\s+<([^>]+)>`_\s*-\s*(.*)', line_to_parse) + # Try matching the standard 'Issue #' format + item_match = re.match( + r'\|\s*`Issue\s+#(\d+)\s+<([^>]+)>`_\s*-\s*(.*)', + line_to_parse + ) if item_match: - issue_num, url, description = item_match.groups() - item_data = { - 'issue': issue_num.strip(), - 'url': url.strip(), - 'description': description.strip().rstrip('.') - } - current_section_list.append(item_data) + issue_num, url, description = item_match.groups() + item_data = { + 'issue': issue_num.strip(), + 'url': url.strip(), + 'description': description.strip().rstrip('.') + } + current_section_list.append(item_data) else: - simple_match = re.match(r'\|\s*(.*)', line_to_parse) - simple_text = simple_match.group(1).strip().rstrip('.') if simple_match else None - if simple_text: - item_data = { - 'issue': None, - 'url': None, - 'description': simple_text - } - current_section_list.append(item_data) + # Fallback for items starting with '|' but without Issue link + simple_match = re.match(r'\|\s*(.*)', line_to_parse) + simple_text = (simple_match.group(1).strip().rstrip('.') + if simple_match else None) + if simple_text: + item_data = { + 'issue': None, + 'url': None, + 'description': simple_text + } + current_section_list.append(item_data) + # Combine bug fixes and housekeeping for unified output sections data['bugs_housekeeping'] = data['bug_fixes'] + data['housekeeping'] + # Add warnings if sections seem empty after parsing if not data['features']: print("Warning: No 'New features' items parsed.", file=sys.stderr) if not data['bugs_housekeeping']: - print("Warning: No 'Bug fixes' or 'Housekeeping' items parsed.", file=sys.stderr) + print("Warning: No 'Bug fixes' or 'Housekeeping' items parsed.", + file=sys.stderr) return data # --- Helper for Plurals --- + + def pluralize(count, singular, plural=None): """Adds 's' for pluralization if count is not 1.""" if count == 1: @@ -124,32 +143,61 @@ def pluralize(count, singular, plural=None): # --- Formatting Functions --- + + def format_email_html(data, skip_issues_set=None): - """Formats the extracted data into HTML suitable for email (Google Doc style).""" + """Formats the extracted data into HTML suitable for email.""" if skip_issues_set is None: skip_issues_set = set() if not data.get('version'): return "

Error: Version not found in parsed data.

" version = data['version'] - release_url = f"https://www.pgadmin.org/docs/pgadmin4/{version}/release_notes_{version.replace('.', '_')}.html" + release_url = ( + f"https://www.pgadmin.org/docs/pgadmin4/{version}/" + f"release_notes_{version.replace('.', '_')}.html" + ) download_url = "https://www.pgadmin.org/download/" website_url = "https://www.pgadmin.org/" - filtered_features = [item for item in data.get('features', []) if item.get('issue') not in skip_issues_set] - filtered_bugs = [item for item in data.get('bugs_housekeeping', []) if item.get('issue') not in skip_issues_set] + # Filter lists first based on skip_issues_set + filtered_features = [ + item for item in data.get('features', []) + if item.get('issue') not in skip_issues_set + ] + filtered_bugs = [ + item for item in data.get('bugs_housekeeping', []) + if item.get('issue') not in skip_issues_set + ] num_features = len(filtered_features) num_bugs_housekeeping = len(filtered_bugs) + # Build HTML output output = f"

pgAdmin 4 v{version} Released

\n" - output += f"

The pgAdmin Development Team is pleased to announce pgAdmin 4 version {version}.

\n" - output += (f"

This release of pgAdmin 4 includes {pluralize(num_features, 'new feature')} " - f"and {pluralize(num_bugs_housekeeping, 'bug fix', 'bug fixes')}/housekeeping change{'s' if num_bugs_housekeeping != 1 else ''}. ") - output += f'For more details please see the Release Notes.

\n' - output += '

pgAdmin is the leading Open Source graphical management tool for PostgreSQL. For more information, please see

\n' - output += f'

{website_url}

\n' + output += ( + f"

The pgAdmin Development Team is pleased to announce " + f"pgAdmin 4 version {version}.

\n" + ) + output += ( + f"

This release of pgAdmin 4 includes " + f"{pluralize(num_features, 'new feature')} and " + f"{pluralize(num_bugs_housekeeping, 'bug fix', 'bug fixes')}/" + f"housekeeping change" + f"{'s' if num_bugs_housekeeping != 1 else ''}. " + ) + output += ( + f'For more details please see the ' + f'Release Notes.

\n' + ) + output += ( + '

pgAdmin is the leading Open Source graphical management ' + 'tool for PostgreSQL. For more information, please see

\n' + ) + # Note: Removed ' ' (HTML tab) as it's non-standard; use CSS if needed + output += f'

{website_url}

\n' output += "

Notable changes in this release include:

\n" + # Add features section only if items remain after filtering if filtered_features: output += "

Features

\n\n" + # Add bugs section only if items remain after filtering if filtered_bugs: - output += "

Bugs/Housekeeping

\n