Skip to content

Commit

Permalink
Use configured repositories as sources by default
Browse files Browse the repository at this point in the history
This change adds globally configured extra repositories from config.toml
as dependency sources. These are added after project specific sources
and before PyPI.
  • Loading branch information
abn committed Oct 25, 2018
1 parent 475c657 commit 735b696
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
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
9 changes: 9 additions & 0 deletions poetry/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ def __init__(
for source in self._local_config.get("source", []):
self._pool.configure(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.configure(
{"name": repository_name, "url": repository_config["url"]}
)

# Always put PyPI last to prefere 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.6"

# 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 @@ -156,3 +162,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

0 comments on commit 735b696

Please sign in to comment.