poetry icon indicating copy to clipboard operation
poetry copied to clipboard

[docs] configuration documentation does not specify the precedence of each method

Open danielknell opened this issue 4 years ago • 3 comments

  • [x] I have searched the issues of this repo and believe that this is not a duplicate.

Issue

https://python-poetry.org/docs/configuration/ specifies which methods are availible to configure poetry, but does not specify the precedence of the options.

e.g. if a value is set via both poetry config, poetry config --local, and an environment variable, the documentation does not specify which method will be picked.

(local trumping global is obvious, but local vs env is less so)

looking at the code it looks like the sources have the following priority (top wins):

  • environment var
  • ./poetry.toml
  • ~/.config/pypoetry/auth.toml
  • ~/.config/pypoetry/config.toml

it would be nice to have this formalised so we can be confident it wont change without warning.

danielknell avatar Jan 12 '22 14:01 danielknell

I had the same question and, as you said, the docs do not state precedence. However, I came to a different conclusion while trying to set credentials via environment variables: POETRY_HTTP_BASIC_REPO_USERNAME and POETRY_HTTP_BASIC_REPO_PASSWORD are ignored unless I run poetry config --unset http-basic.repo

nschrader avatar Jan 16 '22 19:01 nschrader

https://github.com/python-poetry/poetry/blob/master/src/poetry/config/config.py#L114 code very much prioritises environment.

danielknell avatar Jan 21 '22 18:01 danielknell

Okay, this is really a detail. See https://github.com/python-poetry/poetry/blob/335f209c2dd96cb33e75279c4a52cb25b1966bc3/src/poetry/utils/password_manager.py#L155 If you have configured your authentication to use a keyring e.g. poetry config http-basic.repo http://some.repo then you cannot supersede the password by an environment variable. When a config http-basic.repo is found, only the keyring will be inquired. To make environment variables work with HTTP Basic passwords, you must only set http-basic.repo.username and use POETRY_HTTP_BASIC_REPO_PASSWORD subsequently.

There might be a way to supersede http-basic.repo directly by POETRY_HTTP_BASIC_REPO with a Python dict, but I didn't test it out.

nschrader avatar Jan 21 '22 23:01 nschrader