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
feat(globset): allow custom component separator characters? #2703
Comments
I'll think about this. You caught me at a good time because I am in the process of rewriting Here are some concerns though:
As I created that list, I'm afraid I've gotten more and more skeptical of functionality like this unfortunately.
Possibly unfortunate, but not necessarily. It really depends. I think it would be prudent to start here. And if it ends up being a perf concern, then I actually think the next best step would be to build your own pattern language specifically for this sort of thing. The part of |
Thank you for putting so much thought into this suggestion! For Ruff's use case, I think some of the optimizations But we'll see – if you don't think it's a great idea to allow custom separators (and I don't blame you!), I'll explore other ways of implementing this first (if I have the time and bandwidth, that is...). |
Aye. Ideally, we could push those optimizations down into the regex engine. It's in theory more amenable to such things than it was when I wrote I do think it would be wise to get a "macro" benchmark here. If real use cases are dominated by something other than filtering out Python paths, then it might not be worth optimizing it too much. |
Describe your feature request
As discussed on astral-sh/ruff#8403.
It could be useful if
globset
allowed a custom component separator character instead of the default/
or\
path separator, to make it possible to useglobset
for non-filename patterns such as Python qualified names.In other words, if (mildly mis)using the current
globset
as-is with{'foo.x.bar', 'foo.y.bar', 'foo.x.y.bar'}
as potential targets, bothfoo.*.bar
andfoo.**.bar
will match all of them; ifglobset
could be told to interpret.
as the separator character instead,foo.*.bar
wouldn't matchfoo.x.y.bar
(as it wouldn't match a filesystem pathfoo/x/y/bar
).One alternative, as discussed on the Ruff issue, is to pre-mangle the globset contents and the strings to be matched to replace dots with slashes, but that would entail additional allocation and copying at some point, which sounds unfortunate.
The text was updated successfully, but these errors were encountered: