diff mbox series

[AUH,v3,1/2] steps: refactor _get_changelog to update pkg_ctx

Message ID 20261026135414.3796371-1-daniel.turull@ericsson.com
State New
Headers show
Series [AUH,v3,1/2] steps: refactor _get_changelog to update pkg_ctx | expand

Commit Message

Daniel Turull Oct. 26, 2026, 1:54 p.m. UTC
From: Daniel Turull <daniel.turull@ericsson.com>

Keep the handling of devtool's changelog output in one place instead
of splitting it between _get_changelog() and its caller.

No functional change.

Assisted-by: kiro:claude-sonnet-5.5
Signed-off-by: Daniel Turull <daniel.turull@ericsson.com>
---
Changes in v3:
- New patch: refactor split out of "steps: skip changelog in commit
  message when devtool flags it"
---
 modules/steps.py | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

Comments

Alexander Kanavin Oct. 26, 2026, 5:38 p.m. UTC | #1
> +def _get_changelog(pkg_ctx, workdir):
> +    """Copy the changelog generated by devtool upgrade to workdir and
> +    store the changelog data in pkg_ctx."""
> +    pn = pkg_ctx['PN']
> +    base_path = os.path.join(os.environ.get('BUILDDIR', ''),
> +                             'workspace', 'changelogs', pn)
> +    changelog_path = base_path + '.txt'
>      if os.path.isfile(changelog_path):
>          try:
>              with open(changelog_path, 'r', encoding='utf-8',
> errors='replace') as f:
>                  text = f.read()
>              shutil.copy2(changelog_path, os.path.join(workdir,
> '{}-changelog.txt'.format(pn)))
> -            return text
>          except OSError as e:
>              W('Failed to copy changelog for {}: {}'.format(pn, e))
> -    return None
> +            return
> +        if text:
> +            pkg_ctx['changelog_text'] = text
>
>
Apologies, that's not quite what I had in mind. The intended suggestion was
to read the json once, and assign all of its fields as a property of
pkg_ctx. Then when the actual changelog content is needed, it would be
obtained through fields of that property, since it already contains the
filename of the actual text.

Alex
diff mbox series

Patch

diff --git a/modules/steps.py b/modules/steps.py
index e678a4b..0dc365c 100644
--- a/modules/steps.py
+++ b/modules/steps.py
@@ -80,20 +80,23 @@  def _make_commit_msg(group):
     versions = list(dict.fromkeys(_get_version(p) for p in group['pkgs']))
     return "{}: upgrade {}".format(pn, ",".join(versions))
 
-def _get_changelog(pn, workdir):
-    """Read the changelog generated by devtool upgrade and copy it to workdir.
-    Returns the changelog text or None."""
-    changelog_path = os.path.join(os.environ.get('BUILDDIR', ''),
-                                  'workspace', 'changelogs', '{}.txt'.format(pn))
+def _get_changelog(pkg_ctx, workdir):
+    """Copy the changelog generated by devtool upgrade to workdir and
+    store the changelog data in pkg_ctx."""
+    pn = pkg_ctx['PN']
+    base_path = os.path.join(os.environ.get('BUILDDIR', ''),
+                             'workspace', 'changelogs', pn)
+    changelog_path = base_path + '.txt'
     if os.path.isfile(changelog_path):
         try:
             with open(changelog_path, 'r', encoding='utf-8', errors='replace') as f:
                 text = f.read()
             shutil.copy2(changelog_path, os.path.join(workdir, '{}-changelog.txt'.format(pn)))
-            return text
         except OSError as e:
             W('Failed to copy changelog for {}: {}'.format(pn, e))
-    return None
+            return
+        if text:
+            pkg_ctx['changelog_text'] = text
 
 
 def _append_changelog_to_commit_msg(group, opts):
@@ -119,9 +122,7 @@  def _devtool_upgrade(devtool, bb, git, opts, pkg_ctx, workdir):
         devtool_output = devtool.upgrade(pkg_ctx['PN'], pkg_ctx['NPV'], pkg_ctx['NSRCREV'])
         D(" 'devtool upgrade' printed:\n%s" %(devtool_output))
         # Copy changelog before checking for conflicts — it's useful even on failure
-        changelog_text = _get_changelog(pkg_ctx['PN'], workdir)
-        if changelog_text:
-            pkg_ctx['changelog_text'] = changelog_text
+        _get_changelog(pkg_ctx, workdir)
         # If devtool failed to rebase patches, it does not fail, but we should
         if 'conflict' in devtool_output:
             raise DevtoolError("Running 'devtool upgrade' for recipe %s failed." %(pkg_ctx['PN']), devtool_output)