Skip to content

Commit

Permalink
Always use specific config in bolt-code
Browse files Browse the repository at this point in the history
  • Loading branch information
davegaeddert committed Feb 6, 2024
1 parent e631688 commit 37500a3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
32 changes: 13 additions & 19 deletions bolt-code/bolt/code/cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import re
import subprocess
import sys
from pathlib import Path

import click
import tomllib

from bolt.cli.print import print_event

Expand All @@ -20,11 +20,10 @@ def cli():
@click.argument("path", default=".")
def check(path):
"""Check the given path for formatting or linting issues."""
ruff_args = []
ruff_args = ["--config", str(DEFAULT_RUFF_CONFIG)]

if not user_has_ruff_config():
click.secho("Using default bolt.code ruff config", italic=True)
ruff_args.extend(["--config", str(DEFAULT_RUFF_CONFIG)])
for e in get_code_config().get("exclude", []):
ruff_args.extend(["--exclude", e])

print_event("Ruff check")
result = subprocess.run(["ruff", "check", path, *ruff_args])
Expand All @@ -43,11 +42,10 @@ def check(path):
@click.argument("path", default=".")
def fix(path):
"""Lint and format the given path."""
ruff_args = []
ruff_args = ["--config", str(DEFAULT_RUFF_CONFIG)]

if not user_has_ruff_config():
click.secho("Using default bolt.code ruff config", italic=True)
ruff_args.extend(["--config", str(DEFAULT_RUFF_CONFIG)])
for e in get_code_config().get("exclude", []):
ruff_args.extend(["--exclude", e])

print_event("Ruff check")
result = subprocess.run(["ruff", "check", path, "--fix", *ruff_args])
Expand All @@ -62,13 +60,9 @@ def fix(path):
sys.exit(result.returncode)


def user_has_ruff_config():
try:
output = subprocess.check_output(["ruff", "check", ".", "--show-settings"])
except subprocess.CalledProcessError:
return False

if re.search("Settings path: (.+)", output.decode("utf-8")):
return True
else:
return False
def get_code_config():
pyproject = Path("pyproject.toml")
if not pyproject.exists():
return {}
with pyproject.open("rb") as f:
return tomllib.load(f).get("tool", {}).get("bolt", {}).get("code", {})
1 change: 1 addition & 0 deletions bolt-code/bolt/code/ruff_defaults.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target-version = "py310"
ignore = [
"E501", # Never enforce `E501` (line length violations)
"S101", # pytest use of assert
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ build-backend = "poetry.core.masonry.api"
extend = "bolt-code/bolt/code/ruff_defaults.toml"
target-version = "py310"
extend-exclude = ["bolt-pytest/bolt/pytest/pytest"]

[tool.bolt.code]
exclude = ["bolt-pytest/bolt/pytest/pytest"]

0 comments on commit 37500a3

Please sign in to comment.