-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d150fab
commit fad6c58
Showing
5 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Local development files | ||
/.env | ||
/.bolt | ||
*.sqlite3 | ||
|
||
# Publishing | ||
/dist | ||
|
||
# Python | ||
/.venv | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# OS files | ||
.DS_Store |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import re | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
|
||
import click | ||
|
||
DEFAULT_RUFF_CONFIG = Path(__file__).parent / "ruff_defaults.toml" | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
"""Standard code formatting and linting.""" | ||
pass | ||
|
||
|
||
@cli.command() | ||
@click.argument("path", default=".") | ||
@click.option("--fix/--no-fix", "do_fix", default=False) | ||
def lint(path, do_fix): | ||
ruff_args = [] | ||
|
||
if not user_has_ruff_config(): | ||
click.secho("Using default bolt.code ruff config", italic=True, bold=True) | ||
ruff_args.extend(["--config", str(DEFAULT_RUFF_CONFIG)]) | ||
|
||
if do_fix: | ||
ruff_args.append("--fix") | ||
|
||
click.secho("Ruff check", bold=True) | ||
result = subprocess.run(["ruff", "check", path, *ruff_args]) | ||
|
||
if result.returncode != 0: | ||
sys.exit(result.returncode) | ||
|
||
|
||
@cli.command() | ||
@click.argument("path", default=".") | ||
def format(path): | ||
ruff_args = [] | ||
|
||
if not user_has_ruff_config(): | ||
click.secho("Using default bolt.code ruff config", italic=True, bold=True) | ||
ruff_args.extend(["--config", str(DEFAULT_RUFF_CONFIG)]) | ||
|
||
click.secho("Ruff format", bold=True) | ||
result = subprocess.run(["ruff", "format", path, *ruff_args]) | ||
|
||
if result.returncode != 0: | ||
sys.exit(result.returncode) | ||
|
||
|
||
@cli.command() | ||
@click.argument("path", default=".") | ||
def fix(path): | ||
"""Lint and format the given path.""" | ||
ruff_args = [] | ||
|
||
if not user_has_ruff_config(): | ||
click.secho("Using default bolt.code ruff config", italic=True, bold=True) | ||
ruff_args.extend(["--config", str(DEFAULT_RUFF_CONFIG)]) | ||
|
||
click.secho("Ruff check", bold=True) | ||
result = subprocess.run(["ruff", "check", path, "--fix", *ruff_args]) | ||
|
||
if result.returncode != 0: | ||
sys.exit(result.returncode) | ||
|
||
click.secho("Ruff format", bold=True) | ||
result = subprocess.run(["ruff", "format", path, *ruff_args]) | ||
|
||
if result.returncode != 0: | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
ignore = [ | ||
"E501", # Never enforce `E501` (line length violations) | ||
"S101", # pytest use of assert | ||
"ISC001", # Implicit string concatenation | ||
] | ||
extend-select = [ | ||
"I", # isort | ||
# # "C90", # mccabe | ||
# # "N", # pep8-naming | ||
"UP", # pyupgrade | ||
# "S", # bandit | ||
# # "B", # bugbear | ||
"C4", # flake8-comprehensions | ||
# # "DTZ", # flake8-datetimez | ||
"ISC", # flake8-implicit-str-concat | ||
# # "G", # flake8-logging-format | ||
# # "T20", # print | ||
"PT", # pytest | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[tool.poetry] | ||
name = "bolt-code" | ||
packages = [ | ||
{ include = "bolt" }, | ||
] | ||
|
||
version = "0.1.0" | ||
description = "" | ||
authors = ["Dave Gaeddert <dave.gaeddert@dropseed.dev>"] | ||
|
||
# Make the CLI available without adding to INSTALLED_APPS | ||
[tool.poetry.plugins."bolt.cli"] | ||
"code" = "bolt.code:cli" | ||
"fix" = "bolt.code.cli:fix" | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.8" | ||
ruff = "^0.1.0" | ||
|
||
[tool.poetry.dev-dependencies] | ||
pytest = "^7.1.2" | ||
ipdb = "^0.13.9" | ||
isort = "^5.10.1" | ||
black = "^23.1.0" | ||
pytest-django = "^4.5.2" | ||
|
||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend = "poetry.core.masonry.api" |