How to init the pyproject.toml file
Asked Answered
C

1

2

I found that python can use pyproject.toml to list dependencies instead of requirements.txt file. It's more convenient and is very similar to package.json for node.However, I could not find a documentation to init the pyproject.toml file much like the npm init command. How to autogenerate the file with virtualenv or pip? also, is there a way to autoupdate the toml file, as the packagaes get installed, much like npm --save tag, that saves the package to the package.json as its installed?

Clinkstone answered 14/2, 2020 at 15:19 Comment(8)
Look into a project called poetry it can do it for you quiet neatly.Oligocene
I feel like Pipenv is more closer to having a package.jsonConfectionery
Agree, but not to the pyproject toml as of the upcoming standardisationOligocene
python.org/dev/peps/pep-0518/#specificationDimorph
poetry init in the project root dir, answer the questions, done.Eucharist
What are you asking exactly? There are many tools that store configuration in that file. poetry is one of them, so is flit, and a bunch of others. Some can cohabit peacefully, some might not. From the details in your question, poetry might be indeed a strong candidate, but it has its own quirks and limitations, so you have to make sure it is what you want to buy. But really a pyproject.toml is just 2 or 3 lines (the [build-system] section) as per the specification @Dimorph linked to in its comment. Every other section in that file is most likely specific to a tool and non standard.Buoyant
Maybe there is a cookiecutter somewhere that allows you to choose a build-system (poetry, filt, setuptools, etc.) interactively and populate the pyproject.toml accordingly.Buoyant
You could give PDM a try. It has an init feature: pdm.fming.dev/latest/usage/hooks/#initializationPerseid
O
2

Look at poetry. It can do it for you nicely. Actually I think its the only project that handles this already that I know of.

Oligocene answered 14/2, 2020 at 15:21 Comment(2)
Yeah, the toml files are not natively supported by pythonConfectionery
TOML is now natively supported in Python (as of 3.11). :-) An alternative to poetry that has full support for the pyproject.toml file is pdm: pdm.fming.dev/latestPerseid

© 2022 - 2024 — McMap. All rights reserved.