question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

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.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
4F2E4A2Ecommented, Aug 19, 2020

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

0reactions
assuiedmilancommented, Aug 26, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python poetry install failure - invalid hashes
There are several issue reports about invalid hashes. One common cause is running multiple Poetry instances simultaneously; ...
Read more >
Configuration | Documentation
The environment variables must be prefixed by POETRY_ and are comprised of the uppercase name of the setting and with dots and dashes...
Read more >
Making Python Packages Part 2: How to Publish & Test ...
In the last edition of this guide, we published a python package to PyPI using a traditional ... then we can run that...
Read more >
How to Publish Your Python Package with just 2 commands
You can publish it using Poetry. This post will show you how to build your own Python library and publish it on the...
Read more >
Python packaging and dependency management using ...
Poetry is a tool for dependency management and packaging in Python. ... option or by setting the POETRY_UNINSTALL environment variable before executing the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found