Skip to content

Commit 8b42e07

Browse files
committed
update ruff settings
1 parent eb5f23c commit 8b42e07

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+492
-667
lines changed

examples/demo.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,9 @@ def main(args):
1515
tb.init(args.org, args.project, args.key)
1616
actions = []
1717
if args.email:
18-
actions = [
19-
tb.Action(
20-
"*/10%,success,error", integration=EmailIntegration(to=args.email)
21-
)
22-
]
18+
actions = [tb.Action("*/10%,success,error", integration=EmailIntegration(to=args.email))]
2319

24-
task = tb.Task.create(
25-
args.task_name, data={"host": os.uname().nodename}, actions=actions
26-
)
20+
task = tb.Task.create(args.task_name, data={"host": os.uname().nodename}, actions=actions)
2721

2822
context = prepare_migration()
2923

@@ -47,12 +41,8 @@ def perform_migration(context, task: tb.Task):
4741
if __name__ == "__main__":
4842
parser = argparse.ArgumentParser("Demo database migration")
4943
parser.add_argument("task_name")
50-
parser.add_argument(
51-
"-o", "--org", required=True, help="Taskbadger Organization slug"
52-
)
53-
parser.add_argument(
54-
"-p", "--project", required=True, help="Taskbadger Project slug"
55-
)
44+
parser.add_argument("-o", "--org", required=True, help="Taskbadger Organization slug")
45+
parser.add_argument("-p", "--project", required=True, help="Taskbadger Project slug")
5646
parser.add_argument("-k", "--key", required=True, help="Taskbadger API Key")
5747
parser.add_argument("-e", "--email")
5848
args = parser.parse_args()

integration_tests/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,4 @@ def _load_config():
3333
os.environ.get("TASKBADGER_API_KEY", ""),
3434
systems=[CelerySystemIntegration()],
3535
)
36-
print(
37-
f"\nIntegration tests configuration:\n {badger.mug.Badger.current.settings}\n"
38-
)
36+
print(f"\nIntegration tests configuration:\n {badger.mug.Badger.current.settings}\n")

integration_tests/tasks.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,5 @@ def add(self, x, y):
1212

1313
@shared_task(bind=True)
1414
def add_auto_track(self, x, y):
15-
assert (
16-
self.request.taskbadger_task_id is not None
17-
), "missing task ID on self.request"
15+
assert self.request.taskbadger_task_id is not None, "missing task ID on self.request"
1816
return x + y

integration_tests/test_celery.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@
99

1010

1111
@pytest.fixture(autouse=True)
12-
def check_log_errors(caplog):
12+
def _check_log_errors(caplog):
1313
yield
1414
for when in ("call", "setup", "teardown"):
15-
errors = [
16-
r.getMessage()
17-
for r in caplog.get_records(when)
18-
if r.levelno == logging.ERROR
19-
]
15+
errors = [r.getMessage() for r in caplog.get_records(when) if r.levelno == logging.ERROR]
2016
if errors:
2117
pytest.fail(f"log errors during '{when}': {errors}")
2218

pyproject.toml

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,28 @@ dev = [
6969
[project.scripts]
7070
taskbadger = "taskbadger.cli_main:app"
7171

72-
[tool.black]
73-
line-length = 120
74-
target_version = ['py37', 'py38', 'py39']
75-
exclude = '''
76-
(
77-
/(
78-
| \.git
79-
| \.venv
80-
| \.mypy_cache
81-
)/
82-
)
83-
'''
84-
85-
[tool.isort]
86-
line_length = 120
87-
profile = "black"
88-
8972
[tool.pytest.ini_options]
9073
# don't run integration tests unless specifically requested
9174
norecursedirs = ".* integration_tests"
75+
76+
[tool.ruff]
77+
exclude = [
78+
".venv",
79+
".git",
80+
".ruff_cache",
81+
]
82+
line-length = 120
83+
indent-width = 4
84+
target-version = "py39"
85+
86+
[tool.ruff.lint]
87+
select = ["E", "F", "I", "UP", "DJ", "PT"]
88+
fixable = ["ALL"]
89+
unfixable = []
90+
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
91+
92+
[tool.ruff.format]
93+
quote-style = "double"
94+
indent-style = "space"
95+
skip-magic-trailing-comma = false
96+
line-ending = "auto"

taskbadger/celery.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,7 @@ def apply_async(self, *args, **kwargs):
130130
tb_task_id = result.info.get(TB_TASK_ID) if result.info else None
131131
setattr(result, TB_TASK_ID, tb_task_id)
132132

133-
_get_task = (
134-
functools.partial(get_task, tb_task_id) if tb_task_id else lambda: None
135-
)
133+
_get_task = functools.partial(get_task, tb_task_id) if tb_task_id else lambda: None
136134
setattr(result, "get_taskbadger_task", _get_task)
137135

138136
return result

taskbadger/cli/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
from .list_tasks import list_tasks_command
33
from .wrapper import run
44

5-
65
__all__ = ["create", "get", "update", "list_tasks_command", "run"]

taskbadger/cli/basics.py

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import csv
22
import json
33
import sys
4-
from typing import Tuple
54

65
import typer
76
from rich import print
@@ -19,9 +18,7 @@
1918
def get(
2019
ctx: typer.Context,
2120
task_id: str = typer.Argument(..., show_default=False, help="The ID of the task."),
22-
output_format: OutputFormat = typer.Option(
23-
OutputFormat.pretty, "--format", "-f", help="Output format"
24-
),
21+
output_format: OutputFormat = typer.Option(OutputFormat.pretty, "--format", "-f", help="Output format"),
2522
):
2623
"""Get a task."""
2724
configure_api(ctx)
@@ -52,17 +49,15 @@ def create(
5249
ctx: typer.Context,
5350
name: str = typer.Argument(..., show_default=False, help="The task name."),
5451
monitor_id: str = typer.Option(None, help="Associate this task with a monitor."),
55-
action_def: Tuple[str, str, str] = typer.Option(
52+
action_def: tuple[str, str, str] = typer.Option(
5653
(None, None, None),
5754
"--action",
5855
"-a",
5956
metavar="<trigger integration config>",
6057
show_default=False,
6158
help="Action definition e.g. 'success,error email to:me@email.com'",
6259
),
63-
status: StatusEnum = typer.Option(
64-
StatusEnum.PROCESSING, help="The initial status of the task."
65-
),
60+
status: StatusEnum = typer.Option(StatusEnum.PROCESSING, help="The initial status of the task."),
6661
value_max: int = typer.Option(100, help="The maximum value for the task."),
6762
metadata: list[str] = typer.Option(
6863
None,
@@ -74,9 +69,7 @@ def create(
7469
show_default=False,
7570
help="Metadata to associate with the task. Must be valid JSON.",
7671
),
77-
quiet: bool = typer.Option(
78-
False, "--quiet", "-q", help="Minimal output. Only the Task ID."
79-
),
72+
quiet: bool = typer.Option(False, "--quiet", "-q", help="Minimal output. Only the Task ID."),
8073
):
8174
"""Create a task."""
8275
configure_api(ctx)
@@ -103,29 +96,19 @@ def create(
10396

10497
def update(
10598
ctx: typer.Context,
106-
task_id: str = typer.Argument(
107-
..., show_default=False, help="The ID of the task to update."
108-
),
109-
name: str = typer.Option(
110-
None, show_default=False, help="Update the name of the task."
111-
),
112-
action_def: Tuple[str, str, str] = typer.Option(
99+
task_id: str = typer.Argument(..., show_default=False, help="The ID of the task to update."),
100+
name: str = typer.Option(None, show_default=False, help="Update the name of the task."),
101+
action_def: tuple[str, str, str] = typer.Option(
113102
(None, None, None),
114103
"--action",
115104
"-a",
116105
metavar="<trigger integration config>",
117106
show_default=False,
118107
help="Action definition e.g. 'success,error email to:me@email.com'",
119108
),
120-
status: StatusEnum = typer.Option(
121-
StatusEnum.PROCESSING, help="The status of the task."
122-
),
123-
value: int = typer.Option(
124-
None, show_default=False, help="The current task value (progress)."
125-
),
126-
value_max: int = typer.Option(
127-
None, show_default=False, help="The maximum value for the task."
128-
),
109+
status: StatusEnum = typer.Option(StatusEnum.PROCESSING, help="The status of the task."),
110+
value: int = typer.Option(None, show_default=False, help="The current task value (progress)."),
111+
value_max: int = typer.Option(None, show_default=False, help="The maximum value for the task."),
129112
metadata: list[str] = typer.Option(
130113
None,
131114
show_default=False,

taskbadger/cli/list_tasks.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414

1515
def list_tasks_command(
1616
ctx: typer.Context,
17-
output_format: OutputFormat = typer.Option(
18-
OutputFormat.pretty, "--format", "-f", help="Output format"
19-
),
17+
output_format: OutputFormat = typer.Option(OutputFormat.pretty, "--format", "-f", help="Output format"),
2018
limit: int = typer.Option(100, help="Limit the number of results."),
2119
start_token: str = typer.Option(None, show_default=False, help="Start token."),
2220
):

taskbadger/cli/wrapper.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Tuple
2-
31
import typer
42
from rich import print
53

@@ -12,10 +10,8 @@ def run(
1210
ctx: typer.Context,
1311
name: str = typer.Argument(..., show_default=False, help="The task name"),
1412
monitor_id: str = typer.Option(None, help="Associate this task with a monitor."),
15-
update_frequency: int = typer.Option(
16-
5, metavar="SECONDS", min=5, max=300, help="Seconds between updates."
17-
),
18-
action_def: Tuple[str, str, str] = typer.Option(
13+
update_frequency: int = typer.Option(5, metavar="SECONDS", min=5, max=300, help="Seconds between updates."),
14+
action_def: tuple[str, str, str] = typer.Option(
1915
(None, None, None),
2016
"--action",
2117
"-a",
@@ -71,9 +67,7 @@ def run(
7167
if process.returncode == 0:
7268
task.success(value=100)
7369
else:
74-
_update_task(
75-
task, status=StatusEnum.ERROR, return_code=process.returncode
76-
)
70+
_update_task(task, status=StatusEnum.ERROR, return_code=process.returncode)
7771

7872
if process.returncode != 0:
7973
raise typer.Exit(process.returncode)
@@ -86,8 +80,6 @@ def _update_task(task, status=None, **data_kwargs):
8680

8781
merge_strategy = DefaultMergeStrategy(append_keys=("stdout", "stderr"))
8882
try:
89-
task.update(
90-
status=status, data=data_kwargs or None, data_merge_strategy=merge_strategy
91-
)
83+
task.update(status=status, data=data_kwargs or None, data_merge_strategy=merge_strategy)
9284
except Exception as e:
9385
err_console.print(f"Error updating task status: {e!r}")

0 commit comments

Comments
 (0)