-
Notifications
You must be signed in to change notification settings - Fork 281
feat: add a --clean-cache
command to clean up locations specified at CIBW_CACHE_PATH
#2489
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d955e47
Add `clean_cache` to command-line arguments
agriyakhetarpal 7a19069
Add `--clean-cache` to parser
agriyakhetarpal f705697
Add logic
agriyakhetarpal 1039440
Add test to clean cache when it exists
agriyakhetarpal 810c7fa
Ad test to run cache cleaning when none exists
agriyakhetarpal 0687cc1
Add test to run cache cleaning on unwritable path
agriyakhetarpal 5196729
Use `main()` instead
agriyakhetarpal 59a085d
tests: move command tests
henryiii 3e5a78c
Create cibuildwheel cache sentinel file
agriyakhetarpal 05b8a1d
Add sentinel to existing tests + add new test
agriyakhetarpal 8e0b65e
Merge branch 'main' into clean-cache-command
agriyakhetarpal 1a267b6
Add signature and switch to `CACHEDIR.TAG`
agriyakhetarpal 47e870b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] eb9f33a
Another instance to replace with `CACHEDIR.TAG`
agriyakhetarpal 698c5f7
Verify `CACHEDIR.TAG` signature
agriyakhetarpal 8023c76
Simplify code branching and control flow
agriyakhetarpal eced162
Add test
agriyakhetarpal a571ca7
Add link to `CACHEDIR.TAG` specification
agriyakhetarpal 7e8695c
Write with UTF-8 encoding
agriyakhetarpal 18f8bc6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import errno | ||
import shutil | ||
import sys | ||
|
||
import pytest | ||
|
||
import cibuildwheel.__main__ as main_module | ||
from cibuildwheel.__main__ import main | ||
|
||
|
||
def test_clean_cache_when_cache_exists(tmp_path, monkeypatch, capfd): | ||
fake_cache_dir = (tmp_path / "cibw_cache").resolve() | ||
monkeypatch.setattr(main_module, "CIBW_CACHE_PATH", fake_cache_dir) | ||
|
||
fake_cache_dir.mkdir(parents=True, exist_ok=True) | ||
assert fake_cache_dir.exists() | ||
|
||
cibw_sentinel = fake_cache_dir / ".cibuildwheel_cached" | ||
cibw_sentinel.write_text("# Created by cibuildwheel automatically", encoding="utf-8") | ||
agriyakhetarpal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
dummy_file = fake_cache_dir / "dummy.txt" | ||
dummy_file.write_text("hello") | ||
|
||
monkeypatch.setattr(sys, "argv", ["cibuildwheel", "--clean-cache"]) | ||
|
||
with pytest.raises(SystemExit) as e: | ||
main() | ||
|
||
assert e.value.code == 0 | ||
|
||
out, err = capfd.readouterr() | ||
assert f"Clearing cache directory: {fake_cache_dir}" in out | ||
assert "Cache cleared successfully." in out | ||
assert not fake_cache_dir.exists() | ||
|
||
|
||
def test_clean_cache_when_cache_does_not_exist(tmp_path, monkeypatch, capfd): | ||
fake_cache_dir = (tmp_path / "nonexistent_cache").resolve() | ||
monkeypatch.setattr(main_module, "CIBW_CACHE_PATH", fake_cache_dir) | ||
|
||
monkeypatch.setattr(sys, "argv", ["cibuildwheel", "--clean-cache"]) | ||
|
||
with pytest.raises(SystemExit) as e: | ||
main() | ||
|
||
assert e.value.code == 0 | ||
|
||
out, err = capfd.readouterr() | ||
assert f"Cache directory does not exist: {fake_cache_dir}" in out | ||
|
||
|
||
def test_clean_cache_with_error(tmp_path, monkeypatch, capfd): | ||
fake_cache_dir = (tmp_path / "cibw_cache").resolve() | ||
monkeypatch.setattr(main_module, "CIBW_CACHE_PATH", fake_cache_dir) | ||
|
||
fake_cache_dir.mkdir(parents=True, exist_ok=True) | ||
assert fake_cache_dir.exists() | ||
|
||
cibw_sentinel = fake_cache_dir / ".cibuildwheel_cached" | ||
cibw_sentinel.write_text("# Created by cibuildwheel automatically\n") | ||
agriyakhetarpal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
monkeypatch.setattr(sys, "argv", ["cibuildwheel", "--clean-cache"]) | ||
|
||
def fake_rmtree(path): # noqa: ARG001 | ||
raise OSError(errno.EACCES, "Permission denied") | ||
|
||
monkeypatch.setattr(shutil, "rmtree", fake_rmtree) | ||
|
||
with pytest.raises(SystemExit) as e: | ||
main() | ||
|
||
assert e.value.code == 1 | ||
|
||
out, err = capfd.readouterr() | ||
assert f"Clearing cache directory: {fake_cache_dir}" in out | ||
assert "Error clearing cache:" in err | ||
|
||
|
||
def test_clean_cache_without_sentinel(tmp_path, monkeypatch, capfd): | ||
fake_cache_dir = (tmp_path / "not_a_cache").resolve() | ||
monkeypatch.setattr(main_module, "CIBW_CACHE_PATH", fake_cache_dir) | ||
|
||
fake_cache_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
monkeypatch.setattr(sys, "argv", ["cibuildwheel", "--clean-cache"]) | ||
|
||
with pytest.raises(SystemExit) as e: | ||
main() | ||
|
||
assert e.value.code == 1 | ||
|
||
out, err = capfd.readouterr() | ||
assert "does not appear to be a cibuildwheel cache directory" in err | ||
assert fake_cache_dir.exists() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.