Repository navigation
Conversation
📝 WalkthroughWalkthroughThis PR implements a time-based cache validity window for URL-downloaded model weights. A 24-hour TTL constant is added, and ChangesURL weight cache TTL validation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #653 +/- ##
==========================================
+ Coverage 95.47% 95.48% +0.01%
==========================================
Files 14 14
Lines 1656 1660 +4
==========================================
+ Hits 1581 1585 +4
Misses 75 75 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/unit_tests/test_unit.py`:
- Around line 803-808: The code computes stale_time using a naive datetime via
datetime.datetime.now().timestamp(); change this to use a timezone-aware UTC
datetime for consistency (e.g., use
datetime.datetime.now(datetime.timezone.utc).timestamp() or
.astimezone(datetime.timezone.utc).timestamp()) when calculating stale_time for
os.utime on cache_file_path so it matches the timezone-aware usage elsewhere and
keeps behavior consistent with casanovo._URL_WEIGHTS_CACHE_TTL_SECONDS.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 3849d724-aee9-4903-a649-6937369c74b7
📒 Files selected for processing (2)
casanovo/casanovo.pytests/unit_tests/test_unit.py
| stale_time = ( | ||
| datetime.datetime.now().timestamp() | ||
| - casanovo._URL_WEIGHTS_CACHE_TTL_SECONDS | ||
| - 1 | ||
| ) | ||
| os.utime(cache_file_path, (stale_time, stale_time)) |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial | 💤 Low value
Consider using timezone-aware datetime for consistency.
Line 804 uses datetime.datetime.now().timestamp() without a timezone argument, while line 803 uses .astimezone(datetime.timezone.utc) for timezone awareness. Although .timestamp() converts to UTC internally and the code works correctly, using timezone-aware datetimes consistently throughout improves code clarity and follows best practices.
♻️ Proposed fix for timezone consistency
- stale_time = (
- datetime.datetime.now().timestamp()
- - casanovo._URL_WEIGHTS_CACHE_TTL_SECONDS
- - 1
- )
+ stale_time = (
+ datetime.datetime.now(datetime.timezone.utc).timestamp()
+ - casanovo._URL_WEIGHTS_CACHE_TTL_SECONDS
+ - 1
+ )📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| stale_time = ( | |
| datetime.datetime.now().timestamp() | |
| - casanovo._URL_WEIGHTS_CACHE_TTL_SECONDS | |
| - 1 | |
| ) | |
| os.utime(cache_file_path, (stale_time, stale_time)) | |
| stale_time = ( | |
| datetime.datetime.now(datetime.timezone.utc).timestamp() | |
| - casanovo._URL_WEIGHTS_CACHE_TTL_SECONDS | |
| - 1 | |
| ) | |
| os.utime(cache_file_path, (stale_time, stale_time)) |
🧰 Tools
🪛 Ruff (0.15.15)
[warning] 804-804: datetime.datetime.now() called without a tz argument
(DTZ005)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/unit_tests/test_unit.py` around lines 803 - 808, The code computes
stale_time using a naive datetime via datetime.datetime.now().timestamp();
change this to use a timezone-aware UTC datetime for consistency (e.g., use
datetime.datetime.now(datetime.timezone.utc).timestamp() or
.astimezone(datetime.timezone.utc).timestamp()) when calculating stale_time for
os.utime on cache_file_path so it matches the timezone-aware usage elsewhere and
keeps behavior consistent with casanovo._URL_WEIGHTS_CACHE_TTL_SECONDS.
|
As mentioned before, please follow our contributing guidelines. One important aspect that's mentioned there is that new contributions should be submitted against |
Problem
Closes #616.
_get_weights_from_url()made aHEADrequest every time a URL-backed model file already existed in the cache. That meant repeat invocations still depended on network latency and remote availability even when the local cache had just been populated.Before / after
Before:
HEADrequest first.After:
HEADrequest.HEAD/Last-Modifiedfreshness check before deciding whether to re-download.force_download=Truestill bypasses the cache.Verification
python -m pytest tests/unit_tests/test_unit.py -k get_weights_from_urlpython -m ruff check --extend-ignore E402 casanovo/casanovo.py tests/unit_tests/test_unit.pygit diff --checkSummary by CodeRabbit
New Features
Tests