Skip to content

Commit 80ea5da

Browse files
Implement usethis badge ty command
Add a badge for the ty type checker from Astral. The badge uses the endpoint URL from the ty repository's assets. Changes: - Add get_ty_badge() function in src/usethis/_core/badge.py - Add ty to badge ordering in get_badge_order() - Add ty CLI command in src/usethis/_ui/interface/badge.py - Add tests for ty badge in tests/usethis/_ui/interface/test_interface_badge.py - Update docs/cli/reference.md with ty badge entry Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com> Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/9a568c69-1340-45e1-bc80-2c3cd91a906a
1 parent 6fec495 commit 80ea5da

4 files changed

Lines changed: 61 additions & 0 deletions

File tree

docs/cli/reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ Currently supported badges:
317317
- `usethis badge pypi` - [![PyPI Version](https://img.shields.io/pypi/v/usethis.svg)](https://pypi.python.org/pypi/usethis)
318318
- `usethis badge ruff` - [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
319319
- `usethis badge socket` - [![Socket](https://badge.socket.dev/pypi/package/usethis)](https://socket.dev/pypi/package/usethis/overview)
320+
- `usethis badge ty` - [![ty](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ty/main/assets/badge/v0.json)](https://github.com/astral-sh/ty)
320321
- `usethis badge usethis` - [![usethis](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/usethis-python/usethis-python/main/assets/badge/v1.json)](https://github.com/usethis-python/usethis-python)
321322
- `usethis badge uv` - [![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
322323

src/usethis/_core/badge.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ def get_socket_badge() -> Badge:
6262
)
6363

6464

65+
def get_ty_badge() -> Badge:
66+
return Badge(
67+
markdown="[![ty](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ty/main/assets/badge/v0.json)](https://github.com/astral-sh/ty)"
68+
)
69+
70+
6571
def get_uv_badge() -> Badge:
6672
return Badge(
6773
markdown="[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)"
@@ -83,6 +89,7 @@ def get_badge_order() -> list[Badge]:
8389
get_pypi_badge(),
8490
get_uv_badge(),
8591
get_ruff_badge(),
92+
get_ty_badge(),
8693
get_pre_commit_badge(),
8794
get_usethis_badge(),
8895
get_socket_badge(),

src/usethis/_ui/interface/badge.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ def ruff(
4949
_badge_effect(get_ruff_badge(), remove=remove, show=show)
5050

5151

52+
@app.command(help="Add a badge for the ty type checker.")
53+
def ty(
54+
remove: bool = remove_opt,
55+
offline: bool = offline_opt,
56+
quiet: bool = quiet_opt,
57+
show: bool = show_opt,
58+
) -> None:
59+
from usethis._config_file import files_manager
60+
from usethis._core.badge import get_ty_badge
61+
62+
with usethis_config.set(offline=offline, quiet=quiet), files_manager():
63+
_badge_effect(get_ty_badge(), remove=remove, show=show)
64+
65+
5266
@app.command(help="Add a badge for the pre-commit framework.")
5367
def pre_commit(
5468
remove: bool = remove_opt,

tests/usethis/_ui/interface/test_interface_badge.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,45 @@ def test_show(self, tmp_path: Path):
8686
assert result.exit_code == 0, result.output
8787

8888

89+
class TestTy:
90+
def test_add(self, tmp_path: Path):
91+
# Act
92+
runner = CliRunner()
93+
with change_cwd(tmp_path):
94+
result = runner.invoke_safe(app, ["ty"])
95+
96+
# Assert
97+
assert result.exit_code == 0, result.output
98+
99+
def test_remove(self, tmp_path: Path):
100+
# Arrange
101+
(tmp_path / "README.md").write_text("")
102+
103+
# Act
104+
runner = CliRunner()
105+
with change_cwd(tmp_path):
106+
result = runner.invoke_safe(app, ["ty", "--remove"])
107+
108+
# Assert
109+
assert result.exit_code == 0, result.output
110+
111+
def test_show(self, tmp_path: Path):
112+
# Arrange
113+
(tmp_path / "README.md").write_text("")
114+
115+
# Act
116+
runner = CliRunner()
117+
with change_cwd(tmp_path):
118+
result = runner.invoke_safe(app, ["ty", "--show"])
119+
120+
# Assert
121+
assert result.exit_code == 0, result.output
122+
assert (
123+
result.output
124+
== "[![ty](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ty/main/assets/badge/v0.json)](https://github.com/astral-sh/ty)\n"
125+
)
126+
127+
89128
class TestSocket:
90129
def test_add(self, tmp_path: Path):
91130
# Act

0 commit comments

Comments
 (0)