Can I add custom data to a pyproject.toml file
Asked Answered
M

1

6

I am using the toml package to read my pyproject.toml file. I want to add custom data which in this case I will read in my docs/conf.py file. When I try and add a custom section I get errors and warnings from Even Better TOML extension in Vs Code stating that my custom data is no allowed.

Example TOML section in pyproject.toml

[custom.metadata]
docs_name = "GUI Automation for windows"
docs_author = "myname"
docs_copyright = "2023"
docs_url= "https://someurl.readthedocs.io/en/latest/"

So, my question is: Is there a valid way of adding custom data to a pyproject.toml file?

Milena answered 17/8, 2023 at 20:22 Comment(1)
Note that the pyproject.toml file is never installed. It is only available in your source code repository and in the source distributions (sdists).Gomar
K
6

Use a [tool.*] table.

Quoting PEP 518:

The [tool] table is where any tool related to your Python project, not just build tools, can have users specify configuration data as long as they use a sub-table within [tool], e.g. the flit tool would store its configuration in [tool.flit].

Any tools that interpret pyproject.toml files will expect the [tool] sub-tables to contain arbitrary, tool-specific metadata. You should not have any issues populating a custom subtable with whatever project metadata you need.

In your case, something like this should work warning-free:

[tool.my_distribution_name]
docs_name = "GUI Automation for windows"
docs_author = "myname"
docs_copyright = "2023"
docs_url= "https://someurl.readthedocs.io/en/latest/"

Creating your own custom table is not permitted, since PEP 518 reserves all top-level tables in pyproject.toml:

Tables not specified in this PEP are reserved for future use by other PEPs.

Khalif answered 17/8, 2023 at 22:51 Comment(1)
Works great thank you. My repo can be found here github.com/Amourspirit/python-ooo-dev-tools-gui-win for anyone that wants to see an example of this.Milena

© 2022 - 2024 — McMap. All rights reserved.