tconbeer / sqlfmt

sqlfmt formats your dbt SQL files so you don't have to
https://sqlfmt.com
Apache License 2.0
391 stars 16 forks source link

Exclude config in pyproject.toml stopped working in 0.18.3 #431

Closed cmcnicoll closed 1 year ago

cmcnicoll commented 1 year ago

Describe the bug Upgraded to 0.18.3 and ran sqlfmt -k ., which ignored the exclude config. Reverted to 0.18.1 and exclude config works again. Do I have to update my pyproject.toml?

To Reproduce I'm using Windows 11 Pro, Visual Studio Code, venv, powershell terminal.

[tool.sqlfmt]
exclude = [
    "dbt/.dbtenv/**/*",
    "dbt/dbt_packages/**/*",
    "dbt/macros/marts/**/*",
    "dbt/macros/staging/**/*",
    "dbt/macros/util/**/*",
    "dbt/snapshots/**/*",
    "dbt/target/**/*",
    "dbt/tests/generic/**/*",
    "etc/**/*",
    "lib/**/*",
    "sql/**/*",
    "src/**/*",
    "tests/**/*"
]

Additional context What is the output of sqlfmt --version? sqlfmt, version 0.18.3

tconbeer commented 1 year ago

There was a change in that version with making paths absolute.

Can you add a "./" before your paths and see if that fixes the issue for you?

cmcnicoll commented 1 year ago

That didn't work for me. I also can't get the --exclude option to work: sqlfmt . --check --exclude ./dbt/target/**/*.

tconbeer commented 1 year ago

ok, thanks!

tconbeer commented 1 year ago

related to #427

tconbeer commented 1 year ago

@cmcnicoll Would love it if you could give v0.19.0 a spin -- I'm pretty sure it'll fix your issue but I didn't have a perfect repro on my machine, so I'm not 100% sure.

cmcnicoll commented 1 year ago

My exclude config in pyproject.toml is working again as-is. Thanks!

sqlfmt . --check -k -q               
1 file failed formatting check.
176 files passed formatting check.

However, I still can't get the --exclude option to work.

sqlfmt . --check -k -q --exclude ./dbt/**/* --exclude ./sql/**/*
192 files had errors while formatting.
1681 files failed formatting check.
1234 files passed formatting check.
tconbeer commented 1 year ago

Depending on your she'll, you might have to quote those paths?

cmcnicoll commented 1 year ago

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
tconbeer commented 1 year ago

I can repro on Powershell, I'm going to create a new issue for this