RuntimeError thrown when executing `poetry publish -r <name>` with environment variable `POETRY_REPOSITORIES_<NAME>` set
See original GitHub issue-
I am on the latest Poetry version.
-
I have searched the issues of this repo and believe that this is not a duplicate.
-
If an exception occurs when executing a command, I executed it again in debug mode (
-vvv
option). -
OS version and name: 10.15.3 Mac OS X
-
Poetry version: 1.0.5
-
Link of a Gist with the contents of your pyproject.toml file: https://gist.github.com/esciara/dfc058348e597f8586d4f678cc163182
Issue
According to the doc on using environment variables for configuration, I should be able to declare an alternative package repository to publish to by setting an environment variable of format POETRY_REPOSITORIES_<NAME>
(like POETRY_REPOSITORIES_MYREPO
).
However, when running the following commands:
$ export POETRY_REPOSITORIES_MYREPO=http://myrepo.url
$ poetry publish -r myrepo
The following error is thrown:
[RuntimeError]
Repository myrepo is not defined
This is due to the fact that the following code for storing the config
https://github.com/python-poetry/poetry/blob/754dbf80dc022b89974288cff10b40ab2f1c2697/poetry/console/commands/config.py#L168-L170
transforms "repositories.<name>"
into "repositories.<name>.url"
, and the following code for publishing
https://github.com/python-poetry/poetry/blob/754dbf80dc022b89974288cff10b40ab2f1c2697/poetry/masonry/publishing/publisher.py#L51-L56
looks for "repositories.<name>.url"
.
However, the code handling environment variables (in the poetry.config.config.Config.get
method) does not treat the POETRY_REPOSITORIES_<NAME>
environment variables in any particular way, and hence presents with an equivalent to "repositories.<name>"
, not "repositories.<name>.url"
:
https://github.com/python-poetry/poetry/blob/754dbf80dc022b89974288cff10b40ab2f1c2697/poetry/config/config.py#L109-L115
Workaround
A workaround to this is to add _URL
as a suffix to the variables (here POETRY_REPOSITORIES_MYREPO_URL
), but this does not follow the simple and elegant rule for setting poetry though environment variables as defined in the doc.
Corrective options
There are several way this could be corrected:
Option 1: change the config setting repositories.<name>
to repositories.<name>.url
- Pros:
- does not change current way the settings are stored
- backwards compatibility for existing scripts (ci/cd and other automation) could be kept by allowing the usage of
repositories.<name>
- Cons:
- the addition of
.url
does not seem to make much sens - appart perhaps for config file readability, which IMHO is questionable - since there is no other setting required to repositories than their url - backward compatibility fix feels a bit like a dirty hack
- the addition of
Option 2: change the config setting storage from repositories.<name>.url
to repositories.<name>
- Pros:
- removes the use of
.url
- backwards compatibility for existing configuration files could be kept by looking also for
repositories.<name>.url
when searching forrepositories.<name>
- removes the use of
- Cons:
- backward compatibility fix feels a bit like a dirty hack, but is probably necessary to not break existing systems (unless an upgrade process is created)
Option 3: apply to the environment variables the same transformation that that to the comfig setting (POETRY_REPOSITORIES_<NAME>
transformed on the fly to the equivalent of POETRY_REPOSITORIES_<NAME>_URL
)
- Pros:
- keeps much of the code the same
- no need for backward compatibility
- Cons:
- does not remove the use of
.url
- does not remove the use of
Any preferred option? My personal vote goes as first best for option 2 with an upgrade process and as second best to option 3.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:5 (1 by maintainers)
For us it’s working the following way :
poetry config repositories.acme http://localhost:8080/repository/acme-pypi/
poetry config http-basic.acme <user> <password>
poetry build
poetry publish -r acme
Poetry version 1.0.5
I am sad to see that this is two years old and not fixed. I am having the same issue, trying to use
poetry publish -r <url> -u <username> -p <password>
to upload to a private repository and it just will not workWould be great to see it fixed soon, moving to twine in the meantime