-
Notifications
You must be signed in to change notification settings - Fork 440
ci: native extension hash cache #13675
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
Open
P403n1x87
wants to merge
9
commits into
main
Choose a base branch
from
ci/ext-hash-cache
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c2cc5b1
ci: native extension hash cache
P403n1x87 475f53f
use a single cache with multiplexing
P403n1x87 4026777
cache downloads and refresh caches monthly
P403n1x87 bd27a46
add cache operations logging
P403n1x87 f6b4c86
generate cache operations in place
P403n1x87 e3c9e56
add dependencies
P403n1x87 74a8c35
fix cache operations generation
P403n1x87 baffc5f
clean-up
P403n1x87 7ea29ec
Merge remote-tracking branch 'origin/main' into ci/ext-hash-cache
P403n1x87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from pathlib import Path | ||
import subprocess | ||
import sys | ||
import typing as t | ||
|
||
|
||
HERE = Path(__file__).resolve().parent | ||
ROOT = HERE.parent | ||
CACHE = ROOT / ".ext_cache" | ||
RESTORE_FILE = HERE / "restore-ext-cache.sh" | ||
SAVE_FILE = HERE / "save-ext-cache.sh" | ||
|
||
# Get extension information from setup.py | ||
output = subprocess.check_output([sys.executable, ROOT / "setup.py", "ext_hashes", "--inplace"]) | ||
cached_files = set() | ||
for line in output.decode().splitlines(): | ||
if not line.startswith("#EXTHASH:"): | ||
continue | ||
ext_name, ext_hash, ext_target = t.cast(t.Tuple[str, str, str], eval(line.split(":", 1)[-1].strip())) | ||
target = Path(ext_target) | ||
cache_dir = CACHE / ext_name / ext_hash | ||
if ext_target.endswith("*"): | ||
target_dir = target.parent.resolve() | ||
if RESTORE_FILE.exists(): | ||
# Iterate over the target as these are the files we want to cache | ||
for d in target_dir.glob(target.name): | ||
if d.is_file(): | ||
cached_files.add((str(cache_dir / d.name), str(d.resolve()))) | ||
else: | ||
# Iterate over the cached files as these are the ones we want to | ||
# restore | ||
for d in cache_dir.glob(target.name): | ||
if d.is_file(): | ||
cached_files.add((str(d.resolve()), str(target_dir / d.name))) | ||
else: | ||
cached_files.add((str(cache_dir / target.name), ext_target)) | ||
|
||
# Generate the restore script on the first run | ||
if not RESTORE_FILE.exists(): | ||
RESTORE_FILE.write_text( | ||
"\n".join( | ||
[ | ||
f" test -f {cached_file} && (cp {cached_file} {dest} && touch {dest} " | ||
f"&& echo 'Restored {cached_file} -> {dest}') || true" | ||
for cached_file, dest in cached_files | ||
] | ||
) | ||
) | ||
else: | ||
# Generate the save script on the second run | ||
SAVE_FILE.write_text( | ||
"\n".join( | ||
[ | ||
f" test -f {cached_file} || mkdir -p {Path(cached_file).parent} && (cp {dest} {cached_file} " | ||
f"&& echo 'Saved {dest} -> {cached_file}' || true)" | ||
for cached_file, dest in cached_files | ||
] | ||
) | ||
) |
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 was deleted.
Oops, something went wrong.
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
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.