Add a read-only context manager for YAML files to prevent round-trip …#1047
Conversation
CodSpeed Performance ReportMerging #1047 will improve performances by 13.47%Comparing Summary
Benchmarks breakdown
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull Request Overview
This PR introduces read-only context managers for YAML configuration files to prevent unintended modifications during read operations. The key motivation is to avoid round-trip failures where simply reading a YAML file could inadvertently alter its formatting (particularly quote styles).
Key Changes:
- Added
read_yaml()context manager that reads YAML files without writing changes back - Refactored
edit_yaml()to useread_yaml()internally, maintaining backward compatibility - Created read-only wrappers
read_pre_commit_config_yaml()andread_bitbucket_pipelines_yaml()for specific config files
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/usethis/integrations/file/yaml/io.py | Extracted read logic into new read_yaml() context manager; edit_yaml() now delegates to it |
| src/usethis/integrations/pre_commit/io.py | Added read_pre_commit_config_yaml() context manager for read-only access |
| src/usethis/integrations/ci/bitbucket/io.py | Added read_bitbucket_pipelines_yaml() context manager for read-only access |
| src/usethis/_integrations/pre_commit/hooks.py | Updated get_hook_ids() to use read-only context manager instead of edit mode |
| src/usethis/_integrations/ci/bitbucket/steps.py | Updated get_steps_in_default() to use read-only context manager instead of edit mode |
| src/usethis/_integrations/ci/bitbucket/cache.py | Updated get_cache_by_name() to use read-only context manager instead of edit mode |
| tests/usethis/integrations/pre_commit/test_pre_commit_io.py | Added test verifying quote style preservation with read-only context manager |
| tests/usethis/integrations/ci/bitbucket/test_bitbucket_io.py | Added test verifying quote style preservation with read-only context manager |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…failures