GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Extract ZipInfo for archive functionality · Issue #123424 · python/cpython

Extract ZipInfo for archive functionality #123424

New issue
Copy link
New issue
Copy link
Closed
#123429
Closed
Extract ZipInfo for archive functionality#123424
#123429
Copy link
Assignees
jaraco
Labels
easystdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

@jaraco
jaraco
opened on Aug 28, 2024
Issue body actions

In #123354, I found the need to copy code from zipfile into the test:

cpython/Lib/test/test_zipfile/_path/test_path.py

Lines 662 to 676 in 9e108b8

def for_name(cls, name, archive):
"""
Construct the same way that ZipFile.writestr does.
TODO: extract this functionality and re-use
"""
self = cls(filename=name, date_time=time.localtime(time.time())[:6])
self.compress_type = archive.compression
self.compress_level = archive.compresslevel
if self.filename.endswith('/'): # pragma: no cover
self.external_attr = 0o40775 << 16 # drwxrwxr-x
self.external_attr |= 0x10 # MS-DOS directory flag
else:
self.external_attr = 0o600 << 16 # ?rw-------
return self

Let's instead extract that functionality in the zipfile module for re-use in the test (before it starts diverging).

Linked PRs

  • gh-123424: add ZipInfo._for_archive to set suitable default properties #123429

Activity

Next
  1. jaraco
    assigned
    jaraco
    and unassigned
    jaraco
    on Aug 28, 2024
  2. jaraco
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    easy
    on Aug 28, 2024
  3. picnixz
    added this to Zipfile issues 📦on Aug 28, 2024
  4. picnixz commented on Aug 28, 2024

    @picnixz
    picnixz
    on Aug 28, 2024
    Member
    More actions

    @jaraco are you taking it or not? if not, I can take it

  5. jaraco
    assigned
    picnixz
    on Aug 28, 2024
  6. jaraco commented on Aug 28, 2024

    @jaraco
    jaraco
    on Aug 28, 2024
    MemberAuthor
    More actions

    Originally, I was planning to do it, but then I realized it might be an interesting one for others. Have at it!

  7. picnixz
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Aug 28, 2024
  8. serhiy-storchaka commented on Aug 28, 2024

    @serhiy-storchaka
    serhiy-storchaka
    on Aug 28, 2024
    Member
    More actions

    See also #121402 that implements a similar feature.

    I paused it because I am planning to try a different approach.

    Reacted by JustinLi
  9. obfusk commented on Sep 2, 2024

    @obfusk
    obfusk
    on Sep 2, 2024
    Contributor
    More actions

    Nothing against extracting the functionality if it's useful elsewhere, but the test doesn't actually depend on the compression or any of the metadata set by for_name(), just the file name. Nothing else should matter to zipfile.Path here. So removing for_name() and just using zf.writestr(DirtyZipInfo("foo\\bar"), b"content") should work fine.

  10. jaraco commented on Sep 2, 2024

    @jaraco
    jaraco
    on Sep 2, 2024
    MemberAuthor
    More actions

    When I added the for_name to DirtyZipInfo, I was aiming to replace writestr without altering the way it worked. That is, every other test relies on writestr, so I wanted to construct an equivalent ZipInfo, assuming that whoever wrote writestr had reasons for defaulting the date_time, compression type, compression level, and external attrs. I wanted to avoid having to research the motivations for each of those concerns to see if they may apply to this specific case. I wanted to avoid the possibility that those attributes had a meaningful effect or worse did not have an effect today but would in the future. More importantly, I wanted to be sure that if writestr changed in the future to add additional behavior, this routine would inherit that same behavior. By reducing incidental variance, we improve reliability long-term.

    Reacted by FC (Fay) Stegerman
  11. obfusk commented on Sep 2, 2024

    @obfusk
    obfusk
    on Sep 2, 2024
    Contributor
    More actions

    Passing a ZipInfo to writestr() will not set any of those attributes like passing only a filename (and thus having writestr() create the ZipInfo) will and is clearly supported as part of the current API. I rely on this regularly for Reproducible Builds where I need to set the attributes to specific values and using the current time would definitely be unacceptable.

    And the fact that writestr() by default uses the current time means no two test runs ever use the exact same metadata, which is something I would generally try to avoid.

    That said, even if I very much doubt any of the metadata would ever affect this specific test, and would consider that changing to be a bug, I agree that ensuring consistency wrt to writestr() behaviour between different tests is good. Just wanted to clarify the current situation :)

  12. picnixz commented on Dec 22, 2024

    @picnixz
    picnixz
    on Dec 22, 2024
    Member
    More actions

    Removing my assignment on this task since I didn't continue working on the associated PR (and have to prioritize my backlog).

  13. picnixz
    removed their assignment
    on Dec 22, 2024
  14. 12 remaining items

  15. halstead
    added 3 commits that reference this issue on Aug 12, 2025

    python3-zipp: upgrade 3.21.0 -> 3.23.0

    b32d029

    python3-zipp: upgrade 3.21.0 -> 3.23.0

    8c4676b

    python3-zipp: upgrade 3.21.0 -> 3.23.0

    11e7a6a
  16. brainhoard-github
    added 3 commits that reference this issue on Aug 12, 2025

    python3-zipp: upgrade 3.21.0 -> 3.23.0

    fb70511

    python3-zipp: upgrade 3.21.0 -> 3.23.0

    ec7370e

    python3-zipp: upgrade 3.21.0 -> 3.23.0

    24d739e
  17. halstead
    added 2 commits that reference this issue on Aug 13, 2025

    python3-zipp: upgrade 3.21.0 -> 3.23.0

    88fb7af

    python3-zipp: upgrade 3.21.0 -> 3.23.0

    1e764c4
  18. brainhoard-github
    added a commit that references this issue on Aug 14, 2025

    python3-zipp: upgrade 3.21.0 -> 3.23.0

    dc403f2
  19. halstead
    added 4 commits that reference this issue on Aug 14, 2025

    python3-zipp: upgrade 3.21.0 -> 3.23.0

    8c0f3e2

    python3-zipp: upgrade 3.21.0 -> 3.23.0

    50ab43a

    python3-zipp: upgrade 3.21.0 -> 3.23.0

    d8ae9d8

    python3-zipp: upgrade 3.21.0 -> 3.23.0

    f4f9a22
  20. brainhoard-github
    added a commit that references this issue on Aug 14, 2025

    python3-zipp: upgrade 3.21.0 -> 3.23.0

    7dcb5f3
  21. halstead
    added a commit that references this issue on Aug 14, 2025

    python3-zipp: upgrade 3.21.0 -> 3.23.0

    f8d9e47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @jaraco
    jaraco

Labels

easystdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Projects

  • Zipfile issues 📦
    Status
    Done
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.