sqlfmt
sqlfmt copied to clipboard
Command-line exclude option does not work on Windows
That didn't work for me. I tried `path`, `./path`, `.\path`, `"path"`, `"./path"`, `".\path"`.
The --exclude behavior is the same for bash and cmd except for one case, which threw an error:
(.dbtenv)
aaa@aaa MINGW64 /c/aaa-aaa/dbt/tests (aaa)
$ sqlfmt . --check -k -q --exclude .\integration_tests\**\*
Traceback (most recent call last):
File "C:\Users\aaa\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\aaa\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\users\aaa\.local\bin\sqlfmt.exe\__main__.py", line 7, in <module>
File "C:\Users\aaa\.local\pipx\venvs\shandy-sqlfmt\lib\site-packages\click\core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "C:\Users\aaa\.local\pipx\venvs\shandy-sqlfmt\lib\site-packages\click\core.py", line 1055, in main
rv = self.invoke(ctx)
File "C:\Users\aaa\.local\pipx\venvs\shandy-sqlfmt\lib\site-packages\click\core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\aaa\.local\pipx\venvs\shandy-sqlfmt\lib\site-packages\click\core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "C:\Users\aaa\.local\pipx\venvs\shandy-sqlfmt\lib\site-packages\click\decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "C:\Users\aaa\.local\pipx\venvs\shandy-sqlfmt\lib\site-packages\sqlfmt\cli.py", line 185, in sqlfmt
matched_files = api.get_matching_paths(files, mode=mode)
File "C:\Users\aaa\.local\pipx\venvs\shandy-sqlfmt\lib\site-packages\sqlfmt\api.py", line 105, in get_matching_paths
exclude_set.update(mode.exclude_root.glob(s))
File "C:\Users\aaa\AppData\Local\Programs\Python\Python310\lib\pathlib.py", line 1033, in glob
selector = _make_selector(tuple(pattern_parts), self._flavour)
File "C:\Users\aaa\AppData\Local\Programs\Python\Python310\lib\pathlib.py", line 374, in _make_selector
raise ValueError("Invalid pattern: '**' can only be an entire path component")
ValueError: Invalid pattern: '**' can only be an entire path component
Originally posted by @cmcnicoll in https://github.com/tconbeer/sqlfmt/issues/431#issuecomment-1590057746
glob.glob and Path.glob both match paths, whether you use forward or single or doubled backslashes. So there must be an issue either with the way that Click passes in these arguments or the way that we're comparing absolute paths on Windows.
This does not appear to be shell-specific, and it doesn't seem to matter if you quote the option or not.