Last active
February 6, 2024 18:19
-
-
Save bswck/c75d4a5bfcf7f6d8fa830cb2bff4297f to your computer and use it in GitHub Desktop.
Extract projects for https://github.com/jaraco/skeleton/issues/98 roadmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
import re | |
import xmlrpc.client | |
from functools import cache | |
from posixpath import basename | |
import pandas as pd | |
from httpx import HTTPStatusError, get | |
from pypistats import recent | |
# ruff: noqa: T201 | |
SKELETON_PATTERN = re.compile( | |
r"https://img.shields.io/badge/skeleton-\d{4}-informational", | |
) | |
def get_jaraco_projects() -> list[tuple[str, str]]: | |
client = xmlrpc.client.ServerProxy("https://pypi.python.org/pypi") | |
return client.user_packages("jaraco") # type: ignore[return-value] | |
def get_pypi_stats_last_month(project: str) -> int: | |
try: | |
return recent(project, format="pandas").last_month[0] # type: ignore[no-any-return] | |
except HTTPStatusError: | |
return 0 | |
@cache | |
def get_pypi_project_data(project_url: str) -> dict[str, str]: | |
return get( # type: ignore[no-any-return] | |
f"{project_url.replace('/project/', '/pypi/', 1)}/json", | |
).json()["info"] | |
def get_homepage(project: str) -> str: | |
return get_pypi_project_data(project)["home_page"] | |
def get_skeleton_status(project_url: str, no_skeleton: str = "❌") -> str: | |
# fmt: off | |
badge_url = next(iter( | |
SKELETON_PATTERN.findall(get_pypi_project_data(project_url)["description"]), | |
), None) | |
# fmt: on | |
if badge_url: | |
return f"![skeleton]({badge_url})" | |
return no_skeleton | |
if __name__ == "__main__": | |
jaraco_projects = get_jaraco_projects() | |
stats = pd.DataFrame.from_dict( | |
{ | |
f"[{project}]({(project_url := f'https://pypi.org/project/{project}')})": ( | |
get_pypi_stats_last_month(project_url), | |
role, | |
get_skeleton_status(project_url), | |
) | |
for role, project in jaraco_projects | |
}, | |
orient="index", | |
columns=[ | |
key_column := "downloads last month", | |
"jaraco's role", | |
"uses skeleton?", | |
], | |
).sort_values(key_column, ascending=False) | |
table = stats.to_markdown() | |
print(table, end="\n\n# Roadmap\n") | |
for project_link in stats.index: | |
project_url = project_link[project_link.index("(") + 1 : -1] | |
homepage_url = get_homepage(project_url) | |
project = basename(project_url) | |
badge = ( | |
f"[![downloads](https://static.pepy.tech/badge/{project}/month)]" | |
f"(https://pepy.tech/projects/{project})" | |
) | |
print( | |
f"- [ ] [{project}]({homepage_url}) {badge} " | |
f"{get_skeleton_status(project_url, no_skeleton='')}", | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment