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

tarfile should expose supported formats #58221

Open
merwok opened this issue Feb 14, 2012 · 4 comments
Open

tarfile should expose supported formats #58221

merwok opened this issue Feb 14, 2012 · 4 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@merwok
Copy link
Member

merwok commented Feb 14, 2012

BPO 14013
Nosy @gustaebel, @merwok, @berkerpeksag
Files
  • add-tarfile.formats.diff
  • add-tarfile.compression_formats.diff
  • issue14013.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2012-02-14.16:27:26.952>
    labels = ['type-feature', 'library']
    title = 'tarfile should expose supported formats'
    updated_at = <Date 2014-06-23.19:36:25.730>
    user = 'https://github.com/merwok'

    bugs.python.org fields:

    activity = <Date 2014-06-23.19:36:25.730>
    actor = 'berker.peksag'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2012-02-14.16:27:26.952>
    creator = 'eric.araujo'
    dependencies = []
    files = ['24521', '24573', '35742']
    hgrepos = []
    issue_num = 14013
    keywords = ['patch']
    message_count = 4.0
    messages = ['153350', '153650', '153758', '221374']
    nosy_count = 5.0
    nosy_names = ['lars.gustaebel', 'nadeem.vawda', 'eric.araujo', 'docs@python', 'berker.peksag']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue14013'
    versions = ['Python 3.5']

    @merwok
    Copy link
    Member Author

    merwok commented Feb 14, 2012

    shutil contains high-level functions to create a zipfile or a tarball. When a new format is added to the tarfile module, then shutil needs to be updated manually. If tarfile exposed the names of the compressors it supports, then shutil could just automatically support everything that tarfile supports instead of having to re-do import dances for optional modules (bz2, lzma, zlib) and also duplicate formats in its doc.

    This may also be useful for other code wanting to do some introspection.

    Attached patch implements tarfile.formats, a list of strings (I thought about using a frozenset but then followed the precedent set by the 3.3 crypt module). Tests and docs not updated, I wanted to get Lars’ approval on the principle first.

    One could argue that this is not needed: compression modules are not added often; updating shutil after updating tarfile is not hard; it is not that useful to have access to the list of supported formats.

    @merwok merwok added docs Documentation in the Doc dir stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Feb 14, 2012
    @gustaebel
    Copy link
    Mannequin

    gustaebel mannequin commented Feb 18, 2012

    I think this is a reasonable proposal. I think it is good style to let tarfile figure out which supported compression methods are available instead of shutil or the user. So far I have no objections.

    Following 3.3's crypt module, I think the name methods' is superior to formats' (maybe `compression_methods' is even better). Also, crypt's concept of a sorted list from stronger to weaker could also make sense here: ["xz", "bz2", "gz"]. Why not?

    @merwok
    Copy link
    Member Author

    merwok commented Feb 20, 2012

    Thanks for the quick reply.

    I think it is good style to let tarfile figure out which supported compression methods are
    available instead of shutil or the user.
    Note that shutil will not be wholly transparent when I’m done with the refactoring, as it will be able to translate 'xztar', 'bztar' and 'gztar' to tarfile mode strings, but will need to have a special case to morph 'bztar' to 'bz2'. It will be a small ugliness.

    (There will also be ugliness in packaging: Even if I make it transparently supports all formats that shutil supports, I’ll need to have a bit of duplication because packaging has a preferred format by platform. Well.)

    Following 3.3's crypt module, I think the name methods' is superior to formats' (maybe
    `compression_methods' is even better).
    Note that crypt’s methods really are instances of something called Method. hashlib has algorithms_guaranteed and algorithms_available since 3.2 and shutil uses get_archive_formats and get_unpack_formats. I went for tarfile.compression_formats.

    Also, crypt's concept of a sorted list from stronger to weaker could also make sense here:
    Sure. In my first patch I put gz first as it should be universally available, and then put xz before bz2 as I think bz2 is quickly losing ground to xz (even GNU and Debian are switching to xz for their archives). The attached patch follows your idea.

    BTW I will gladly wait for commits related to the other bugs (misc bugs and misc doc edits) and refresh my patch then.

    @berkerpeksag
    Copy link
    Member

    I've updated Éric's patch. Minor changes:

    • Updated versionadded directive
    • A couple of cosmetic changes (e.g. removed brackets in the list comprehension)

    @berkerpeksag berkerpeksag removed the docs Documentation in the Doc dir label Jun 23, 2014
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    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-feature A feature request or enhancement
    Projects
    Status: No status
    Development

    No branches or pull requests

    2 participants