Repository: python-poetry/poetry

Issue:
1.0b4 performs unnecessary installs of packages found in a custom repository
<!--
  Hi there! Thank you for discovering and submitting an issue.

  Before you submit this; let's make sure of a few things.
  Please make sure the following boxes are ticked if they are correct.
  If not, please try and fulfill these first.
-->

<!-- Checked checkbox should look like this: [x] -->
- [x] I am on the [latest](https://github.com/sdispater/poetry/releases/latest) Poetry version.
- [x] I have searched the [issues](https://github.com/sdispater/poetry/issues) of this repo and believe that this is not a duplicate.
- [x] If an exception occurs when executing a command, I executed it again in debug mode (`-vvv` option).

<!--
  Once those are done, if you're able to fill in the following list with your information,
  it'd be very helpful to whoever handles the issue.
-->

- **Centos 7**: <!-- Replace with version + name -->
- **1.0b4**: <!-- Replace with version -->
- **Link of a [Gist](https://gist.github.com/) with the contents of your pyproject.toml file**: <!-- Gist Link Here -->https://gist.github.com/dimbleby/0721a2b8ce3b138e5d4d1f88092113c5 (shows the general shape, I have redacted details of my actual custom repository)

## Issue
If I use a custom repository, as in:

```toml
[[tool.poetry.source]]
name = "custom"
url = "https://example.com/api/pypi/pypi-virtual/simple"
```

then any packages installed from that repository are redundantly re-installed at `poetry update`.

I believe the reason is that:
- the desired package source type is marked as 'legacy' in `poetry.lock`:

```toml
[package.source]
reference = "custom"
type = "legacy"
url = "https://example.com/api/pypi/pypi-virtual/simple"
```
- but the found package source type is left empty, [here](https://github.com/sdispater/poetry/blob/51c7042160a74adf14038460468e5e5a72b0d965/poetry/repositories/installed_repository.py#L25)
- so [this code](https://github.com/sdispater/poetry/blob/51c7042160a74adf14038460468e5e5a72b0d965/poetry/puzzle/solver.py#L92-L93) decides that an update is needed

cf [this comment](https://github.com/sdispater/poetry/pull/1240#discussion_r305579566).  On the plus side, I think that bf2d515a has probably fixed #1240; but it has introduced at least this case where we make unnecessary updates (and maybe others too?).


Discussion:

Resolving patch:
diff --git a/poetry/installation/pip_installer.py b/poetry/installation/pip_installer.py
--- a/poetry/installation/pip_installer.py
+++ b/poetry/installation/pip_installer.py
@@ -40,7 +40,10 @@ def install(self, package, update=False):
 
         args = ["install", "--no-deps"]
 
-        if package.source_type == "legacy" and package.source_url:
+        if (
+            package.source_type not in {"git", "directory", "file", "url"}
+            and package.source_url
+        ):
             repository = self._pool.repository(package.source_reference)
             parsed = urlparse.urlparse(package.source_url)
             if parsed.scheme == "http":
@@ -70,7 +73,7 @@ def install(self, package, update=False):
         if update:
             args.append("-U")
 
-        if package.files and not package.source_type:
+        if package.files and not package.source_url:
             # Format as a requirements.txt
             # We need to create a requirements.txt file
             # for each package in order to check hashes.
diff --git a/poetry/repositories/legacy_repository.py b/poetry/repositories/legacy_repository.py
--- a/poetry/repositories/legacy_repository.py
+++ b/poetry/repositories/legacy_repository.py
@@ -269,7 +269,6 @@ def find_packages(
 
         for version in versions:
             package = Package(name, version)
-            package.source_type = "legacy"
             package.source_url = self._url
 
             if extras is not None:
@@ -314,7 +313,6 @@ def package(
             if release_info["requires_python"]:
                 package.python_versions = release_info["requires_python"]
 
-            package.source_type = "legacy"
             package.source_url = self._url
             package.source_reference = self.name
 
diff --git a/poetry/utils/exporter.py b/poetry/utils/exporter.py
--- a/poetry/utils/exporter.py
+++ b/poetry/utils/exporter.py
@@ -107,7 +107,10 @@ def _export_requirements_txt(
             if ";" in requirement:
                 line += "; {}".format(requirement.split(";")[1].strip())
 
-            if package.source_type == "legacy" and package.source_url:
+            if (
+                package.source_type not in {"git", "directory", "file", "url"}
+                and package.source_url
+            ):
                 indexes.append(package.source_url)
 
             if package.files and with_hashes:


Test patch:
diff --git a/tests/puzzle/test_solver.py b/tests/puzzle/test_solver.py
--- a/tests/puzzle/test_solver.py
+++ b/tests/puzzle/test_solver.py
@@ -1686,7 +1686,6 @@ def test_solver_chooses_from_correct_repository_if_forced(
         ops, [{"job": "install", "package": get_package("tomlkit", "0.5.2")}]
     )
 
-    assert "legacy" == ops[0].package.source_type
     assert "http://foo.bar" == ops[0].package.source_url
 
 
@@ -1715,7 +1714,6 @@ def test_solver_chooses_from_correct_repository_if_forced_and_transitive_depende
         ],
     )
 
-    assert "legacy" == ops[0].package.source_type
     assert "http://foo.bar" == ops[0].package.source_url
 
     assert "" == ops[1].package.source_type
@@ -1745,11 +1743,9 @@ def test_solver_does_not_choose_from_secondary_repository_by_default(
         ],
     )
 
-    assert "legacy" == ops[0].package.source_type
     assert "http://foo.bar" == ops[0].package.source_url
     assert "" == ops[1].package.source_type
     assert "" == ops[1].package.source_url
-    assert "legacy" == ops[2].package.source_type
     assert "http://foo.bar" == ops[2].package.source_url
 
 
@@ -1774,7 +1770,6 @@ def test_solver_chooses_from_secondary_if_explicit(package, installed, locked, i
         ],
     )
 
-    assert "legacy" == ops[0].package.source_type
     assert "http://foo.bar" == ops[0].package.source_url
     assert "" == ops[1].package.source_type
     assert "" == ops[1].package.source_url