Skip to content

Commit 04a1544

Browse files
authored
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
1 parent 46a1103 commit 04a1544

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

poetry/masonry/publishing/publisher.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,12 @@ def publish(self, repository_name, username, password, cert=None, client_cert=No
4949
repository_name = "pypi"
5050
else:
5151
# Retrieving config information
52-
repository = self._poetry.config.get(
53-
"repositories.{}".format(repository_name)
54-
)
55-
if repository is None:
52+
url = self._poetry.config.get("repositories.{}.url".format(repository_name))
53+
if url is None:
5654
raise RuntimeError(
5755
"Repository {} is not defined".format(repository_name)
5856
)
5957

60-
url = repository["url"]
61-
6258
if not (username and password):
6359
# Check if we have a token first
6460
token = self._password_manager.get_pypi_token(repository_name)

tests/masonry/publishing/test_publisher.py

+20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
import pytest
24

35
from poetry.factory import Factory
@@ -119,3 +121,21 @@ def test_publish_uses_client_cert(fixture_dir, mocker, config):
119121
("https://foo.bar",),
120122
{"cert": None, "client_cert": Path(client_cert)},
121123
] == uploader_upload.call_args
124+
125+
126+
def test_publish_read_from_environment_variable(fixture_dir, environ, mocker, config):
127+
os.environ["POETRY_REPOSITORIES_FOO_URL"] = "https://foo.bar"
128+
os.environ["POETRY_HTTP_BASIC_FOO_USERNAME"] = "bar"
129+
os.environ["POETRY_HTTP_BASIC_FOO_PASSWORD"] = "baz"
130+
uploader_auth = mocker.patch("poetry.masonry.publishing.uploader.Uploader.auth")
131+
uploader_upload = mocker.patch("poetry.masonry.publishing.uploader.Uploader.upload")
132+
poetry = Factory().create_poetry(fixture_dir("sample_project"))
133+
publisher = Publisher(poetry, NullIO())
134+
135+
publisher.publish("foo", None, None)
136+
137+
assert [("bar", "baz")] == uploader_auth.call_args
138+
assert [
139+
("https://foo.bar",),
140+
{"cert": None, "client_cert": None},
141+
] == uploader_upload.call_args

0 commit comments

Comments
 (0)