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

Use configured repositories as sources by default #562

Closed
Closed
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
6 changes: 5 additions & 1 deletion docs/docs/repositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
11 changes: 11 additions & 0 deletions poetry/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/config_with_repositories/auth.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[http-basic]
5 changes: 5 additions & 0 deletions tests/fixtures/config_with_repositories/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[settings]

[repositories]
[repositories.foo]
url = "https://baz.com"
5 changes: 5 additions & 0 deletions tests/fixtures/simple_project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ classifiers = [
# Requirements
[tool.poetry.dependencies]
python = "~2.7 || ^3.4"

# Extra Source
[[tool.poetry.source]]
name = "foo"
url = "https://bar.com"
26 changes: 26 additions & 0 deletions tests/test_poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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