python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
31.7k stars 2.27k forks source link

Offer Some Way to Validate poetry.toml #4644

Open Kurt-von-Laven opened 3 years ago

Kurt-von-Laven commented 3 years ago

Feature Request

poetry check is great for validating pyproject.toml. It would be helpful to have some way to validate poetry.toml as well. poetry check could validate both files by default, and a new optional option could be introduced to specify the path to the file to check.

kkirsche commented 2 years ago

So working backward from the request, the check command is here: https://github.com/python-poetry/poetry/blob/master/src/poetry/console/commands/check.py

This loads the PyProject.toml file using: https://github.com/python-poetry/poetry-core/blob/master/src/poetry/core/pyproject/toml.py

And then calls the validate strict method from the Factory class. This is actually an inherited method though from BaseFactory here: https://github.com/python-poetry/poetry-core/blob/master/src/poetry/core/factory.py#L375

Now, if we look at how the config command works, it loads poetry.toml first here: https://github.com/python-poetry/poetry/blob/master/src/poetry/factory.py#L50-L55

This seems to be the case before based on the fact the configuration file output from above shows up in the command output https://github.com/python-poetry/poetry/blob/master/src/poetry/console/commands/config.py#L107

Output:

❯ poetry config --list -vvv
Loading configuration file /Users/REDACTED/Library/Application Support/pypoetry/config.toml
cache-dir = "/Users/REDACTED/Library/Caches/pypoetry"
experimental.new-installer = true
installer.parallel = true
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.path = "{cache-dir}/virtualenvs"  # /Users/REDACTED/Library/Caches/pypoetry/virtualenvs

So it looks easy enough to do, mostly just add new keys to validate and then extend the check command to merge the configurations, but I'd be curious what the team is thinking in terms of structuring this. E.g. do you want separate validation methods for different configuration types (pyproject, poetry, etc.) or extend the main one as the application uses the configurations as if they're one from an object perspective

Kurt-von-Laven commented 2 years ago

My personal preference as a user would be that the existing check command validate both pyproject.toml and poetry.toml by default.

Phil305 commented 2 years ago

Hey guys, quick question that I didn't see answered in the online docs; what is the poetry.toml file?

I ran poetry config --local virtualenvs.in-project true to create virtualenv in my project, expecting pyproject.toml to get updated, and instead saw the new file in my Git working tree.

Thanks, sorry if it actually is in the docs and I missed it 🙂

finswimmer commented 2 years ago

what is the poetry.toml file?

poetry.toml is for storing local poetry config settings. So you are able to have different poetry settings per project. Because application settings are usually specific to the user, we don't store this in the pyproject.toml. Otherwise one cannot separate project specific data you usually want to share and application settings you don't want to share.

A section in the docs about this file seems to be missing. PR is welcome ;)

Phil305 commented 2 years ago

@finswimmer Cool sounds good 👍🏿

I haven't looked, but assuming docs built with Sphinx? I should be able to do PR tmrw after work or next Monday 🙏🏿