-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
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
gh-99203: shutil.make_archive()
: restore select CPython <= 3.10.5 behavior
#99802
Conversation
Will look into the failed Windows tests later. |
…10.5 behavior Restore following CPython <= 3.10.5 behavior of `shutil.make_archive()` that went away as part of pythongh-93160: Do not create an empty archive if `root_dir` is not a directory, and, in that case, raise `FileNotFoundError` or `NotADirectoryError` regardless of `format` choice. Beyond the brought-back behavior, the function may now also raise these exceptions in `dry_run` mode.
@giampaolo if I'm not mistaken, the P.S.: I acknowledge [1], [2] and won't force-push here any longer, sorry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating an empty archive without raising an exception is definitely a bug. Leaving an empty archive and raising an exception is more in a grey area, but in any case it is better to not create it if we can to detect an error earlier.
Thanks for the review! I addressed the findings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Thank you for your response and sorry for the delay. This issue fell off my radar.
Thanks @6t8k for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
Sorry, @6t8k and @serhiy-storchaka, I could not cleanly backport this to |
….5 behavior (pythonGH-99802) Restore following CPython <= 3.10.5 behavior of shutil.make_archive() that went away as part of pythongh-93160: Do not create an empty archive if root_dir is not a directory, and, in that case, raise FileNotFoundError or NotADirectoryError regardless of format choice. Beyond the brought-back behavior, the function may now also raise these exceptions in dry_run mode. (cherry picked from commit a86df29) Co-authored-by: 6t8k <58048945+6t8k@users.noreply.github.com>
GH-107998 is a backport of this pull request to the 3.12 branch. |
…<= 3.10.5 behavior (pythonGH-99802) Restore following CPython <= 3.10.5 behavior of shutil.make_archive() that went away as part of pythongh-93160: Do not create an empty archive if root_dir is not a directory, and, in that case, raise FileNotFoundError or NotADirectoryError regardless of format choice. Beyond the brought-back behavior, the function may now also raise these exceptions in dry_run mode.. (cherry picked from commit a86df29) Co-authored-by: 6t8k <58048945+6t8k@users.noreply.github.com>
GH-107999 is a backport of this pull request to the 3.11 branch. |
…0.5 behavior (GH-99802) (GH-107999) Restore following CPython <= 3.10.5 behavior of shutil.make_archive() that went away as part of gh-93160: Do not create an empty archive if root_dir is not a directory, and, in that case, raise FileNotFoundError or NotADirectoryError regardless of format choice. Beyond the brought-back behavior, the function may now also raise these exceptions in dry_run mode. (cherry picked from commit a86df29) Co-authored-by: 6t8k <58048945+6t8k@users.noreply.github.com>
…0.5 behavior (GH-99802) (#107998) gh-99203: shutil.make_archive(): restore select CPython <= 3.10.5 behavior (GH-99802) Restore following CPython <= 3.10.5 behavior of shutil.make_archive() that went away as part of gh-93160: Do not create an empty archive if root_dir is not a directory, and, in that case, raise FileNotFoundError or NotADirectoryError regardless of format choice. Beyond the brought-back behavior, the function may now also raise these exceptions in dry_run mode. (cherry picked from commit a86df29) Co-authored-by: 6t8k <58048945+6t8k@users.noreply.github.com>
root_dir
does not exist, or is not a directory, then CPython >3.10.5 will create an empty archive, so introduce an explicit check for it being a directory.shutil.make_archive()
may then raiseFileNotFoundError
orNotADirectoryError
before proceeding to call the internal format-specific archive creation function, as was formerly (implicitly) caused byos.chdir(root_dir)
, restoring CPython <=3.10.5 behavior._make_tarball()
and_make_zipfile()
scenario: although the former, unlike the latter, may already causeNotADirectoryError
orFileNotFoundError
to be raised with respect toroot_dir
without this proposed change, an empty archive will still be created. On the other hand,_make_zipfile()
, is able to create an empty archive while not raising any exceptions, so test it as well, even thoughmake_archive()
would otherwise already be covered bytest_make_tarfile_rootdir_nodir()
, which runs regardless of zlib availability.