Skip to content

Commit 37500a3

Browse files
committed
Always use specific config in bolt-code
1 parent e631688 commit 37500a3

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

bolt-code/bolt/code/cli.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import re
21
import subprocess
32
import sys
43
from pathlib import Path
54

65
import click
6+
import tomllib
77

88
from bolt.cli.print import print_event
99

@@ -20,11 +20,10 @@ def cli():
2020
@click.argument("path", default=".")
2121
def 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=".")
4443
def 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", {})

bolt-code/bolt/code/ruff_defaults.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
target-version = "py310"
12
ignore = [
23
"E501", # Never enforce `E501` (line length violations)
34
"S101", # pytest use of assert

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ build-backend = "poetry.core.masonry.api"
3232
extend = "bolt-code/bolt/code/ruff_defaults.toml"
3333
target-version = "py310"
3434
extend-exclude = ["bolt-pytest/bolt/pytest/pytest"]
35+
36+
[tool.bolt.code]
37+
exclude = ["bolt-pytest/bolt/pytest/pytest"]

0 commit comments

Comments
 (0)