Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Oct 28, 2024
1 parent 4c07eb8 commit 0c9fd3c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ For example:
{directive="spec", title="Specification", prefix="S_", color="#FEDCD2", style="node"},
]
To specify a different `table path <https://toml.io/en/v1.0.0#table>`__ to read from in the toml file, use the ``needs_from_toml_table`` option.
To specify a different `root table path <https://toml.io/en/v1.0.0#table>`__ to read from in the toml file, use the ``needs_from_toml_table`` option.
For example to read from a ``[tool.needs]`` table:

.. code-block:: python
needs_from_toml_table = ["tool", "needs"]
needs_from_toml_table = ["tool"]
.. caution:: Any configuration specifying relative paths in the toml file will be resolved relative to the directory containing the :file:`conf.py` file.

Expand Down Expand Up @@ -258,8 +258,12 @@ And use it like:

.. versionadded:: 4.1.0

Values in the list can also be dictionaries, allowing for setting a description of an option
that will be output in the schema of the :ref:`needs.json <needs_builder_format>`.
Values in the list can also be dictionaries, with keys:

* ``name``: The name of the option (required).
* ``description``: A description of the option (optional).
This will be output in the schema of the :ref:`needs.json <needs_builder_format>`,
and can be used by other tools.

For example:

Expand Down
4 changes: 2 additions & 2 deletions sphinx_needs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,9 @@ def get_default(cls, name: str) -> Any:
"""Path to a TOML file to load configuration from."""

from_toml_table: list[str] = field(
default_factory=lambda: ["needs"], metadata={"rebuild": "env", "types": (list,)}
default_factory=list, metadata={"rebuild": "env", "types": (list,)}
)
"""Path to the table in the toml file to load configuration from."""
"""Path to the root table in the toml file to load configuration from."""

types: list[NeedType] = field(
default_factory=lambda: [
Expand Down
2 changes: 1 addition & 1 deletion sphinx_needs/needs.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def load_config_from_toml(app: Sphinx, config: Config) -> None:
try:
with toml_file.open("rb") as f:
toml_data = tomllib.load(f)
for key in toml_path:
for key in (*toml_path, "needs"):
toml_data = toml_data[key]
assert isinstance(toml_data, dict), "Data must be a dict"
except Exception as e:
Expand Down

0 comments on commit 0c9fd3c

Please sign in to comment.