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

Return file size along with count on cache purge or removal #13108

Merged
merged 9 commits into from
Dec 12, 2024

Conversation

charwick
Copy link
Contributor

@charwick charwick commented Dec 9, 2024

Fixes #12176

Copy link
Member

@ichard26 ichard26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keep both? It can be helpful to know how many wheels were removed.

You should also use utils.misc.format_size() as reading something like 10,182,123 bytes of files removed is not exactly user friendly...

Perhaps something like this?

        bytes_removed = 0
        for filename in files:
            bytes_removed += os.stat(filename).st_size
            os.unlink(filename)
            logger.verbose("Removed %s", filename)
        logger.info("Files removed: %s (%s)", len(files), format_size(bytes_removed))

@charwick
Copy link
Contributor Author

Good call on format_size(). I'm fine with it reporting both, though I'm curious when it would ever be useful to know the number of files removed?

@charwick charwick changed the title Return file size rather than count on cache purge Return file size along with count on cache purge Dec 10, 2024
Copy link
Member

@ichard26 ichard26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't useful for pip cache purge, yes, but it can helpful when you're trying to remove only a few cached wheels, say with pip cache remove six.

I'll leave this open in case other maintainers have differing opinions, but otherwise, this looks good to me! Thank you!

@@ -0,0 +1 @@
Pip now returns the size, rather than the number, of files cleared on ``pip cache purge``
Copy link
Member

@ichard26 ichard26 Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be updated to note that it's alongside the count and affects both purge and remove.

@ichard26 ichard26 changed the title Return file size along with count on cache purge Return file size along with count on cache purge or removal Dec 12, 2024
@ichard26 ichard26 merged commit 8936fee into pypa:main Dec 12, 2024
31 checks passed
@ichard26
Copy link
Member

Congrats on your first contribution! @charwick

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pip cache purge show freed space
3 participants