Skip to content

Commit 3343c0f

Browse files
committed
uv + ruff
1 parent 2b13965 commit 3343c0f

47 files changed

Lines changed: 1943 additions & 240 deletions

Some content is hidden

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

.pre-commit-config.yaml

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,25 @@
11
exclude: ^static/.*|assets/.*|/migrations/.*|\.min\.js$|\.min\.css$|\.css\.map$|\.min\.js$|\.js\.map$|\.svg$
2+
default_language_version:
3+
python: python3.11
24
repos:
3-
- repo: https://github.com/pycqa/isort
4-
rev: 5.12.0
5+
- repo: https://github.com/astral-sh/ruff-pre-commit
6+
rev: v0.2.1
57
hooks:
6-
- id: isort
7-
name: isort (python)
8-
args: ["--filter-files", "--profile", "black", "--line-length=120"]
9-
- repo: https://github.com/psf/black
10-
rev: 23.1.0
11-
hooks:
12-
- id: black
13-
args: ["--line-length=120"]
14-
language_version: python3.10
8+
- id: ruff
9+
args: [ --fix ]
10+
- id: ruff-format
1511
- repo: https://github.com/pre-commit/pre-commit-hooks
1612
rev: v4.4.0
1713
hooks:
1814
- id: check-added-large-files
19-
args: [--maxkb=2048]
15+
args: [ --maxkb=2048 ]
2016
- id: check-toml
21-
types: [toml]
17+
types: [ toml ]
2218
- id: check-yaml
23-
types: [yaml]
19+
types: [ yaml ]
2420
- id: end-of-file-fixer
25-
types: [text]
26-
stages: [commit, push, manual]
21+
types: [ text ]
22+
stages: [ pre-commit, pre-push, manual ]
2723
- id: trailing-whitespace
28-
types: [text]
29-
stages: [commit, push, manual]
30-
- repo: https://github.com/pre-commit/mirrors-prettier
31-
rev: v3.0.0-alpha.4
32-
hooks:
33-
- id: prettier
34-
exclude: taskbadger.yaml
24+
types: [ text ]
25+
stages: [ pre-commit, pre-push, manual ]

examples/demo.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,28 @@
22
import os
33

44
import taskbadger as tb
5-
from examples.migration_utils import get_data_chunks, get_total, prepare_migration, process_chunk
5+
from examples.migration_utils import (
6+
get_data_chunks,
7+
get_total,
8+
prepare_migration,
9+
process_chunk,
10+
)
611
from taskbadger import EmailIntegration
712

813

914
def main(args):
1015
tb.init(args.org, args.project, args.key)
1116
actions = []
1217
if args.email:
13-
actions = [tb.Action("*/10%,success,error", integration=EmailIntegration(to=args.email))]
18+
actions = [
19+
tb.Action(
20+
"*/10%,success,error", integration=EmailIntegration(to=args.email)
21+
)
22+
]
1423

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

1728
context = prepare_migration()
1829

@@ -36,8 +47,12 @@ def perform_migration(context, task: tb.Task):
3647
if __name__ == "__main__":
3748
parser = argparse.ArgumentParser("Demo database migration")
3849
parser.add_argument("task_name")
39-
parser.add_argument("-o", "--org", required=True, help="Taskbadger Organization slug")
40-
parser.add_argument("-p", "--project", required=True, help="Taskbadger Project slug")
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+
)
4156
parser.add_argument("-k", "--key", required=True, help="Taskbadger API Key")
4257
parser.add_argument("-e", "--email")
4358
args = parser.parse_args()

integration_tests/__init__.py

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

integration_tests/tasks.py

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

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

integration_tests/test_celery.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
def check_log_errors(caplog):
1313
yield
1414
for when in ("call", "setup", "teardown"):
15-
errors = [r.getMessage() for r in caplog.get_records(when) if r.levelno == logging.ERROR]
15+
errors = [
16+
r.getMessage()
17+
for r in caplog.get_records(when)
18+
if r.levelno == logging.ERROR
19+
]
1620
if errors:
1721
pytest.fail(f"log errors during '{when}': {errors}")
1822

