Skip to content

Commit

Permalink
Fix #1791: Load repository URL from config (#2061)
Browse files Browse the repository at this point in the history
* Fix #1791: Load repository URL from config

* Ran black to fix linting errors

* Add test for repo URL env variable
  • Loading branch information
thejcannon authored Feb 21, 2020
1 parent 46a1103 commit 04a1544
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
8 changes: 2 additions & 6 deletions poetry/masonry/publishing/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions tests/masonry/publishing/test_publisher.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import pytest

from poetry.factory import Factory
Expand Down Expand Up @@ -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

0 comments on commit 04a1544

Please sign in to comment.