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

pool: ensure sources are prioritised over PyPI #3251

Merged
merged 1 commit into from
Oct 23, 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
6 changes: 4 additions & 2 deletions poetry/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def create_poetry(
)

# Configuring sources
for source in poetry.local_config.get("source", []):
sources = poetry.local_config.get("source", [])
for source in sources:
repository = self.create_legacy_repository(source, config)
is_default = source.get("default", False)
is_secondary = source.get("secondary", False)
Expand All @@ -90,7 +91,8 @@ def create_poetry(
# Always put PyPI last to prefer private repositories
# but only if we have no other default source
if not poetry.pool.has_default():
poetry.pool.add_repository(PyPiRepository(), True)
has_sources = bool(sources)
poetry.pool.add_repository(PyPiRepository(), not has_sources, has_sources)
else:
if io.is_debug():
io.write_line("Deactivating the PyPI repository")
Expand Down
18 changes: 18 additions & 0 deletions tests/fixtures/with_non_default_source/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[tool.poetry]
name = "my-package"
version = "1.2.3"
description = "Some description."
authors = [
"Your Name <you@example.com>"
]
license = "MIT"

# Requirements
[tool.poetry.dependencies]
python = "~2.7 || ^3.6"

[tool.poetry.dev-dependencies]

[[tool.poetry.source]]
name = "foo"
url = "https://foo.bar/simple/"
27 changes: 27 additions & 0 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from poetry.core.toml.file import TOMLFile
from poetry.factory import Factory
from poetry.repositories.legacy_repository import LegacyRepository
from poetry.repositories.pypi_repository import PyPiRepository
from poetry.utils._compat import PY2
from poetry.utils._compat import Path

Expand Down Expand Up @@ -150,6 +152,31 @@ def test_poetry_with_default_source():
assert 1 == len(poetry.pool.repositories)


def test_poetry_with_non_default_source():
poetry = Factory().create_poetry(fixtures_dir / "with_non_default_source")

assert len(poetry.pool.repositories) == 2

assert not poetry.pool.has_default()

assert poetry.pool.repositories[0].name == "foo"
assert isinstance(poetry.pool.repositories[0], LegacyRepository)

assert poetry.pool.repositories[1].name == "PyPI"
assert isinstance(poetry.pool.repositories[1], PyPiRepository)


def test_poetry_with_no_default_source():
poetry = Factory().create_poetry(fixtures_dir / "sample_project")

assert len(poetry.pool.repositories) == 1

assert poetry.pool.has_default()

assert poetry.pool.repositories[0].name == "PyPI"
assert isinstance(poetry.pool.repositories[0], PyPiRepository)


def test_poetry_with_two_default_sources():
with pytest.raises(ValueError) as e:
Factory().create_poetry(fixtures_dir / "with_two_default_sources")
Expand Down