Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
sphinx-api-relink
This package is a plugin for the sphinx.ext.autodoc
extension. The autodoc_type_aliases
configuration does not always work well when using postponed evaluation of annotations (PEP 563, i.e. from __future__ import annotations
) or when importing through typing.TYPE_CHECKING
, because sphinx.ext.autodoc
generates the API dynamically (not statically, as opposed to sphinx-autoapi
).
Just install through PyPI with pip
:
pip install sphinx-api-relink
Next, in your Sphinx configuration file (conf.py
), add "sphinx_api_relink"
to your extensions
:
extensions = [
"sphinx_api_relink",
]
There are two ways to relink type hint references in your API. The first one, api_target_substitutions
, should be used when the target is different than the type hint itself:
api_target_substitutions: dict[str, str | tuple[str, str]] = {
"sp.Expr": "sympy.core.expr.Expr",
"Protocol": ("obj", "typing.Protocol"),
}
The second, api_target_types
, is useful when you want to redirect the reference type. This is for instance useful when Sphinx thinks the reference is a class
, but it should be an obj
:
api_target_types: dict[str, str] = {
"RangeDefinition": "obj",
}
The extension can also link to the source code on GitHub through the sphinx.ext.linkcode
extension. To activate, specify the GitHub organization and the repository name as follows:
api_github_repo: str = "ComPWA/sphinx-api-relink"
Set api_linkcode_debug = True
to print the generated URLs to the console.
To generate the API for sphinx.ext.autodoc
, add this to your conf.py
:
generate_apidoc_package_path = "../src/my_package" # relative to conf.py
Multiple packages can be listed as well:
generate_apidoc_package_path = [
"../src/package1",
"../src/package2",
]
The API is generated with the same style used by the ComPWA repositories (see e.g. ampform.rtfd.io/en/stable/api/ampform.html). To use the default template, set:
generate_apidoc_use_compwa_template = False
Other configuration values (with their defaults):
generate_apidoc_directory = "api"
generate_apidoc_excludes = ["version.py"]
FAQs
Relink type hints in your Sphinx API
We found that sphinx-api-relink demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.