Repository: python-poetry/poetry

Issue:
Poetry cant resolve with git dependency
I have `werkzeug` installed with git version and then add `flask-jwt-extended` shows error though `werkzeug` is 1.0.0.dev0

```bash
$ poetry --version
Poetry 0.12.11
```

```bash
$ cat pyproject.toml
[tool.poetry]
name = "test-poetry-git-deps"
version = "0.1.0"
description = ""
authors = []

[tool.poetry.dependencies]
python = "^3.6"
werkzeug = {git = "https://github.com/pallets/werkzeug.git"}

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
```

```bash
$ cat poetry.lock
[[package]]
category = "main"
description = "The comprehensive WSGI web application library."
name = "Werkzeug"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
version = "1.0.0.dev0"

[package.source]
reference = "86f7bdf6d7c005d3ab8be50226fe42edc1ce4f7c"
type = "git"
url = "https://github.com/pallets/werkzeug.git"
[metadata]
content-hash = "7d88d5e01ecd59f104fee20ece9f80aa3b98bc2a281afc0975c36010d6af2648"
python-versions = "^3.6"

[metadata.hashes]
Werkzeug = []
```

```bash
$ poetry add flask-jwt-extended
Using version ^3.18 for flask-jwt-extended

Updating dependencies
Resolving dependencies... (6.9s)
                                                                                                                               
[SolverProblemError]                                                                                            
Because no versions of flask-jwt-extended match >3.18,<4.0                                                                   
 and flask-jwt-extended (3.18.0) depends on Werkzeug (>=0.14), flask-jwt-extended (>=3.18,<4.0) requires Werkzeug (>=0.14).  
So, because no versions of werkzeug match >=0.14                                                                             
 and test-poetry-git-deps depends on flask-jwt-extended (^3.18), version solving failed.                                     
                                                                                                                               
add [-D|--dev] [--git GIT] [--path PATH] [-E|--extras EXTRAS] [--optional] [--python PYTHON] [--platform PLATFORM] [--allow-prereleases] [--dry-run] [--] <name> (<name>)...
```

```bash
$ poetry show                                                                                                                                                                                                                                   
Werkzeug 1.0.0.dev0 86f7bdf The comprehensive WSGI web application library.
```


Discussion:
Did you know https://github.com/sdispater/poetry/issues/736?
@drunkwcodes i dont think it's the same problem
I also have this problem. In my case its django from the git branch (the `stable/2.2.x` branch), and the majority of packages that are dependent on django, will produce a complaint that they cant find a dependency, which will look something like this.
```
[SolverProblemError]
Because no versions of django-dirtyfields match >=1.3,<1.3.1 || >1.3.1,<2.0
 and django-dirtyfields (1.3.1) depends on Django (>=1.8), django-dirtyfields (>=1.3,<2.0) requires Django (>=1.8).
So, because no versions of django match >=1.8 
```
The version of django changes depending on what the package is looking for, so the overall problem seems to be that poetry is not using the git version of a package (in my case django, in the OP, case werkzeug) to satisfy requirements in subsequent dependency resolution runs.

_EDIT: Clarified inadvertent use of dependencies when I meant dependent packages._

Resolving patch:
diff --git a/poetry/repositories/repository.py b/poetry/repositories/repository.py
--- 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):


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
--- 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
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
--- /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 <sebastien@eustace.io>"
+]
+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
--- 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