exclude
option does not follow symlinks when generating exclude_set
for relative paths in Python <3.13
#457
Labels
bug
Something isn't working
Describe the bug
Given the following directory structure:
If we try to run
sqlfmt testdir --exclude "testdir/venv/**/*"
,testdir/venv/symlink/exclude_me.sql
will not be excluded, due to a known bug in Python <3.13 that preventspathlib.Path.glob()
from following symlinks in this code block:sqlfmt/src/sqlfmt/api.py
Lines 111 to 114 in abf9763
This is particularly a problem for directories containing Python virtual environments, where
lib64/
is often a symlink tolib/
and can contain third-party packages that should be excluded bysqlfmt
.To Reproduce
Create the above directory structure:
Run sqlfmt and try to exclude
testdir/venv/**/*
:Expected behavior
With the above directory structure, sqlfmt should follow the symlink and exclude
exclude_me.sql
:Actual behavior
sqlfmt includes
exclude_me.sql
:Additional context
I'm not totally sure what the right way to handle this is, given that the underlying
Path.glob()
bug will be fixed in the upcoming Python 3.13 release. It seems like the choice that would support a wider range of versions would be to replace thePath.glob()
call with a relativeglob.glob()
call, which seems to be a common workaround, but I don't know how high priority it is to support this behavior. If you agree with switching toglob.glob()
, I'd be happy to put up a patch!The text was updated successfully, but these errors were encountered: