1- import re
21import subprocess
32import sys
43from pathlib import Path
54
65import click
6+ import tomllib
77
88from bolt .cli .print import print_event
99
@@ -20,11 +20,10 @@ def cli():
2020@click .argument ("path" , default = "." )
2121def check (path ):
2222 """Check the given path for formatting or linting issues."""
23- ruff_args = []
23+ ruff_args = ["--config" , str ( DEFAULT_RUFF_CONFIG ) ]
2424
25- if not user_has_ruff_config ():
26- click .secho ("Using default bolt.code ruff config" , italic = True )
27- ruff_args .extend (["--config" , str (DEFAULT_RUFF_CONFIG )])
25+ for e in get_code_config ().get ("exclude" , []):
26+ ruff_args .extend (["--exclude" , e ])
2827
2928 print_event ("Ruff check" )
3029 result = subprocess .run (["ruff" , "check" , path , * ruff_args ])
@@ -43,11 +42,10 @@ def check(path):
4342@click .argument ("path" , default = "." )
4443def fix (path ):
4544 """Lint and format the given path."""
46- ruff_args = []
45+ ruff_args = ["--config" , str ( DEFAULT_RUFF_CONFIG ) ]
4746
48- if not user_has_ruff_config ():
49- click .secho ("Using default bolt.code ruff config" , italic = True )
50- ruff_args .extend (["--config" , str (DEFAULT_RUFF_CONFIG )])
47+ for e in get_code_config ().get ("exclude" , []):
48+ ruff_args .extend (["--exclude" , e ])
5149
5250 print_event ("Ruff check" )
5351 result = subprocess .run (["ruff" , "check" , path , "--fix" , * ruff_args ])
@@ -62,13 +60,9 @@ def fix(path):
6260 sys .exit (result .returncode )
6361
6462
65- def user_has_ruff_config ():
66- try :
67- output = subprocess .check_output (["ruff" , "check" , "." , "--show-settings" ])
68- except subprocess .CalledProcessError :
69- return False
70-
71- if re .search ("Settings path: (.+)" , output .decode ("utf-8" )):
72- return True
73- else :
74- return False
63+ def get_code_config ():
64+ pyproject = Path ("pyproject.toml" )
65+ if not pyproject .exists ():
66+ return {}
67+ with pyproject .open ("rb" ) as f :
68+ return tomllib .load (f ).get ("tool" , {}).get ("bolt" , {}).get ("code" , {})
0 commit comments