-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
-
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 (
-vvvoption). -
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
poetry/poetry/console/commands/config.py
Lines 168 to 170 in 754dbf8
| config.config_source.add_property( | |
| "repositories.{}.url".format(m.group(1)), url | |
| ) |
transforms
"repositories.<name>" into "repositories.<name>.url", and the following code for publishingpoetry/poetry/masonry/publishing/publisher.py
Lines 51 to 56 in 754dbf8
| # Retrieving config information | |
| url = self._poetry.config.get("repositories.{}.url".format(repository_name)) | |
| if url is None: | |
| raise RuntimeError( | |
| "Repository {} is not defined".format(repository_name) | |
| ) |
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":
poetry/poetry/config/config.py
Lines 109 to 115 in 754dbf8
| if self._use_environment: | |
| env = "POETRY_{}".format( | |
| "_".join(k.upper().replace("-", "_") for k in keys) | |
| ) | |
| value = os.getenv(env, _NOT_SET) | |
| if value is not _NOT_SET: | |
| return self.process(self._get_normalizer(setting_name)(value)) |
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
.urldoes 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>.urlwhen 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.