1
- import re
2
1
import subprocess
3
2
import sys
4
3
from pathlib import Path
5
4
6
5
import click
6
+ import tomllib
7
7
8
8
from bolt .cli .print import print_event
9
9
@@ -20,11 +20,10 @@ def cli():
20
20
@click .argument ("path" , default = "." )
21
21
def check (path ):
22
22
"""Check the given path for formatting or linting issues."""
23
- ruff_args = []
23
+ ruff_args = ["--config" , str ( DEFAULT_RUFF_CONFIG ) ]
24
24
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 ])
28
27
29
28
print_event ("Ruff check" )
30
29
result = subprocess .run (["ruff" , "check" , path , * ruff_args ])
@@ -43,11 +42,10 @@ def check(path):
43
42
@click .argument ("path" , default = "." )
44
43
def fix (path ):
45
44
"""Lint and format the given path."""
46
- ruff_args = []
45
+ ruff_args = ["--config" , str ( DEFAULT_RUFF_CONFIG ) ]
47
46
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 ])
51
49
52
50
print_event ("Ruff check" )
53
51
result = subprocess .run (["ruff" , "check" , path , "--fix" , * ruff_args ])
@@ -62,13 +60,9 @@ def fix(path):
62
60
sys .exit (result .returncode )
63
61
64
62
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