From 8a7764f5432a9f5657c559cfa149b0899a1ed4d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Fri, 11 Oct 2019 11:04:25 +0200 Subject: [PATCH] Fix git dependencies prereleases resolution (#1458) --- poetry/repositories/repository.py | 8 +++++- tests/conftest.py | 3 +- .../demo/prerelease/prerelease/__init__.py | 0 .../github.com/demo/prerelease/pyproject.toml | 14 ++++++++++ tests/installation/test_installer.py | 28 +++++++++++++++++++ 5 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/git/github.com/demo/prerelease/prerelease/__init__.py create mode 100644 tests/fixtures/git/github.com/demo/prerelease/pyproject.toml diff --git a/poetry/repositories/repository.py b/poetry/repositories/repository.py index 73f1528db71..18590a10a97 100644 --- a/poetry/repositories/repository.py +++ b/poetry/repositories/repository.py @@ -64,7 +64,13 @@ def find_packages( for package in self.packages: if name == package.name: - if package.is_prerelease() and not allow_prereleases: + if ( + package.is_prerelease() + and not allow_prereleases + and not package.source_type + ): + # If prereleases are not allowed and the package is a prerelease + # and is a standard package then we skip it continue if constraint.allows(package.version): diff --git a/tests/conftest.py b/tests/conftest.py index a4f58b0acc8..1b9c12f34b2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -81,7 +81,7 @@ def mock_clone(_, source, dest): parts = urlparse.urlparse(source) folder = ( - Path(__file__).parent.parent + Path(__file__).parent / "fixtures" / "git" / parts.netloc @@ -91,7 +91,6 @@ def mock_clone(_, source, dest): if dest.exists(): shutil.rmtree(str(dest)) - shutil.rmtree(str(dest)) shutil.copytree(str(folder), str(dest)) diff --git a/tests/fixtures/git/github.com/demo/prerelease/prerelease/__init__.py b/tests/fixtures/git/github.com/demo/prerelease/prerelease/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/fixtures/git/github.com/demo/prerelease/pyproject.toml b/tests/fixtures/git/github.com/demo/prerelease/pyproject.toml new file mode 100644 index 00000000000..b06aef85184 --- /dev/null +++ b/tests/fixtures/git/github.com/demo/prerelease/pyproject.toml @@ -0,0 +1,14 @@ +[tool.poetry] +name = "prerelease" +version = "1.0.0.dev0" +description = "Some description." +authors = [ + "Sébastien Eustace " +] +license = "MIT" + +# Requirements +[tool.poetry.dependencies] +python = "~2.7 || ^3.4" + +[tool.poetry.dev-dependencies] diff --git a/tests/installation/test_installer.py b/tests/installation/test_installer.py index c8e9ce140c0..707b4272ca6 100644 --- a/tests/installation/test_installer.py +++ b/tests/installation/test_installer.py @@ -1529,3 +1529,31 @@ def test_run_installs_with_url_file(installer, locker, repo, package): assert locker.written_data == expected assert len(installer.installer.installs) == 2 + + +def test_installer_uses_prereleases_if_they_are_compatible( + installer, locker, package, repo +): + package.python_versions = "~2.7 || ^3.4" + package.add_dependency( + "prerelease", {"git": "https://github.com/demo/prerelease.git"} + ) + + package_b = get_package("b", "2.0.0") + package_b.add_dependency("prerelease", ">=0.19") + + repo.add_package(package_b) + + installer.run() + + del installer.installer.installs[:] + locker.locked(True) + locker.mock_lock_data(locker.written_data) + + package.add_dependency("b", "^2.0.0") + + installer.whitelist(["b"]) + installer.update(True) + installer.run() + + assert len(installer.installer.installs) == 2