1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
from __future__ import annotations
import ast
import textwrap
from typing import Any
from docutils import nodes
from docutils.statemachine import StringList
from sphinx.util.docutils import SphinxDirective
class ConfTabs(SphinxDirective):
required_arguments = 2
final_argument_whitespace = True
def run(self) -> list[nodes.Node]:
name, result = self.arguments
env_name = f"SKBUILD_{name.replace('.', '_').replace('-', '_').upper()}"
value_result = ast.literal_eval(result)
if isinstance(value_result, list):
joined_result = ";".join(value_result)
elif isinstance(value_result, bool):
result = joined_result = "true" if value_result else "false"
else:
joined_result = result
pyproject = textwrap.dedent(
f"""\
````{{tab}} pyproject.toml
```toml
[tool.scikit-build]
{name} = {result}
```
````
`````{{tab}} config-settings
````{{tab}} pip
```console
$ pip install . --config-settings={name}={joined_result}
```
````
````{{tab}} build
```console
$ pipx run build --wheel -C{name}={joined_result}
```
````
````{{tab}} cibuildwheel
```toml
[tool.cibuildwheel.config-settings]
"{name}" = {result}
```
````
`````
````{{tab}} Environment
```yaml
{env_name}: "{joined_result}"
```
````
"""
)
content = nodes.container("")
self.state.nested_parse(
StringList(pyproject.splitlines()), self.content_offset, content
)
return [content]
def setup(app: Any) -> dict[str, Any]:
app.add_directive("conftabs", ConfTabs)
return {
"version": "0.1",
"parallel_read_safe": True,
"parallel_write_safe": True,
}
|