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

Fix #1791: Load repository URL from config #2061

Merged
merged 4 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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