Skip to content

archive or delete old patches#19827

Merged
boegel merged 3 commits intoeasybuilders:5.0.xfrom
branfosj:archive_patches
Feb 11, 2024
Merged

archive or delete old patches#19827
boegel merged 3 commits intoeasybuilders:5.0.xfrom
branfosj:archive_patches

Conversation

@branfosj
Copy link
Copy Markdown
Member

@branfosj branfosj commented Feb 11, 2024

If the patch is not used in an EB5 easyconfig then:

  • move it to the archive
  • or delete it (if there is no matching directory in the archive)
  • and restore the ones that the testsuite fails on (these look to be related to finding patches in components)

Yes, I know these numbers do not add up. The unused count is of unique patch names, but the archived/deleted counts count each instance of a patch name.

currently 2630 patches
1290 unused patches
1256 archived and 52 deleted
Code used
import glob
import os
from easybuild.framework.easyconfig.easyconfig import EasyConfig
from easybuild.tools.options import set_up_configuration
from easybuild.tools.run import run_shell_cmd

set_up_configuration(reconfigure=True)

f = '*'
patches = {}
for patch in glob.glob(f"{f}/*/*.patch*"):
    if os.path.basename(patch) not in patches:
        patches[os.path.basename(patch)] = []
    patches[os.path.basename(patch)].append(patch)
print(f"currently {len(patches)} patches")

ecs = glob.glob(f"{f}/*/*.eb")
easyconfigs = []
for ec in ecs:
    e = EasyConfig(ec, validate=False)
    
    if 'components' in e and e['components']:
        for component in e['components']:
            if len(component) > 2 and type(component[2]) is not str:
                for patch in component[2].get('patches', []):
                    if type(patch) == str:
                        patchfile = patch
                    elif type(patch) == tuple:
                        patchfile = patch[0]
                    else:
                        patchfile = patch['name']
                    if patchfile in patches:
                        del patches[patchfile]

    for ext in e['exts_list']:
        if isinstance(ext, tuple) and len(ext) >= 3:
            for patch in ext[2].get('patches', []):
                if type(patch) == str:
                    patchfile = patch
                elif type(patch) == tuple:
                    patchfile = patch[0]
                else:
                    patchfile = patch['name']
                if patchfile in patches:
                    del patches[patchfile]

    for patch in e['patches']:
        if type(patch) == str:
            patchfile = patch
        elif type(patch) == tuple:
            patchfile = patch[0]
        else:
            patchfile = patch['name']
        if patchfile in patches:
            del patches[patchfile]

print(f"{len(patches)} unused patches")

archive = 0
delete = 0
for p in patches:
    for pf in patches[p]:
        # if no directory then the patch is ancient (only for something we archived in an older version)
        if os.path.isdir(os.path.dirname(f"__archive__/{pf}")):
            run_shell_cmd(f"git mv {pf} __archive__/{pf}")
            archive += 1
        else:
            run_shell_cmd(f"git rm {pf}")
            delete += 1

print(f"{archive} archived and {delete} deleted")

@branfosj branfosj added this to the 5.0 milestone Feb 11, 2024
@boegel boegel merged commit 11a05ac into easybuilders:5.0.x Feb 11, 2024
@branfosj branfosj deleted the archive_patches branch February 11, 2024 17:05
@branfosj branfosj mentioned this pull request Jun 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

No open projects
Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants