gritql
gritql copied to clipboard
Look for `.grit` patterns anywhere when running `grit patterns test`
We don't want to require them to be at the root.
Importantly, this is a hard requirement if we want to piggyback on distribution from Poetry or PyPi. Trying to include .grit file from a parent dir into a subpackage yields this error:
'/Users/morgante/code/grit/demos/langchain/.grit/grit.yaml' is not in the subpath of '/Users/morgante/code/grit/demos/langchain/libs/cli' OR one path is relative and the other is absolute.
I have tried the following commands, expecting them to recognise my desire to have patterns defined outside of .grit/patterns. But none seem to work.
Set up:
- Create a new pattern called
test_pattern.mdin a directory called./grittestat the root of my repository.
Here are the commands I've tried and their error messages:
% grit apply test_pattern --dry-run --grit-dir=./grittest test.ts
ERROR (code: 200) - pattern definition not found: test_pattern. Try running grit init.
% grit apply test_pattern.md --dry-run --grit-dir=./grittest test.ts
ERROR (code: 200) - pattern definition not found: test_pattern.md. Try running grit init.
% grit --grit-dir=./grittest apply test_pattern --dry-run test.ts
ERROR (code: 200) - pattern definition not found: test_pattern. Try running grit init.
% grit patterns test --grit-dir=./grittest
Error: No testable patterns found. To test a pattern, make sure it is defined in .grit/grit.yaml or a .md file in your .grit/patterns directory.
% grit --grit-dir=./grittest patterns test
Error: No testable patterns found. To test a pattern, make sure it is defined in .grit/grit.yaml or a .md file in your .grit/patterns directory.
From the help commands I would have expected this to work.
grit patterns test --help
Test patterns against expected output
Usage: grit patterns test [OPTIONS]
Options:
--filter <FILTER> Regex of a specific pattern to test
--exclude <EXCLUDE> Tags and pattern names to exclude. Only direct matches will be excluded.
--verbose Show verbose output
--update Update expected test outputs
--watch Enable watch mode on .grit dir
--json Enable JSON output, only supported on some commands
--jsonl Enable JSONL output, only supported on some commands
--log-level <LOG_LEVEL> Override the default log level (info)
--grit-dir <GRIT_DIR> Override the default .grit directory location
-h, --help Print help
What's your reason for not wanting to use the .grit/patterns directory?
In a large repository, where we may want to co-locate codemods within certain packages or sub-modules of the repository. Alternatively the codemods may be built and packaged in a separate repository, so that they may be applied to many repositories instead of just one.
Just to be clear, grit apply can work with patterns anywhere.
grit apply /path/to/pattern.grit test.ts