Skip to content

Commit

Permalink
Fix installation with non-PyPI default repository
Browse files Browse the repository at this point in the history
Co-authored-by: rusty <rusty@spoqa.com>
  • Loading branch information
sdispater and rusty committed Jul 5, 2019
1 parent d78b57f commit 6f4aa21
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
18 changes: 8 additions & 10 deletions poetry/installation/pip_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

from subprocess import CalledProcessError

from clikit.api.io import IO
from clikit.io import NullIO

from poetry.config import Config
from poetry.utils.helpers import get_http_basic_auth
from poetry.utils.helpers import safe_rmtree


Expand All @@ -15,19 +14,15 @@
except ImportError:
import urlparse

from poetry.repositories.pool import Pool
from poetry.utils._compat import encode
from poetry.utils.env import Env

from .base_installer import BaseInstaller


class PipInstaller(BaseInstaller):
def __init__(
self,
env, # type: Env
io,
pool,
): # type: (...) -> None
def __init__(self, env, io, pool): # type: (Env, IO, Pool) -> None
self._env = env
self._io = io
self._pool = pool
Expand Down Expand Up @@ -60,8 +55,11 @@ def install(self, package, update=False):

args += ["--index-url", index_url]
if self._pool.has_default():
if repository.name != self._pool.default.name:
args += ["--extra-index-url", self._pool.default.authenticated_url]
if repository.name != self._pool.repositories[0].name:
args += [
"--extra-index-url",
self._pool.repositories[0].authenticated_url,
]

if update:
args.append("-U")
Expand Down
25 changes: 25 additions & 0 deletions tests/installation/test_pip_installer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from poetry.installation.pip_installer import PipInstaller
from poetry.io.null_io import NullIO
from poetry.packages.package import Package
from poetry.repositories.legacy_repository import LegacyRepository
from poetry.repositories.pool import Pool
from poetry.utils.env import NullEnv

Expand All @@ -23,3 +24,27 @@ def test_requirement():
)

assert expected == result


def test_install_with_non_pypi_default_repository():

This comment has been minimized.

Copy link
@areeh

areeh Jul 10, 2019

Thanks for this

pool = Pool()

default = LegacyRepository("default", "https://default.com")
another = LegacyRepository("another", "https://another.com")

pool.add_repository(default, default=True)
pool.add_repository(another)

installer = PipInstaller(NullEnv(), NullIO(), pool)

foo = Package("foo", "0.0.0")
foo.source_type = "legacy"
foo.source_reference = default._name
foo.source_url = default._url
bar = Package("bar", "0.1.0")
bar.source_type = "legacy"
bar.source_reference = another._name
bar.source_url = another._url

installer.install(foo)
installer.install(bar)

0 comments on commit 6f4aa21

Please sign in to comment.