2023-12-31 21:25:13 +08:00
|
|
|
# mypy: disallow-untyped-defs
|
2021-01-29 22:19:54 +08:00
|
|
|
import datetime
|
|
|
|
import pathlib
|
|
|
|
import re
|
2021-10-28 16:31:52 +08:00
|
|
|
from textwrap import dedent
|
|
|
|
from textwrap import indent
|
2023-12-31 21:25:13 +08:00
|
|
|
from typing import Any
|
|
|
|
from typing import Iterable
|
|
|
|
from typing import Iterator
|
|
|
|
from typing import TypedDict
|
2021-01-29 22:19:54 +08:00
|
|
|
|
|
|
|
import packaging.version
|
2023-04-24 23:12:25 +08:00
|
|
|
import platformdirs
|
2021-01-29 22:19:54 +08:00
|
|
|
import tabulate
|
2021-10-28 16:31:52 +08:00
|
|
|
import wcwidth
|
2023-04-24 23:12:25 +08:00
|
|
|
from requests_cache import CachedResponse
|
|
|
|
from requests_cache import CachedSession
|
|
|
|
from requests_cache import OriginalResponse
|
|
|
|
from requests_cache import SQLiteCache
|
2021-10-28 16:31:52 +08:00
|
|
|
from tqdm import tqdm
|
2021-01-29 22:19:54 +08:00
|
|
|
|
2023-04-24 23:12:25 +08:00
|
|
|
|
2021-04-01 21:12:46 +08:00
|
|
|
FILE_HEAD = r"""
|
2023-04-24 23:12:25 +08:00
|
|
|
.. Note this file is autogenerated by scripts/update-plugin-list.py - usually weekly via github action
|
|
|
|
|
2021-03-26 18:13:52 +08:00
|
|
|
.. _plugin-list:
|
|
|
|
|
2023-09-06 18:34:38 +08:00
|
|
|
Pytest Plugin List
|
|
|
|
==================
|
2021-01-29 22:19:54 +08:00
|
|
|
|
2023-09-06 18:34:38 +08:00
|
|
|
Below is an automated compilation of ``pytest``` plugins available on `PyPI <https://pypi.org>`_.
|
|
|
|
It includes PyPI projects whose names begin with "pytest-" and a handful of manually selected projects.
|
2023-06-06 17:15:57 +08:00
|
|
|
Packages classified as inactive are excluded.
|
2021-10-28 16:31:52 +08:00
|
|
|
|
2023-09-06 18:34:38 +08:00
|
|
|
For detailed insights into how this list is generated,
|
|
|
|
please refer to `the update script <https://github.com/pytest-dev/pytest/blob/main/scripts/update-plugin-list.py>`_.
|
|
|
|
|
|
|
|
.. warning::
|
|
|
|
|
|
|
|
Please be aware that this list is not a curated collection of projects
|
|
|
|
and does not undergo a systematic review process.
|
|
|
|
It serves purely as an informational resource to aid in the discovery of ``pytest`` plugins.
|
|
|
|
|
|
|
|
Do not presume any endorsement from the ``pytest`` project or its developers,
|
|
|
|
and always conduct your own quality assessment before incorporating any of these plugins into your own projects.
|
|
|
|
|
|
|
|
|
2021-10-28 16:31:52 +08:00
|
|
|
.. The following conditional uses a different format for this list when
|
|
|
|
creating a PDF, because otherwise the table gets far too wide for the
|
|
|
|
page.
|
|
|
|
|
2021-01-29 22:19:54 +08:00
|
|
|
"""
|
|
|
|
DEVELOPMENT_STATUS_CLASSIFIERS = (
|
|
|
|
"Development Status :: 1 - Planning",
|
|
|
|
"Development Status :: 2 - Pre-Alpha",
|
|
|
|
"Development Status :: 3 - Alpha",
|
|
|
|
"Development Status :: 4 - Beta",
|
|
|
|
"Development Status :: 5 - Production/Stable",
|
|
|
|
"Development Status :: 6 - Mature",
|
|
|
|
"Development Status :: 7 - Inactive",
|
|
|
|
)
|
2023-06-06 17:15:57 +08:00
|
|
|
ADDITIONAL_PROJECTS = { # set of additional projects to consider as plugins
|
|
|
|
"logassert",
|
2023-08-19 05:34:40 +08:00
|
|
|
"nuts",
|
2023-09-13 06:17:20 +08:00
|
|
|
"flask_fixture",
|
2023-06-06 17:15:57 +08:00
|
|
|
}
|
2021-01-29 22:19:54 +08:00
|
|
|
|
|
|
|
|
2021-09-22 21:29:37 +08:00
|
|
|
def escape_rst(text: str) -> str:
|
|
|
|
"""Rudimentary attempt to escape special RST characters to appear as
|
|
|
|
plain text."""
|
|
|
|
text = (
|
2021-09-22 21:41:32 +08:00
|
|
|
text.replace("*", "\\*")
|
2021-09-22 21:29:37 +08:00
|
|
|
.replace("<", "\\<")
|
|
|
|
.replace(">", "\\>")
|
|
|
|
.replace("`", "\\`")
|
|
|
|
)
|
|
|
|
text = re.sub(r"_\b", "", text)
|
|
|
|
return text
|
|
|
|
|
|
|
|
|
2023-04-24 23:12:25 +08:00
|
|
|
def project_response_with_refresh(
|
|
|
|
session: CachedSession, name: str, last_serial: int
|
|
|
|
) -> OriginalResponse | CachedResponse:
|
|
|
|
"""Get a http cached pypi project
|
|
|
|
|
|
|
|
force refresh in case of last serial mismatch
|
|
|
|
"""
|
|
|
|
|
|
|
|
response = session.get(f"https://pypi.org/pypi/{name}/json")
|
|
|
|
if int(response.headers.get("X-PyPI-Last-Serial", -1)) != last_serial:
|
|
|
|
response = session.get(f"https://pypi.org/pypi/{name}/json", refresh=True)
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
|
def get_session() -> CachedSession:
|
|
|
|
"""Configures the requests-cache session"""
|
|
|
|
cache_path = platformdirs.user_cache_path("pytest-plugin-list")
|
|
|
|
cache_path.mkdir(exist_ok=True, parents=True)
|
|
|
|
cache_file = cache_path.joinpath("http_cache.sqlite3")
|
|
|
|
return CachedSession(backend=SQLiteCache(cache_file))
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_plugin_projects_from_pypi(session: CachedSession) -> dict[str, int]:
|
|
|
|
response = session.get(
|
|
|
|
"https://pypi.org/simple",
|
|
|
|
headers={"Accept": "application/vnd.pypi.simple.v1+json"},
|
|
|
|
refresh=True,
|
|
|
|
)
|
|
|
|
return {
|
|
|
|
name: p["_last-serial"]
|
|
|
|
for p in response.json()["projects"]
|
|
|
|
if (name := p["name"]).startswith("pytest-") or name in ADDITIONAL_PROJECTS
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-31 21:25:13 +08:00
|
|
|
class PluginInfo(TypedDict):
|
|
|
|
"""Relevant information about a plugin to generate the summary."""
|
|
|
|
|
|
|
|
name: str
|
|
|
|
summary: str
|
|
|
|
last_release: str
|
|
|
|
status: str
|
|
|
|
requires: str
|
|
|
|
|
|
|
|
|
|
|
|
def iter_plugins() -> Iterator[PluginInfo]:
|
2023-04-24 23:12:25 +08:00
|
|
|
session = get_session()
|
|
|
|
name_2_serial = pytest_plugin_projects_from_pypi(session)
|
|
|
|
|
|
|
|
for name, last_serial in tqdm(name_2_serial.items(), smoothing=0):
|
|
|
|
response = project_response_with_refresh(session, name, last_serial)
|
2021-01-29 22:19:54 +08:00
|
|
|
if response.status_code == 404:
|
2023-06-06 17:15:57 +08:00
|
|
|
# Some packages, like pytest-azurepipelines42, are included in https://pypi.org/simple
|
|
|
|
# but return 404 on the JSON API. Skip.
|
2021-01-29 22:19:54 +08:00
|
|
|
continue
|
|
|
|
response.raise_for_status()
|
|
|
|
info = response.json()["info"]
|
|
|
|
if "Development Status :: 7 - Inactive" in info["classifiers"]:
|
|
|
|
continue
|
|
|
|
for classifier in DEVELOPMENT_STATUS_CLASSIFIERS:
|
|
|
|
if classifier in info["classifiers"]:
|
|
|
|
status = classifier[22:]
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
status = "N/A"
|
|
|
|
requires = "N/A"
|
|
|
|
if info["requires_dist"]:
|
|
|
|
for requirement in info["requires_dist"]:
|
2022-11-09 02:05:10 +08:00
|
|
|
if re.match(r"pytest(?![-.\w])", requirement):
|
2021-01-29 22:19:54 +08:00
|
|
|
requires = requirement
|
|
|
|
break
|
2022-12-22 00:49:20 +08:00
|
|
|
|
2023-12-31 21:25:13 +08:00
|
|
|
def version_sort_key(version_string: str) -> Any:
|
2022-12-22 00:49:20 +08:00
|
|
|
"""
|
|
|
|
Return the sort key for the given version string
|
|
|
|
returned by the API.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
return packaging.version.parse(version_string)
|
|
|
|
except packaging.version.InvalidVersion:
|
|
|
|
# Use a hard-coded pre-release version.
|
|
|
|
return packaging.version.Version("0.0.0alpha")
|
|
|
|
|
2021-01-29 22:19:54 +08:00
|
|
|
releases = response.json()["releases"]
|
2022-12-22 00:49:20 +08:00
|
|
|
for release in sorted(releases, key=version_sort_key, reverse=True):
|
2021-01-29 22:19:54 +08:00
|
|
|
if releases[release]:
|
|
|
|
release_date = datetime.date.fromisoformat(
|
|
|
|
releases[release][-1]["upload_time_iso_8601"].split("T")[0]
|
|
|
|
)
|
|
|
|
last_release = release_date.strftime("%b %d, %Y")
|
|
|
|
break
|
2021-10-22 20:47:57 +08:00
|
|
|
name = f':pypi:`{info["name"]}`'
|
2022-11-08 04:00:31 +08:00
|
|
|
summary = ""
|
|
|
|
if info["summary"]:
|
|
|
|
summary = escape_rst(info["summary"].replace("\n", ""))
|
2021-01-29 22:19:54 +08:00
|
|
|
yield {
|
|
|
|
"name": name,
|
2021-10-28 16:31:52 +08:00
|
|
|
"summary": summary.strip(),
|
2023-12-31 21:25:13 +08:00
|
|
|
"last_release": last_release,
|
2021-01-29 22:19:54 +08:00
|
|
|
"status": status,
|
|
|
|
"requires": requires,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-31 21:25:13 +08:00
|
|
|
def plugin_definitions(plugins: Iterable[PluginInfo]) -> Iterator[str]:
|
2021-10-28 16:31:52 +08:00
|
|
|
"""Return RST for the plugin list that fits better on a vertical page."""
|
|
|
|
|
|
|
|
for plugin in plugins:
|
|
|
|
yield dedent(
|
|
|
|
f"""
|
|
|
|
{plugin['name']}
|
2023-12-31 21:25:13 +08:00
|
|
|
*last release*: {plugin["last_release"]},
|
2021-10-28 16:31:52 +08:00
|
|
|
*status*: {plugin["status"]},
|
|
|
|
*requires*: {plugin["requires"]}
|
|
|
|
|
|
|
|
{plugin["summary"]}
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-12-31 21:25:13 +08:00
|
|
|
def main() -> None:
|
2023-04-24 23:12:25 +08:00
|
|
|
plugins = [*iter_plugins()]
|
2021-10-28 16:31:52 +08:00
|
|
|
|
|
|
|
reference_dir = pathlib.Path("doc", "en", "reference")
|
|
|
|
|
|
|
|
plugin_list = reference_dir / "plugin_list.rst"
|
2022-12-22 00:49:20 +08:00
|
|
|
with plugin_list.open("w", encoding="UTF-8") as f:
|
2021-01-29 22:19:54 +08:00
|
|
|
f.write(FILE_HEAD)
|
|
|
|
f.write(f"This list contains {len(plugins)} plugins.\n\n")
|
2021-10-28 16:31:52 +08:00
|
|
|
f.write(".. only:: not latex\n\n")
|
|
|
|
|
|
|
|
wcwidth # reference library that must exist for tabulate to work
|
|
|
|
plugin_table = tabulate.tabulate(plugins, headers="keys", tablefmt="rst")
|
|
|
|
f.write(indent(plugin_table, " "))
|
|
|
|
f.write("\n\n")
|
|
|
|
|
|
|
|
f.write(".. only:: latex\n\n")
|
|
|
|
f.write(indent("".join(plugin_definitions(plugins)), " "))
|
2021-01-29 22:19:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|