Skip to content

Commit e7563ee

Browse files
1063 usethis badge socket (#1080)
* Add Socket badge implementation * Add the socket badge to the README
1 parent 7db8e93 commit e7563ee

4 files changed

Lines changed: 41 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ If you're not interested in templating automations, then [configurator](https://
198198
[![CodSpeed](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/usethis-python/usethis-python)
199199
[![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)
200200
[![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)
201+
[![Socket Badge](https://badge.socket.dev/pypi/package/usethis)](https://socket.dev/pypi/package/usethis/overview)
201202

202203
### Roadmap
203204

src/usethis/_core/badge.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ def get_ruff_badge() -> Badge:
5555
)
5656

5757

58+
def get_socket_badge() -> Badge:
59+
name = get_project_name()
60+
return Badge(
61+
markdown=f"[![Socket Badge](https://badge.socket.dev/pypi/package/{name})](https://socket.dev/pypi/package/{name}/overview)"
62+
)
63+
64+
5865
def get_uv_badge() -> Badge:
5966
return Badge(
6067
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)"
@@ -68,12 +75,17 @@ def get_usethis_badge() -> Badge:
6875

6976

7077
def get_badge_order() -> list[Badge]:
78+
# Some general principles here:
79+
# 1. Dynamic badges giving factual information about the package should go first
80+
# 2. Static badges which list affiliation should go next e.g. uv, Ruff, etc.
81+
# 3. Badges giving project scores, ratings, etc. should go last.
7182
return [
7283
get_pypi_badge(),
7384
get_uv_badge(),
7485
get_ruff_badge(),
7586
get_pre_commit_badge(),
7687
get_usethis_badge(),
88+
get_socket_badge(),
7789
]
7890

7991

src/usethis/_ui/interface/badge.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ def pre_commit(
6565
_badge_effect(get_pre_commit_badge(), remove=remove, show=show)
6666

6767

68+
@app.command(
69+
help="Add a badge with your PyPI package's supply chain security rating from Socket."
70+
)
71+
def socket(
72+
remove: bool = remove_opt,
73+
offline: bool = offline_opt,
74+
quiet: bool = quiet_opt,
75+
show: bool = show_opt,
76+
) -> None:
77+
from usethis._config import usethis_config
78+
from usethis._config_file import files_manager
79+
from usethis._core.badge import get_socket_badge
80+
81+
with usethis_config.set(offline=offline, quiet=quiet), files_manager():
82+
_badge_effect(get_socket_badge(), remove=remove, show=show)
83+
84+
6885
@app.command(help="Add a badge for usethis.")
6986
def usethis(
7087
remove: bool = remove_opt,

tests/usethis/_ui/interface/test_interface_badge.py

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

8888

89+
class TestSocket:
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, ["socket"])
95+
96+
# Assert
97+
assert result.exit_code == 0, result.output
98+
99+
89100
class TestPreCommit:
90101
def test_add(self, tmp_path: Path):
91102
# Act

0 commit comments

Comments
 (0)