Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError thrown when executing poetry publish -r <name> with environment variable POETRY_REPOSITORIES_<NAME> set #2204

Closed
3 tasks done
esciara opened this issue Mar 19, 2020 · 7 comments · Fixed by #9121
Labels
area/publishing Related to PyPI/PEP 503 publishing kind/bug Something isn't working as expected

Comments

@esciara
Copy link

esciara commented Mar 19, 2020

  • 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

config.config_source.add_property(
"repositories.{}.url".format(m.group(1)), url
)

transforms "repositories.<name>" into "repositories.<name>.url", and the following code for publishing
# 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":

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 .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

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 for repositories.<name>
  • 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

Any preferred option? My personal vote goes as first best for option 2 with an upgrade process and as second best to option 3.

@esciara esciara added the kind/bug Something isn't working as expected label Mar 19, 2020
@esciara esciara changed the title Environment variable POETRY_REPOSITORIES_<NAME> not taken into account by poetry publish -r <name> Environment variable POETRY_REPOSITORIES_<NAME> not taken into account by poetry publish -r <name> (RuntimeError thrown) Mar 19, 2020
@esciara esciara changed the title Environment variable POETRY_REPOSITORIES_<NAME> not taken into account by poetry publish -r <name> (RuntimeError thrown) RuntimeError thrown when executing poetry publish -r <name> with environment variable POETRY_REPOSITORIES_<NAME> set Mar 19, 2020
@janjagusch
Copy link

janjagusch commented Jul 1, 2020

Thank you for the excellent issue description! I encountered the same issue on Poetry 1.0.9 and your workaround worked like a charm.

@finswimmer finswimmer added area/publishing Related to PyPI/PEP 503 publishing status/triage This issue needs to be triaged labels Jul 1, 2020
@4F2E4A2E
Copy link

For us it's working the following way :

  • config: poetry config repositories.acme http://localhost:8080/repository/acme-pypi/
  • config: poetry config http-basic.acme <user> <password>
  • build: poetry build
  • publish: poetry publish -r acme

Poetry version 1.0.5

@abn
Copy link
Member

abn commented Aug 19, 2020

Most likely related: #2359 #2210

@spencercjh
Copy link

Had the same problem 😭

@assuiedmilan
Copy link

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 work

Repository is not defined

url = self._poetry.config.get("repositories.{}.url".format(repository_name))

Would be great to see it fixed soon, moving to twine in the meantime

abn added a commit to abn/poetry that referenced this issue Mar 5, 2024
@abn abn removed the status/triage This issue needs to be triaged label Mar 5, 2024
@abn
Copy link
Member

abn commented Mar 5, 2024

This is a documentation issue. The expected env var is POETRY_REPOSITORIES_<NAME>_URL for the url configuration.

#9121 should resolve documentation issue.

@abn abn closed this as completed Mar 5, 2024
Copy link

github-actions bot commented Apr 5, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/publishing Related to PyPI/PEP 503 publishing kind/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants