Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zipapp archives are always empty #130379

Open
swhcz opened this issue Feb 20, 2025 · 1 comment
Open

Zipapp archives are always empty #130379

swhcz opened this issue Feb 20, 2025 · 1 comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@swhcz
Copy link

swhcz commented Feb 20, 2025

Bug report

Bug description:

Good evening,

I have recently installed Python 3.13 (Windows x64) over 3.12.
Now zipapp.create_archive(..) is creating just empty archives.

After some fiddling around I found there might be an issue in these lines:

(from zipapp.py, lines 113 ff)

    with _maybe_open(target, 'wb') as fd:
        _write_file_prefix(fd, interpreter)
        compression = (zipfile.ZIP_DEFLATED if compressed else
                       zipfile.ZIP_STORED)
        with zipfile.ZipFile(fd, 'w', compression=compression) as z:
            for child in sorted(source.rglob('*')):
                arcname = child.relative_to(source)
                if filter is None or filter(arcname) and child.resolve() != arcname.resolve():   # ██ LOOK HERE ! ██
                    z.write(child, arcname.as_posix())
            if main_py:
                z.writestr('__main__.py', main_py.encode('utf-8'))

This change was introduced in Python 3.13 (have verified against 3.12 sources) and seemingly causes the trouble.

My guess is, as child is pointing to the same file as arcname, and naturally, they both resolve to the same file, no file gets added due to the != check, ever, to the archive-to-be-created.

Maybe it was intended to check against target, not arcname?

Once I monkeypatched the and child.resolve() != arcname.resolve() part away, the archive got written again.

Or am I just not doing it right?
Any help much appreciated!

Sebastian.

CPython versions tested on:

3.13

Operating systems tested on:

Windows

@swhcz swhcz added the type-bug An unexpected behavior, bug, or error label Feb 20, 2025
@swhcz
Copy link
Author

swhcz commented Feb 20, 2025

maybe related to #104527 ?

@swhcz swhcz changed the title Zipapp creates empty archives Zipapp archives are always empty Feb 20, 2025
@encukou encukou added the stdlib Python modules in the Lib dir label Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants