diff --git a/docs/docs/repositories.md b/docs/docs/repositories.md index 9519668f25a..2ae35fcd75e 100644 --- a/docs/docs/repositories.md +++ b/docs/docs/repositories.md @@ -54,7 +54,11 @@ with the `--username` and `--password` options. Now that you can publish to your private repository, you need to be able to install dependencies from it. -For that, you have to edit your `pyproject.toml` file, like so +By default, Poetry uses all repositories configured as shown above for package +installation. + +If you would like to use a repository that was not configured like above, you have to +edit your `pyproject.toml` file, like so ```toml [[tool.poetry.source]] diff --git a/poetry/poetry.py b/poetry/poetry.py index f9b93cad4a9..6b8cf14180a 100644 --- a/poetry/poetry.py +++ b/poetry/poetry.py @@ -46,6 +46,17 @@ def __init__( for source in self._local_config.get("source", []): self._pool.add_repository(self.create_legacy_repository(source)) + # Add any additional repositories configured globally as source + # This is done after local config sources and before PyPI + extra_repositories = self._config.setting("repositories", default={}) + for repository_name, repository_config in extra_repositories.items(): + if "url" in repository_config: + self._pool.add_repository( + self.create_legacy_repository( + {"name": repository_name, "url": repository_config["url"]} + ) + ) + # Always put PyPI last to prefer private repositories self._pool.add_repository(PyPiRepository()) diff --git a/tests/fixtures/config_with_repositories/auth.toml b/tests/fixtures/config_with_repositories/auth.toml new file mode 100644 index 00000000000..2057b10d388 --- /dev/null +++ b/tests/fixtures/config_with_repositories/auth.toml @@ -0,0 +1 @@ +[http-basic] \ No newline at end of file diff --git a/tests/fixtures/config_with_repositories/config.toml b/tests/fixtures/config_with_repositories/config.toml new file mode 100644 index 00000000000..b0abd1aa41d --- /dev/null +++ b/tests/fixtures/config_with_repositories/config.toml @@ -0,0 +1,5 @@ +[settings] + +[repositories] +[repositories.foo] +url = "https://baz.com" diff --git a/tests/fixtures/simple_project/pyproject.toml b/tests/fixtures/simple_project/pyproject.toml index cbaa386c742..fc5bc718f58 100644 --- a/tests/fixtures/simple_project/pyproject.toml +++ b/tests/fixtures/simple_project/pyproject.toml @@ -23,3 +23,8 @@ classifiers = [ # Requirements [tool.poetry.dependencies] python = "~2.7 || ^3.6" + +# Extra Source +[[tool.poetry.source]] +name = "foo" +url = "https://bar.com" diff --git a/tests/test_poetry.py b/tests/test_poetry.py index 62537920a3b..ac73a85a129 100644 --- a/tests/test_poetry.py +++ b/tests/test_poetry.py @@ -3,10 +3,16 @@ from __future__ import unicode_literals from poetry.poetry import Poetry +from poetry.repositories.pypi_repository import PyPiRepository from poetry.utils._compat import PY2 from poetry.utils._compat import Path from poetry.utils.toml_file import TomlFile +if PY2: + from mock import patch +else: + from unittest.mock import patch + fixtures_dir = Path(__file__).parent / "fixtures" @@ -152,3 +158,23 @@ def test_check_fails(): ) assert Poetry.check(content) == {"errors": [expected], "warnings": []} + + +@patch("poetry.config.CONFIG_DIR", fixtures_dir / "config_with_repositories") +def test_sources(): + poetry = Poetry.create(str(fixtures_dir / "simple_project")) + repositories = [ + r._url for r in poetry.pool.repositories if isinstance(r, PyPiRepository) + ] + + source_local = "https://bar.com" + source_global = "https://baz.com" + source_pypi = "https://pypi.org/" + + assert source_local in repositories + assert source_global in repositories + assert source_pypi in repositories + + assert repositories.index(source_local) < repositories.index(source_global) + assert repositories.index(source_global) < repositories.index(source_pypi) + assert repositories.index(source_pypi) == len(repositories) - 1