gritql icon indicating copy to clipboard operation
gritql copied to clipboard

Look for `.grit` patterns anywhere when running `grit patterns test`

Open morgante opened this issue 1 year ago • 5 comments

We don't want to require them to be at the root.

morgante avatar May 19 '24 08:05 morgante

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.

morgante avatar May 19 '24 08:05 morgante

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:

  1. Create a new pattern called test_pattern.md in a directory called ./grittest at 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

mtokar-atlassian avatar Mar 10 '25 02:03 mtokar-atlassian

What's your reason for not wanting to use the .grit/patterns directory?

morgante avatar Mar 10 '25 02:03 morgante

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.

mtokar-atlassian avatar Mar 10 '25 02:03 mtokar-atlassian

Just to be clear, grit apply can work with patterns anywhere.

grit apply /path/to/pattern.grit test.ts

morgante avatar Mar 12 '25 17:03 morgante