Skip to content

Commit b39e493

Browse files
committed
chore(autoformat): Change blue to ruff
1 parent a14914b commit b39e493

6 files changed

+53
-48
lines changed

.pre-commit-config.yaml

+6-25
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ repos:
99

1010
- repo: local
1111
hooks:
12-
- id: blue
13-
name: blue
14-
entry: blue
12+
- id: ruff-format
13+
name: ruff-format
14+
entry: ruff format
1515
exclude: |
1616
(?x)(
1717
docs
@@ -21,23 +21,15 @@ repos:
2121
types:
2222
- python
2323

24-
- id: ruff
25-
name: ruff
24+
- id: ruff-linter
25+
name: ruff-linter
2626
entry: ruff check
2727
language: system
2828
exclude: "docs/"
2929
pass_filenames: true
3030
types:
3131
- python
3232

33-
- id: isort
34-
name: isort
35-
entry: isort
36-
language: system
37-
pass_filenames: true
38-
types:
39-
- python
40-
4133
- id: mypy
4234
name: mypy
4335
entry: mypy
@@ -47,7 +39,6 @@ repos:
4739
types:
4840
- python
4941

50-
5142
- id: bandit
5243
name: bandit
5344
entry: bandit
@@ -59,20 +50,10 @@ repos:
5950

6051
- id: vulture
6152
name: vulture
62-
entry: vulture
53+
entry: vulture --min-confidence 80
6354
language: system
6455
files: "makim/"
6556
description: Find unused Python code.
6657
pass_filenames: true
6758
types:
6859
- python
69-
70-
- id: pydocstyle
71-
name: pydocstyle
72-
entry: pydocstyle
73-
exclude: ^$
74-
files: "makim/"
75-
language: system
76-
pass_filenames: true
77-
types:
78-
- python

makim/cli.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import argparse
33
import os
44
import sys
5+
56
from pathlib import Path
67

78
from makim import Makim, __version__

makim/makim.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,24 @@
1111
import sys
1212
import tempfile
1313
import warnings
14+
1415
from copy import deepcopy
1516
from pathlib import Path
1617
from typing import Dict, Optional, Tuple
1718

1819
import dotenv
1920
import sh
2021
import yaml # type: ignore
22+
2123
from colorama import Fore
2224
from jinja2 import Template
2325

2426
from makim.errors import MakimError
2527

28+
SCOPE_GLOBAL = 0
29+
SCOPE_GROUP = 1
30+
SCOPE_TARGET = 2
31+
2632

2733
def escape_template_tag(v: str) -> str:
2834
"""Escape template tag when processing the template config file."""
@@ -150,7 +156,7 @@ def _change_group_data(self, group_name=None):
150156
self.group_name = group_name
151157
shell_app_default = self.global_data.get('shell', 'xonsh')
152158
if self.group_name == 'default' and len(groups) == 1:
153-
group = list(groups)[0]
159+
group = next(iter(groups))
154160
self.group_data = groups[group]
155161

156162
shell_app = self.group_data.get('shell', shell_app_default)
@@ -174,8 +180,8 @@ def _load_config_data(self):
174180
with open(self.makim_file, 'r') as f:
175181
# escape template tags
176182
content = escape_template_tag(f.read())
177-
f = io.StringIO(content)
178-
self.global_data = yaml.safe_load(f)
183+
content_io = io.StringIO(content)
184+
self.global_data = yaml.safe_load(content_io)
179185

180186
def _load_shell_app(self, shell_app: str = ''):
181187
if not shell_app:
@@ -219,19 +225,19 @@ def _render_env_inplace(
219225
env = deepcopy(dict(os.environ))
220226
variables: dict = {}
221227

222-
if scope_id >= 0:
228+
if scope_id >= SCOPE_GLOBAL:
223229
env_user = self.global_data.get('env', {})
224230
env_file = self._load_dotenv(self.global_data)
225231
_render_env_inplace(env_user, env_file, variables, env)
226232
variables.update(self._load_scoped_vars('global', env=env))
227233

228-
if scope_id >= 1:
234+
if scope_id >= SCOPE_GROUP:
229235
env_user = self.group_data.get('env', {})
230236
env_file = self._load_dotenv(self.group_data)
231237
_render_env_inplace(env_user, env_file, variables, env)
232238
variables.update(self._load_scoped_vars('group', env=env))
233239

234-
if scope_id == 2:
240+
if scope_id == SCOPE_TARGET:
235241
env_user = self.target_data.get('env', {})
236242
env_file = self._load_dotenv(self.target_data)
237243
_render_env_inplace(env_user, env_file, variables, env)
@@ -247,21 +253,21 @@ def _load_scoped_vars(self, scope: str, env) -> dict:
247253

248254
variables = {}
249255

250-
if scope_id >= 0:
256+
if scope_id >= SCOPE_GLOBAL:
251257
variables.update(
252258
{
253259
k: v.strip()
254260
for k, v in self.global_data.get('vars', {}).items()
255261
}
256262
)
257-
if scope_id >= 1:
263+
if scope_id >= SCOPE_GROUP:
258264
variables.update(
259265
{
260266
k: v.strip()
261267
for k, v in self.group_data.get('vars', {}).items()
262268
}
263269
)
264-
if scope_id == 2:
270+
if scope_id == SCOPE_TARGET:
265271
variables.update(
266272
{
267273
k: v.strip()

pyproject.toml

+27-14
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ colorama = ">=0.4.6"
5151
[tool.poetry.group.dev.dependencies]
5252
containers-sugar = "1.9.0"
5353
pytest = ">=7"
54-
blue = ">=0.9.1"
55-
isort = ">=5"
5654
pre-commit = ">=3"
5755
mypy = ">=1"
5856
pytest-cov = ">=3.0.0"
@@ -63,10 +61,9 @@ mkdocs-literate-nav = ">=0.4.1"
6361
mkdocs-macros-plugin = ">=0.6.3"
6462
mkdocs-material = ">=8"
6563
mkdocstrings = {version=">=0.19.0", extras=["python"]}
66-
ruff = ">=0.0.278"
64+
ruff = ">=0.1.5"
6765
bandit = ">=1.7.5"
6866
vulture = ">=2.7"
69-
pydocstyle = ">=6.3.0"
7067
compose-go = ">=2.20.2"
7168

7269
[build-system]
@@ -78,24 +75,40 @@ testpaths = [
7875
"tests",
7976
]
8077

81-
[tool.blue]
82-
line-length = 79 # this is the default
83-
84-
[tool.isort]
85-
ensure_newline_before_comments = true
86-
line_length = 79
87-
multi_line_output = 3
88-
include_trailing_comma = true
89-
skip_glob = ["docs/*", "*.egg-info"]
90-
9178
[tool.mypy]
9279
ignore_missing_imports = true
9380

81+
9482
[tool.ruff]
9583
line-length = 79
84+
force-exclude = true
85+
src = ["./makim", "./tests"]
86+
ignore = ["RUF012"]
9687
exclude = [
9788
"docs",
9889
]
90+
select = [
91+
"E", # pycodestyle
92+
"F", # pyflakes
93+
"D", # pydocstyle
94+
"YTT", # flake8-2020
95+
"PL", # PL
96+
"RUF", # Ruff-specific rules
97+
"I001", # isort
98+
]
99+
# fixable = ["I001"]
100+
fix = true
101+
102+
[tool.ruff.pydocstyle]
103+
convention = "numpy"
104+
105+
[tool.ruff.isort]
106+
# Use a single line between direct and from import
107+
lines-between-types = 1
108+
109+
[tool.ruff.format]
110+
quote-style = "single"
111+
99112

100113
[tool.bandit]
101114
exclude_dirs = ["tests"]

tests/test_failure.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"""Tests for `makim` package."""
22
import os
33
import sys
4+
45
from pathlib import Path
56

67
import pytest
78

89
import makim
10+
911
from makim.errors import MakimError
1012

1113

@@ -18,6 +20,7 @@
1820
],
1921
)
2022
def test_failure(target, args, error_code):
23+
"""Test makim with expected failures."""
2124
makim_file = Path(__file__).parent / '.makim-unittest.yaml'
2225

2326
m = makim.Makim()

tests/test_success.py

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
],
2222
)
2323
def test_success(target, args):
24+
"""Test makim when expects success."""
2425
makim_file = Path(__file__).parent / '.makim-unittest.yaml'
2526

2627
m = makim.Makim()

0 commit comments

Comments
 (0)