Commit 04a15441 by Joshua Cannon Committed by GitHub

Fix #1791: Load repository URL from config (#2061)

* Fix #1791: Load repository URL from config

* Ran black to fix linting errors

* Add test for repo URL env variable
parent 46a11037
...@@ -49,16 +49,12 @@ class Publisher: ...@@ -49,16 +49,12 @@ class Publisher:
repository_name = "pypi" repository_name = "pypi"
else: else:
# Retrieving config information # Retrieving config information
repository = self._poetry.config.get( url = self._poetry.config.get("repositories.{}.url".format(repository_name))
"repositories.{}".format(repository_name) if url is None:
)
if repository is None:
raise RuntimeError( raise RuntimeError(
"Repository {} is not defined".format(repository_name) "Repository {} is not defined".format(repository_name)
) )
url = repository["url"]
if not (username and password): if not (username and password):
# Check if we have a token first # Check if we have a token first
token = self._password_manager.get_pypi_token(repository_name) token = self._password_manager.get_pypi_token(repository_name)
......
import os
import pytest import pytest
from poetry.factory import Factory from poetry.factory import Factory
...@@ -119,3 +121,21 @@ def test_publish_uses_client_cert(fixture_dir, mocker, config): ...@@ -119,3 +121,21 @@ def test_publish_uses_client_cert(fixture_dir, mocker, config):
("https://foo.bar",), ("https://foo.bar",),
{"cert": None, "client_cert": Path(client_cert)}, {"cert": None, "client_cert": Path(client_cert)},
] == uploader_upload.call_args ] == uploader_upload.call_args
def test_publish_read_from_environment_variable(fixture_dir, environ, mocker, config):
os.environ["POETRY_REPOSITORIES_FOO_URL"] = "https://foo.bar"
os.environ["POETRY_HTTP_BASIC_FOO_USERNAME"] = "bar"
os.environ["POETRY_HTTP_BASIC_FOO_PASSWORD"] = "baz"
uploader_auth = mocker.patch("poetry.masonry.publishing.uploader.Uploader.auth")
uploader_upload = mocker.patch("poetry.masonry.publishing.uploader.Uploader.upload")
poetry = Factory().create_poetry(fixture_dir("sample_project"))
publisher = Publisher(poetry, NullIO())
publisher.publish("foo", None, None)
assert [("bar", "baz")] == uploader_auth.call_args
assert [
("https://foo.bar",),
{"cert": None, "client_cert": None},
] == uploader_upload.call_args
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment