0

If I do...

shutil.make_archive("foo", "gztar")

...it produces foo.tar.gz. How can I tell it to produce foo.tgz instead?

erik
  • 83
  • 6
  • 2
    There's no simple way. Ultimately, `make_archive` calls `shutil._make_tarball`, and that function hard-codes the archive name as `archive_name = base_name + '.tar' + compress_ext`. You would essentially need to reimplement `_make_tarball` to use `base_name + '.tgz'` instead, then patch `shutil._ARCHIVE_FORMATS` to use your new implementation of `_make_tarball`. – chepner Jun 23 '23 at 16:23
  • 1
    I would just create the archive, then rename it. – chepner Jun 23 '23 at 16:23
  • That's what I am doing for now but it makes my code platform-dependent. – erik Jun 23 '23 at 16:24
  • `os.replace` is not platform-dependent. – chepner Jun 23 '23 at 16:40
  • See also [here](https://stackoverflow.com/a/73121102/20851944) what kind of formats are available in shututil. – Hermann12 Jun 23 '23 at 16:42
  • @chepner On windows I can do only `shutil.make_archive()` (with format zip), on posix I must do `shutil.make_archive()` plus `os.replace()`. – erik Jun 26 '23 at 13:01

0 Answers0