-
Notifications
You must be signed in to change notification settings - Fork 8
ENH: Cache schemas for taplo lint #29
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
serl
wants to merge
2
commits into
ComPWA:main
Choose a base branch
from
serl:cached-schemas
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
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| *.egg-info |
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,22 @@ | ||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| cache_path = Path(sys.prefix) / "taplo-cache" | ||
|
|
||
|
|
||
| def main(): | ||
| args = sys.argv[1:] | ||
|
|
||
| if not any( | ||
| arg == "--cache-path" or arg.startswith("--cache-path=") for arg in args | ||
| ): | ||
| cache_path.mkdir(parents=True, exist_ok=True) | ||
| args.extend(["--cache-path", str(cache_path)]) | ||
|
|
||
| proc = subprocess.run(["taplo", "lint", *args]) | ||
| sys.exit(proc.returncode) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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,98 @@ | ||
| import unittest | ||
| from unittest import mock | ||
|
|
||
| import cached_taplo_lint | ||
|
|
||
|
|
||
| @mock.patch("subprocess.run") | ||
| class TestCachedTaploLint(unittest.TestCase): | ||
| def test_success(self, mock_run: mock.Mock): | ||
| mock_run.return_value.returncode = 0 | ||
|
|
||
| try: | ||
| cached_taplo_lint.main() | ||
| except SystemExit as e: | ||
| self.assertEqual(e.code, 0) | ||
|
|
||
| mock_run.assert_called() | ||
|
|
||
| def test_failure(self, mock_run: mock.Mock): | ||
| mock_run.return_value.returncode = 1 | ||
|
|
||
| with self.assertRaises(SystemExit) as cm: | ||
| cached_taplo_lint.main() | ||
| self.assertNotEqual(cm.exception.code, 0) | ||
|
|
||
| mock_run.assert_called() | ||
|
|
||
| def test_add_cache_argument(self, mock_run: mock.Mock): | ||
| mock_run.return_value.returncode = 0 | ||
|
|
||
| test_args = ["cached-taplo-lint", "--foo", "bar"] | ||
| with mock.patch("sys.argv", test_args): | ||
| try: | ||
| cached_taplo_lint.main() | ||
| except SystemExit as e: | ||
| self.assertEqual(e.code, 0) | ||
|
|
||
| called_args = mock_run.call_args[0][0] | ||
| self.assertEqual( | ||
| called_args, | ||
| [ | ||
| "taplo", | ||
| "lint", | ||
| "--foo", | ||
| "bar", | ||
| "--cache-path", | ||
| mock.ANY, | ||
| ], | ||
| ) | ||
|
|
||
| def test_keep_cache_argument(self, mock_run: mock.Mock): | ||
| mock_run.return_value.returncode = 0 | ||
|
|
||
| test_args = ["cached-taplo-lint", "--foo", "bar", "--cache-path", "/tmp/cache"] | ||
| with mock.patch("sys.argv", test_args): | ||
| try: | ||
| cached_taplo_lint.main() | ||
| except SystemExit as e: | ||
| self.assertEqual(e.code, 0) | ||
|
|
||
| called_args = mock_run.call_args[0][0] | ||
| self.assertEqual( | ||
| called_args, | ||
| [ | ||
| "taplo", | ||
| "lint", | ||
| "--foo", | ||
| "bar", | ||
| "--cache-path", | ||
| "/tmp/cache", | ||
| ], | ||
| ) | ||
|
|
||
| def test_keep_cache_argument_with_equals(self, mock_run: mock.Mock): | ||
| mock_run.return_value.returncode = 0 | ||
|
|
||
| test_args = ["cached-taplo-lint", "--foo", "bar", "--cache-path=/tmp/cache"] | ||
| with mock.patch("sys.argv", test_args): | ||
| try: | ||
| cached_taplo_lint.main() | ||
| except SystemExit as e: | ||
| self.assertEqual(e.code, 0) | ||
|
|
||
| called_args = mock_run.call_args[0][0] | ||
| self.assertEqual( | ||
| called_args, | ||
| [ | ||
| "taplo", | ||
| "lint", | ||
| "--foo", | ||
| "bar", | ||
| "--cache-path=/tmp/cache", | ||
| ], | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better to have a separate hook? I don't want to temper with the default behaviour of
taplo-lint.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand your concern, but I'd still "shadow" the original hook:
pre-commit autoupdateseems the best we can do.--cache-path somethingshouldn't be impacted, since the wrapper takes this case into account (and does nothing when it's the case).Sure things could break in other ways:
taplo lintchanging the caching behaviorOf course you have the last word.