#!/usr/bin/env python3

"""Remake the ziptestdata.zip file.

Run this to rebuild the importlib_resources/tests/data/ziptestdata.zip file,
e.g. if you want to add a new file to the zip.

This will replace the file with the new build, but it won't commit anything to
git.
"""

import contextlib
import os
import pathlib
from zipfile import ZipFile


def main():
    suffixes = '01', '02'
    tuple(map(generate, suffixes))


def generate(suffix):
    basepath = pathlib.Path('ziptestdata')
    base = pathlib.Path('importlib_resources/tests')
    zfpath = base / f'zipdata{suffix}/ziptestdata.zip'
    with ZipFile(zfpath, 'w') as zf:
        relpath = base / f'data{suffix}'
        for dirpath, dirnames, filenames in os.walk(relpath):
            with contextlib.suppress(KeyError):
                dirnames.remove('__pycache__')
            for filename in filenames:
                src = os.path.join(dirpath, filename)
                if src == zfpath:
                    continue
                commonpath = os.path.commonpath((relpath, dirpath))
                dst = basepath / dirpath[len(commonpath) + 1 :] / filename
                print(src, '->', dst)
                zf.write(src, dst)


__name__ == '__main__' and main()

@@ -634,19 +634,20 @@
         
-rel
+data
 path = b
@@ -720,19 +720,20 @@
 os.walk(
-rel
+data
 path):%0A 
@@ -826,16 +826,78 @@
 che__')%0A
+            loc = pathlib.Path(dirpath).relative_to(datapath)%0A
         
@@ -1048,76 +1048,8 @@
 nue%0A
-                commonpath = os.path.commonpath((relpath, dirpath))%0A
     
@@ -1081,38 +1081,11 @@
 h / 
-dirpath%5Blen(commonpath) + 1 :%5D
+loc
  / f

Use relative_to instead of string manipulation