Any reliable way to refer to the manifest file when building using `build.py`?

I am writing a C extension module as a library targetting >=Python 3.8.

I am using a build.py with poetry as the build tool.
I would very much love to have the project metadata all residing within the pyproject.toml manifest file.

However, this is not entirely possible because the standard library shipped in Python 3.8 does not include a TOML parser, hence I would need to hardcode some of these metadata into build.py. For example, I might want to refer to the package name defined in the manifest file instead of hardcoding it in build.py.

Just curious if there are any more reliable ways to do this.

IDK of poerty exposes some api for this, but you always just have a conditional build time dependency on some toml parser, same way you have a build time dependency on poetry.

For some toml parser, you can use tomli, the project that became tomllib and now acts as a backport. See “Building a tomli/tomllib compatibility layer” in tomli’s readme.

2 Likes