3737
3838import httpx
3939import packaging .version
40- import tabulate
4140import wcwidth
42- from tqdm import tqdm
4341
4442if TYPE_CHECKING :
4543 from collections .abc import Generator
4644
4745_FILE_HEAD = """# Plugin List
4846
49- PyPI projects that match `pytask-*` are considered plugins and are listed
50- automatically. Packages classified as inactive are excluded.
47+ PyPI projects that match `pytask-*` are considered plugins and are listed automatically.
48+ Packages classified as inactive are excluded.
5149
5250!!! warning
5351
54- Please be aware that this list is not a curated collection of projects and does not
55- undergo a systematic review process. It serves purely as an informational resource
56- to aid in the discovery of `pytask` plugins.
52+ ```
53+ Please be aware that this list is not a curated collection of projects and does not
54+ undergo a systematic review process. It serves purely as an informational resource
55+ to aid in the discovery of `pytask` plugins.
5756
58- Do not presume any endorsement from the `pytask` project or its developers, and
59- always conduct your own quality assessment before incorporating any of these plugins
60- into your own projects.
57+ Do not presume any endorsement from the `pytask` project or its developers, and
58+ always conduct your own quality assessment before incorporating any of these plugins
59+ into your own projects.
60+ ```
6161
6262"""
6363
@@ -86,6 +86,43 @@ def _escape_markdown(text: str) -> str:
8686 return text .replace ("|" , "\\ |" )
8787
8888
89+ def _pad (text : str , width : int ) -> str :
90+ """Pad text to the requested display width."""
91+ return text + " " * (width - wcwidth .wcswidth (text ))
92+
93+
94+ def _create_table (entries : list [dict [str , str ]]) -> str :
95+ """Create a markdown table in the repository's canonical format."""
96+ if not entries :
97+ msg = "Cannot create a plugin table without entries."
98+ raise ValueError (msg )
99+
100+ headers = list (entries [0 ])
101+ widths = [
102+ max (
103+ wcwidth .wcswidth (header ),
104+ * (wcwidth .wcswidth (row [header ]) for row in entries ),
105+ )
106+ for header in headers
107+ ]
108+
109+ header_cells = (
110+ _pad (header , width ) for header , width in zip (headers , widths , strict = False )
111+ )
112+ header = "| " + " | " .join (header_cells ) + " |"
113+ separator = "| " + " | " .join ("-" * width for width in widths ) + " |"
114+ rows = [
115+ "| "
116+ + " | " .join (
117+ _pad (row [header ], width )
118+ for header , width in zip (headers , widths , strict = False )
119+ )
120+ + " |"
121+ for row in entries
122+ ]
123+ return "\n " .join ([header , separator , * rows ])
124+
125+
89126def _iter_plugins () -> Generator [dict [str , str ], None , None ]: # noqa: C901
90127 """Iterate over all plugins and format entries."""
91128 regex = r">([\d\w-]*)</a>"
@@ -98,7 +135,7 @@ def _iter_plugins() -> Generator[dict[str, str], None, None]: # noqa: C901
98135 and match .groups ()[0 ] not in _EXCLUDED_PACKAGES
99136 ]
100137
101- for match in tqdm ( matches , smoothing = 0 ) :
138+ for match in matches :
102139 name = match .groups ()[0 ]
103140 response = httpx .get (f"https://pypi.org/pypi/{ name } /json" , timeout = 20 )
104141 if response .status_code == 404 : # noqa: PLR2004
@@ -168,10 +205,7 @@ def main() -> None:
168205 with plugin_list .open ("w" ) as f :
169206 f .write (_FILE_HEAD )
170207 f .write (f"This list contains { len (plugins )} plugins.\n \n " )
171-
172- assert wcwidth # reference library that must exist for tabulate to work
173- plugin_table = tabulate .tabulate (plugins , headers = "keys" , tablefmt = "github" )
174- f .write (plugin_table )
208+ f .write (_create_table (plugins ))
175209 f .write ("\n " )
176210
177211
0 commit comments