diff --git a/poetry/masonry/publishing/publisher.py b/poetry/masonry/publishing/publisher.py index 3ff39a7c840..b62b3addbe6 100644 --- a/poetry/masonry/publishing/publisher.py +++ b/poetry/masonry/publishing/publisher.py @@ -49,16 +49,12 @@ def publish(self, repository_name, username, password, cert=None, client_cert=No repository_name = "pypi" else: # Retrieving config information - repository = self._poetry.config.get( - "repositories.{}".format(repository_name) - ) - if repository is None: + url = self._poetry.config.get("repositories.{}.url".format(repository_name)) + if url is None: raise RuntimeError( "Repository {} is not defined".format(repository_name) ) - url = repository["url"] - if not (username and password): # Check if we have a token first token = self._password_manager.get_pypi_token(repository_name) diff --git a/tests/masonry/publishing/test_publisher.py b/tests/masonry/publishing/test_publisher.py index 4058e255ae4..18af37f1636 100644 --- a/tests/masonry/publishing/test_publisher.py +++ b/tests/masonry/publishing/test_publisher.py @@ -1,3 +1,5 @@ +import os + import pytest from poetry.factory import Factory @@ -119,3 +121,21 @@ def test_publish_uses_client_cert(fixture_dir, mocker, config): ("https://foo.bar",), {"cert": None, "client_cert": Path(client_cert)}, ] == 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