pyproject.toml

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
[tool.poetry]
1+
[project]
22
name = "taskbadger"
33
version = "1.3.4"
44
description = "The official Python SDK for Task Badger"
5-
license = "Apache-2.0"
6-
5+
requires-python = ">=3.9"
76
authors = []
8-
97
readme = "README.md"
10-
packages = [
11-
{include = "taskbadger"},
12-
]
13-
include = ["taskbadger/internal/py.typed"]
14-
15-
homepage = "https://taskbadger.net/"
16-
repository = "https://github.com/taskbadger/taskbadger-python"
17-
documentation = "https://docs.taskbadger.net/"
188
classifiers = [
199
"Development Status :: 4 - Beta",
2010
"Environment :: Web Environment",
@@ -30,40 +20,55 @@ classifiers = [
3020
"Topic :: Software Development :: Libraries :: Python Modules",
3121
]
3222

33-
[tool.poetry.urls]
34-
"Changelog" = "https://github.com/taskbadger/taskbadger-python/releases"
23+
dependencies = [
24+
"httpx >=0.20.0,<0.28.0",
25+
"attrs >=21.3.0",
26+
"python-dateutil >=2.8.0",
27+
"typer[all] <0.10.0",
28+
"tomlkit >=0.12.5",
29+
"importlib-metadata >=1.0; python_version < '3.8'",
30+
"typing-extensions >=4.7.1; python_version <= '3.9'",
31+
]
3532

36-
[tool.poetry.dependencies]
37-
python = "^3.8"
38-
httpx = ">=0.20.0,<0.28.0"
39-
attrs = ">=21.3.0"
40-
python-dateutil = "^2.8.0"
41-
typer = {extras = ["all"], version = "<0.10.0"}
42-
tomlkit = "^0.12.5"
43-
importlib-metadata = {version = "^1.0", python = "<3.8"}
44-
typing-extensions = {version = "^4.7.1", python = "3.9"}
45-
celery = {version = ">=4.0.0,<6.0.0", optional = true}
33+
[build-system]
34+
requires = ["hatchling"]
35+
build-backend = "hatchling.build"
4636

47-
[tool.poetry.extras]
48-
celery = ["celery"]
4937

50-
[tool.poetry.group.dev.dependencies]
51-
openapi-python-client = "^0.15.1"
52-
pytest = "^7.2.1"
53-
isort = "^5.12.0"
54-
black = "^23.1.0"
55-
pre-commit = "^3.0.2"
56-
pytest-httpx = "^0.21.3"
57-
invoke = "^2.0.0"
58-
pytest-celery = ">0.0.0"
59-
redis = "^5.0.4"
38+
[tool.setuptools]
39+
packages = ["taskbadger"]
40+
include = ["taskbadger/internal/py.typed"]
6041

61-
[tool.poetry.scripts]
62-
taskbadger = "taskbadger.cli_main:app"
42+
[project.optional-dependencies]
43+
celery = [
44+
"celery>=4.0.0,<6.0.0",
45+
]
6346

64-
[build-system]
65-
requires = ["poetry-core>=1.0.0"]
66-
build-backend = "poetry.core.masonry.api"
47+
[tool.uv]
48+
package = true
49+
50+
[project.urls]
51+
"Changelog" = "https://github.com/taskbadger/taskbadger-python/releases"
52+
homepage = "https://taskbadger.net/"
53+
repository = "https://github.com/taskbadger/taskbadger-python"
54+
documentation = "https://docs.taskbadger.net/"
55+
56+
57+
[dependency-groups]
58+
dev = [
59+
"black",
60+
"isort",
61+
"pre-commit",
62+
"pytest",
63+
"pytest-httpx",
64+
"invoke",
65+
"pytest-celery",
66+
"redis",
67+
"openapi-python-client",
68+
]
69+
70+
[project.scripts]
71+
taskbadger = "taskbadger.cli_main:app"
6772

6873
[tool.black]
6974
line-length = 120

taskbadger/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@
55
from .safe_sdk import create_task_safe, update_task_safe
66
from .sdk import DefaultMergeStrategy, Task, create_task, get_task, init, update_task
77

8+
__all__ = [
9+
"track",
10+
"Action",
11+
"EmailIntegration",
12+
"WebhookIntegration",
13+
"StatusEnum",
14+
"Badger",
15+
"Session",
16+
"create_task_safe",
17+
"update_task_safe",
18+
"DefaultMergeStrategy",
19+
"Task",
20+
"create_task",
21+
"get_task",
22+
"init",
23+
"update_task",
24+
]
25+
826
try:
927
import importlib.metadata as importlib_metadata
1028
except ModuleNotFoundError:

taskbadger/celery.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
import logging
44

55
import celery
6-
from celery.signals import before_task_publish, task_failure, task_prerun, task_retry, task_success
6+
from celery.signals import (
7+
before_task_publish,
8+
task_failure,
9+
task_prerun,
10+
task_retry,
11+
task_success,
12+
)
713

814
from .internal.models import StatusEnum
915
from .mug import Badger
@@ -15,7 +21,12 @@
1521
IGNORE_ARGS = {TB_KWARGS_ARG, f"{KWARG_PREFIX}task", f"{KWARG_PREFIX}task_id"}
1622
TB_TASK_ID = f"{KWARG_PREFIX}task_id"
1723

18-
TERMINAL_STATES = {StatusEnum.SUCCESS, StatusEnum.ERROR, StatusEnum.CANCELLED, StatusEnum.STALE}
24+
TERMINAL_STATES = {
25+
StatusEnum.SUCCESS,
26+
StatusEnum.ERROR,
27+
StatusEnum.CANCELLED,
28+
StatusEnum.STALE,
29+
}
1930

2031
log = logging.getLogger("taskbadger")
2132

@@ -119,7 +130,9 @@ def apply_async(self, *args, **kwargs):
119130
tb_task_id = result.info.get(TB_TASK_ID) if result.info else None
120131
setattr(result, TB_TASK_ID, tb_task_id)
121132

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

125138
return result

taskbadger/cli/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
from .basics import create, get, update
22
from .list_tasks import list_tasks_command
33
from .wrapper import run
4+
5+
6+
__all__ = ["create", "get", "update", "list_tasks_command", "run"]

0 commit comments

Comments
 (0)