gritql
gritql copied to clipboard
Allow for non-standard suffixes/filenames for languages
I have files that should be treated as python, but do not end in .py. I can't convince grit to respect the files and treat them as python with any option or config value that I've found. Instead, grit fails with:
ERROR (code: 410) - Skipped <mypath here> since it is not a python file
My workaround is hardlinking grit.yaml.
I think there's two immediate things we could do:
- Adjust this logic so that if the path of the file is directly specified (vs. being discovered via traversal) we always attempt to parse it.
- Add an
--extensionsflag to override which extensions are parsed at runtime.
Happy to review a PR.
I think option #1 is best.
/bounty $10
💎 $10 bounty • Grit
Steps to solve:
- Start working: Comment
/attempt #485with your implementation plan - Submit work: Create a pull request including
/claim #485in the PR body to claim the bounty - Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts
Thank you for contributing to getgrit/gritql!
Add a bounty • Share on socials
| Attempt | Started (GMT+0) | Solution |
|---|---|---|
| 🟢 @mobley-trent | Oct 24, 2024, 11:14:16 AM | WIP |
| 🟢 @Alex-ley-scrub | Oct 24, 2024, 10:46:04 PM | #562 |
/attempt #485
| Algora profile | Completed bounties | Tech | Active attempts | Options |
|---|---|---|---|---|
| @mobley-trent | 10 bounties from 5 projects | Python, Rust, Jupyter Notebook |
Cancel attempt |
/attempt #485
@dshahbaz what is the suffix of the file out of curiosity if you don't mind sharing?
It's not "pyi" by any chance is it? Or another (semi) valid/standard python extension? .pyi - Stub file (PEP 484)
I only ask because if it is .pyi I believe they are a true subset of .py files (they're just interface files with function signatues and type hints but no implementations, instead just have ... in the function bodies etc.) and should be able to be parsed just like a normal .py file.
@morgante should we consider to add "pyi" here (I've done that in this commit 63f113c in case the answer is yes, otherwise can revert):
https://github.com/getgrit/gritql/blob/a1b312bdefed4982f7a96304b88577762f7edcf1/crates/language/src/target_language.rs#L290
https://github.com/getgrit/gritql/blob/a1b312bdefed4982f7a96304b88577762f7edcf1/crates/language/src/target_language.rs#L346
This is my minimal reproducible example (added as a test case in this commit 9abf798):
These both fail for me using the released version of grit (with or without --force):
echo 'class MyClass(object): ...' > dummy.nopy
grit apply '`object` => ``' dummy.nopy --lang=python --force
# out: dummy.nopy: ERROR (code: 410) - Skipped dummy.nopy since it is not a python file
# out: Processed 2 files and found 0 matches
and
echo 'class MyClass(object): ...' > dummy.pyi
grit apply '`object` => ``' dummy.pyi --lang=python --force
# out: dummy.pyi: ERROR (code: 410) - Skipped dummy.pyi since it is not a python file
# out: Processed 2 files and found 0 matches
(as an aside the count of processed files seems to be doubled for the failed ones, which I also fixed in this commit ff3fafc)
see my PR attempt coming shortly
| Algora profile | Completed bounties | Tech | Active attempts | Options |
|---|---|---|---|---|
| @Alex-ley-scrub | 2 grit bounties | Rust |
Cancel attempt |
Adding .pyi seems reasonable, as well as fixing the overall problem.
/assign @Alex-ley-scrub
💡 @Alex-ley-scrub submitted a pull request that claims the bounty. You can visit your bounty board to reward.
Thank you! I haven't tried this yet.
In my use case I was attempting to use bazel BUILD files, which approximately python, at least in terms of syntax.