Repository: python-poetry/poetry

Issue:
error with local packages and 'poetry show -o'

- [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.
-->

- **OS version and name**: Linux Mint 18.3 Sylvia
- **Poetry version**: 0.11.2
- **Link of a [Gist](https://gist.github.com/) with the contents of your pyproject.toml file**: https://gist.github.com/tkossak/359ec6a67014dca89626c55b27abc837

## Issue
Poetry checks for updates to local packates on PyPI:

```
poetry show -o -vvv
Virtualenv kossak-pydata-helpers-py3.6 already exists.
Using virtualenv: /home/kossak/.cache/pypoetry/virtualenvs/kossak-pydata-helpers-py3.6

[ValueError]
Package [kossak-pass] not found.

Exception trace:
 /home/kossak/.pyenv/versions/3.6.6/lib/python3.6/site-packages/cleo/application.py in run() at line 94
   status_code = self.do_run(input_, output_)
 /home/kossak/.pyenv/versions/3.6.6/lib/python3.6/site-packages/poetry/console/application.py in do_run() at line 88
   return super(Application, self).do_run(i, o)
 /home/kossak/.pyenv/versions/3.6.6/lib/python3.6/site-packages/cleo/application.py in do_run() at line 197
   status_code = command.run(input_, output_)
 /home/kossak/.pyenv/versions/3.6.6/lib/python3.6/site-packages/poetry/console/commands/command.py in run() at line 72
   return super(BaseCommand, self).run(i, o)
 /home/kossak/.pyenv/versions/3.6.6/lib/python3.6/site-packages/cleo/commands/base_command.py in run() at line 146
   status_code = self.execute(input_, output_)
 /home/kossak/.pyenv/versions/3.6.6/lib/python3.6/site-packages/cleo/commands/command.py in execute() at line 107
   return self.handle()
 /home/kossak/.pyenv/versions/3.6.6/lib/python3.6/site-packages/poetry/console/commands/show.py in handle() at line 129
   latest = self.find_latest_package(locked)
 /home/kossak/.pyenv/versions/3.6.6/lib/python3.6/site-packages/poetry/console/commands/show.py in find_latest_package() at line 300
   return selector.find_best_candidate(name, ">={}".format(package.pretty_version))
 /home/kossak/.pyenv/versions/3.6.6/lib/python3.6/site-packages/poetry/version/version_selector.py in find_best_candidate() at line 29
   package_name, constraint, allow_prereleases=allow_prereleases
 /home/kossak/.pyenv/versions/3.6.6/lib/python3.6/site-packages/poetry/repositories/pool.py in find_packages() at line 83
   name, constraint, extras=extras, allow_prereleases=allow_prereleases
 /home/kossak/.pyenv/versions/3.6.6/lib/python3.6/site-packages/poetry/repositories/pypi_repository.py in find_packages() at line 90
   info = self.get_package_info(name)
 /home/kossak/.pyenv/versions/3.6.6/lib/python3.6/site-packages/poetry/repositories/pypi_repository.py in get_package_info() at line 218
   name, lambda: self._get_package_info(name)
 /home/kossak/.pyenv/versions/3.6.6/lib/python3.6/site-packages/cachy/repository.py in remember_forever() at line 174
   val = value(callback)
 /home/kossak/.pyenv/versions/3.6.6/lib/python3.6/site-packages/cachy/helpers.py in value() at line 6
   return val()
 /home/kossak/.pyenv/versions/3.6.6/lib/python3.6/site-packages/poetry/repositories/pypi_repository.py in <lambda>() at line 218
   name, lambda: self._get_package_info(name)
 /home/kossak/.pyenv/versions/3.6.6/lib/python3.6/site-packages/poetry/repositories/pypi_repository.py in _get_package_info() at line 224
   raise ValueError("Package [{}] not found.".format(name))

show [-t|--tree] [-l|--latest] [-o|--outdated] [-a|--all] [--] [<package>]
```


Discussion:
You are right. There is definitely a bug here.

We will check and get back to you when it's fixed.
This is still happening on `0.12.7` and happens with git dependencies as well
Here's some more info:

If I have a git dependency in `tool.poetry.dev-dependencies`, I encounter this error when running `poetry show -o`. If I move the same dependency to `tool.poetry.dependencies`, the error goes away and `poetry show -o` works fine.

Resolving patch:
diff --git a/poetry/console/commands/show.py b/poetry/console/commands/show.py
--- a/poetry/console/commands/show.py
+++ b/poetry/console/commands/show.py
@@ -35,7 +35,8 @@ def handle(self):
         if self.option("outdated"):
             self.input.set_option("latest", True)
 
-        locked_repo = self.poetry.locker.locked_repository(not self.option("no-dev"))
+        include_dev = not self.option("no-dev")
+        locked_repo = self.poetry.locker.locked_repository(include_dev)
 
         # Show tree view if requested
         if self.option("tree") and not package:
@@ -95,6 +96,7 @@ def handle(self):
         width = terminal.width
         name_length = version_length = latest_length = 0
         latest_packages = {}
+        latest_statuses = {}
         installed_repo = InstalledRepository.load(self.env)
         skipped = []
 
@@ -118,15 +120,25 @@ def handle(self):
                 if installed_status == "not-installed":
                     current_length += 4
 
-            name_length = max(name_length, current_length)
-            version_length = max(version_length, len(locked.full_pretty_version))
             if show_latest:
-                latest = self.find_latest_package(locked)
+                latest = self.find_latest_package(locked, include_dev)
                 if not latest:
                     latest = locked
 
                 latest_packages[locked.pretty_name] = latest
-                latest_length = max(latest_length, len(latest.full_pretty_version))
+                update_status = latest_statuses[
+                    locked.pretty_name
+                ] = self.get_update_status(latest, locked)
+
+                if not self.option("outdated") or update_status != "up-to-date":
+                    name_length = max(name_length, current_length)
+                    version_length = max(
+                        version_length, len(locked.full_pretty_version)
+                    )
+                    latest_length = max(latest_length, len(latest.full_pretty_version))
+            else:
+                name_length = max(name_length, current_length)
+                version_length = max(version_length, len(locked.full_pretty_version))
 
         write_version = name_length + version_length + 3 <= width
         write_latest = name_length + version_length + latest_length + 3 <= width
@@ -157,22 +169,24 @@ def handle(self):
                 line += " <comment>{:{}}</comment>".format(
                     locked.full_pretty_version, version_length
                 )
-            if show_latest and write_latest:
+            if show_latest:
                 latest = latest_packages[locked.pretty_name]
+                update_status = latest_statuses[locked.pretty_name]
 
-                update_status = self.get_update_status(latest, locked)
-                color = "green"
-                if update_status == "semver-safe-update":
-                    color = "red"
-                elif update_status == "update-possible":
-                    color = "yellow"
-
-                line += " <fg={}>{:{}}</>".format(
-                    color, latest.full_pretty_version, latest_length
-                )
                 if self.option("outdated") and update_status == "up-to-date":
                     continue
 
+                if write_latest:
+                    color = "green"
+                    if update_status == "semver-safe-update":
+                        color = "red"
+                    elif update_status == "update-possible":
+                        color = "yellow"
+
+                    line += " <fg={}>{:{}}</>".format(
+                        color, latest.full_pretty_version, latest_length
+                    )
+
             if write_description:
                 description = locked.description
                 remaining = width - name_length - version_length - 4
@@ -286,18 +300,27 @@ def init_styles(self):
         for color in self.colors:
             self.set_style(color, color)
 
-    def find_latest_package(self, package):
+    def find_latest_package(self, package, include_dev):
         from poetry.io import NullIO
         from poetry.puzzle.provider import Provider
         from poetry.version.version_selector import VersionSelector
 
         # find the latest version allowed in this pool
-        if package.source_type == "git":
-            for dep in self.poetry.package.requires:
-                if dep.name == package.name and dep.is_vcs():
-                    return Provider(
-                        self.poetry.package, self.poetry.pool, NullIO()
-                    ).search_for_vcs(dep)[0]
+        if package.source_type in ("git", "file", "directory"):
+            requires = self.poetry.package.requires
+            if include_dev:
+                requires = requires + self.poetry.package.dev_requires
+
+            for dep in requires:
+                if dep.name == package.name:
+                    provider = Provider(self.poetry.package, self.poetry.pool, NullIO())
+
+                    if dep.is_vcs():
+                        return provider.search_for_vcs(dep)[0]
+                    if dep.is_file():
+                        return provider.search_for_file(dep)[0]
+                    if dep.is_directory():
+                        return provider.search_for_directory(dep)[0]
 
         name = package.name
         selector = VersionSelector(self.poetry.pool)


Test patch:
diff --git a/tests/console/commands/test_show.py b/tests/console/commands/test_show.py
--- a/tests/console/commands/test_show.py
+++ b/tests/console/commands/test_show.py
@@ -1,3 +1,4 @@
+import pytest
 from cleo.testers import CommandTester
 
 from tests.helpers import get_package
@@ -369,8 +370,338 @@ def test_show_outdated(app, poetry, installed, repo):
 
     tester.execute([("command", command.get_name()), ("--outdated", True)])
 
+    expected = """\
+cachy 0.1.0 0.2.0 Cachy package
+"""
+
+    assert tester.get_display(True) == expected
+
+
+def test_show_outdated_formatting(app, poetry, installed, repo):
+    command = app.find("show")
+    tester = CommandTester(command)
+
+    cachy_010 = get_package("cachy", "0.1.0")
+    cachy_010.description = "Cachy package"
+    cachy_020 = get_package("cachy", "0.2.0")
+    cachy_020.description = "Cachy package"
+
+    pendulum_200 = get_package("pendulum", "2.0.0")
+    pendulum_200.description = "Pendulum package"
+    pendulum_201 = get_package("pendulum", "2.0.1")
+    pendulum_201.description = "Pendulum package"
+
+    installed.add_package(cachy_010)
+    installed.add_package(pendulum_200)
+
+    repo.add_package(cachy_010)
+    repo.add_package(cachy_020)
+    repo.add_package(pendulum_200)
+    repo.add_package(pendulum_201)
+
+    poetry.locker.mock_lock_data(
+        {
+            "package": [
+                {
+                    "name": "cachy",
+                    "version": "0.1.0",
+                    "description": "Cachy package",
+                    "category": "main",
+                    "optional": False,
+                    "platform": "*",
+                    "python-versions": "*",
+                    "checksum": [],
+                },
+                {
+                    "name": "pendulum",
+                    "version": "2.0.0",
+                    "description": "Pendulum package",
+                    "category": "main",
+                    "optional": False,
+                    "platform": "*",
+                    "python-versions": "*",
+                    "checksum": [],
+                },
+            ],
+            "metadata": {
+                "python-versions": "*",
+                "platform": "*",
+                "content-hash": "123456789",
+                "hashes": {"cachy": [], "pendulum": []},
+            },
+        }
+    )
+
+    tester.execute([("command", command.get_name()), ("--outdated", True)])
+
     expected = """\
 cachy    0.1.0 0.2.0 Cachy package
+pendulum 2.0.0 2.0.1 Pendulum package
+"""
+
+    assert tester.get_display(True) == expected
+
+
+@pytest.mark.parametrize("project_directory", ["project_with_local_dependencies"])
+def test_show_outdated_local_dependencies(app, poetry, installed, repo):
+    command = app.find("show")
+    tester = CommandTester(command)
+
+    cachy_010 = get_package("cachy", "0.1.0")
+    cachy_010.description = "Cachy package"
+    cachy_020 = get_package("cachy", "0.2.0")
+    cachy_020.description = "Cachy package"
+
+    pendulum_200 = get_package("pendulum", "2.0.0")
+    pendulum_200.description = "Pendulum package"
+
+    demo_010 = get_package("demo", "0.1.0")
+    demo_010.description = ""
+
+    my_package_012 = get_package("my-package", "0.1.2")
+    my_package_012.description = "Demo project."
+
+    installed.add_package(cachy_010)
+    installed.add_package(pendulum_200)
+    installed.add_package(demo_010)
+    installed.add_package(my_package_012)
+
+    repo.add_package(cachy_010)
+    repo.add_package(cachy_020)
+    repo.add_package(pendulum_200)
+
+    poetry.locker.mock_lock_data(
+        {
+            "package": [
+                {
+                    "name": "cachy",
+                    "version": "0.1.0",
+                    "description": "Cachy package",
+                    "category": "main",
+                    "optional": False,
+                    "platform": "*",
+                    "python-versions": "*",
+                    "checksum": [],
+                },
+                {
+                    "name": "pendulum",
+                    "version": "2.0.0",
+                    "description": "Pendulum package",
+                    "category": "main",
+                    "optional": False,
+                    "platform": "*",
+                    "python-versions": "*",
+                    "checksum": [],
+                },
+                {
+                    "name": "demo",
+                    "version": "0.1.0",
+                    "description": "Demo package",
+                    "category": "main",
+                    "optional": False,
+                    "platform": "*",
+                    "python-versions": "*",
+                    "checksum": [],
+                    "source": {
+                        "type": "file",
+                        "reference": "",
+                        "url": "../distributions/demo-0.1.0-py2.py3-none-any.whl",
+                    },
+                },
+                {
+                    "name": "my-package",
+                    "version": "0.1.1",
+                    "description": "Demo project.",
+                    "category": "main",
+                    "optional": False,
+                    "platform": "*",
+                    "python-versions": "*",
+                    "checksum": [],
+                    "source": {
+                        "type": "directory",
+                        "reference": "",
+                        "url": "../project_with_setup",
+                    },
+                },
+            ],
+            "metadata": {
+                "python-versions": "*",
+                "platform": "*",
+                "content-hash": "123456789",
+                "hashes": {"cachy": [], "pendulum": [], "demo": [], "my-package": []},
+            },
+        }
+    )
+
+    tester.execute([("command", command.get_name()), ("--outdated", True)])
+
+    expected = """\
+cachy      0.1.0                       0.2.0                      
+my-package 0.1.1 ../project_with_setup 0.1.2 ../project_with_setup
+"""
+    assert tester.get_display(True) == expected
+
+
+@pytest.mark.parametrize("project_directory", ["project_with_git_dev_dependency"])
+def test_show_outdated_git_dev_dependency(app, poetry, installed, repo):
+    command = app.find("show")
+    tester = CommandTester(command)
+
+    cachy_010 = get_package("cachy", "0.1.0")
+    cachy_010.description = "Cachy package"
+    cachy_020 = get_package("cachy", "0.2.0")
+    cachy_020.description = "Cachy package"
+
+    pendulum_200 = get_package("pendulum", "2.0.0")
+    pendulum_200.description = "Pendulum package"
+
+    demo_011 = get_package("demo", "0.1.1")
+    demo_011.description = "Demo package"
+
+    installed.add_package(cachy_010)
+    installed.add_package(pendulum_200)
+    installed.add_package(demo_011)
+
+    repo.add_package(cachy_010)
+    repo.add_package(cachy_020)
+    repo.add_package(pendulum_200)
+
+    poetry.locker.mock_lock_data(
+        {
+            "package": [
+                {
+                    "name": "cachy",
+                    "version": "0.1.0",
+                    "description": "Cachy package",
+                    "category": "main",
+                    "optional": False,
+                    "platform": "*",
+                    "python-versions": "*",
+                    "checksum": [],
+                },
+                {
+                    "name": "pendulum",
+                    "version": "2.0.0",
+                    "description": "Pendulum package",
+                    "category": "main",
+                    "optional": False,
+                    "platform": "*",
+                    "python-versions": "*",
+                    "checksum": [],
+                },
+                {
+                    "name": "demo",
+                    "version": "0.1.1",
+                    "description": "Demo package",
+                    "category": "dev",
+                    "optional": False,
+                    "platform": "*",
+                    "python-versions": "*",
+                    "checksum": [],
+                    "source": {
+                        "type": "git",
+                        "reference": "9cf87a285a2d3fbb0b9fa621997b3acc3631ed24",
+                        "url": "https://github.com/demo/pyproject-demo.git",
+                    },
+                },
+            ],
+            "metadata": {
+                "python-versions": "*",
+                "platform": "*",
+                "content-hash": "123456789",
+                "hashes": {"cachy": [], "pendulum": [], "demo": []},
+            },
+        }
+    )
+
+    tester.execute([("command", command.get_name()), ("--outdated", True)])
+
+    expected = """\
+cachy 0.1.0         0.2.0         Cachy package
+demo  0.1.1 9cf87a2 0.1.2 9cf87a2 Demo package
+"""
+
+    assert tester.get_display(True) == expected
+
+
+@pytest.mark.parametrize("project_directory", ["project_with_git_dev_dependency"])
+def test_show_outdated_no_dev_git_dev_dependency(app, poetry, installed, repo):
+    command = app.find("show")
+    tester = CommandTester(command)
+
+    cachy_010 = get_package("cachy", "0.1.0")
+    cachy_010.description = "Cachy package"
+    cachy_020 = get_package("cachy", "0.2.0")
+    cachy_020.description = "Cachy package"
+
+    pendulum_200 = get_package("pendulum", "2.0.0")
+    pendulum_200.description = "Pendulum package"
+
+    demo_011 = get_package("demo", "0.1.1")
+    demo_011.description = "Demo package"
+
+    installed.add_package(cachy_010)
+    installed.add_package(pendulum_200)
+    installed.add_package(demo_011)
+
+    repo.add_package(cachy_010)
+    repo.add_package(cachy_020)
+    repo.add_package(pendulum_200)
+
+    poetry.locker.mock_lock_data(
+        {
+            "package": [
+                {
+                    "name": "cachy",
+                    "version": "0.1.0",
+                    "description": "Cachy package",
+                    "category": "main",
+                    "optional": False,
+                    "platform": "*",
+                    "python-versions": "*",
+                    "checksum": [],
+                },
+                {
+                    "name": "pendulum",
+                    "version": "2.0.0",
+                    "description": "Pendulum package",
+                    "category": "main",
+                    "optional": False,
+                    "platform": "*",
+                    "python-versions": "*",
+                    "checksum": [],
+                },
+                {
+                    "name": "demo",
+                    "version": "0.1.1",
+                    "description": "Demo package",
+                    "category": "dev",
+                    "optional": False,
+                    "platform": "*",
+                    "python-versions": "*",
+                    "checksum": [],
+                    "source": {
+                        "type": "git",
+                        "reference": "9cf87a285a2d3fbb0b9fa621997b3acc3631ed24",
+                        "url": "https://github.com/demo/pyproject-demo.git",
+                    },
+                },
+            ],
+            "metadata": {
+                "python-versions": "*",
+                "platform": "*",
+                "content-hash": "123456789",
+                "hashes": {"cachy": [], "pendulum": [], "demo": []},
+            },
+        }
+    )
+
+    tester.execute(
+        [("command", command.get_name()), ("--outdated", True), ("--no-dev", True)]
+    )
+
+    expected = """\
+cachy 0.1.0 0.2.0 Cachy package
 """
 
     assert tester.get_display(True) == expected
diff --git a/tests/console/conftest.py b/tests/console/conftest.py
--- a/tests/console/conftest.py
+++ b/tests/console/conftest.py
@@ -15,11 +15,12 @@
 from poetry.poetry import Poetry as BasePoetry
 from poetry.packages import Locker as BaseLocker
 from poetry.repositories import Pool
-from poetry.repositories import Repository
+from poetry.repositories import Repository as BaseRepository
 from poetry.utils._compat import Path
 from poetry.utils.env import Env
 from poetry.utils.env import MockEnv
 from poetry.utils.toml_file import TomlFile
+from poetry.repositories.exceptions import PackageNotFound
 
 
 @pytest.fixture()
@@ -45,7 +46,7 @@ def mock_clone(self, source, dest):
 
 @pytest.fixture
 def installed():
-    return Repository()
+    return BaseRepository()
 
 
 @pytest.fixture(autouse=True)
@@ -140,14 +141,31 @@ def __init__(self, file, local_config, package, locker):
         self._pool = Pool()
 
 
+class Repository(BaseRepository):
+    def find_packages(
+        self, name, constraint=None, extras=None, allow_prereleases=False
+    ):
+        packages = super(Repository, self).find_packages(
+            name, constraint, extras, allow_prereleases
+        )
+        if len(packages) == 0:
+            raise PackageNotFound("Package [{}] not found.".format(name))
+        return packages
+
+
 @pytest.fixture
 def repo():
     return Repository()
 
 
 @pytest.fixture
-def poetry(repo):
-    p = Poetry.create(Path(__file__).parent.parent / "fixtures" / "simple_project")
+def project_directory():
+    return "simple_project"
+
+
+@pytest.fixture
+def poetry(repo, project_directory):
+    p = Poetry.create(Path(__file__).parent.parent / "fixtures" / project_directory)
 
     with p.file.path.open() as f:
         content = f.read()
diff --git a/tests/fixtures/project_with_git_dev_dependency/pyproject.toml b/tests/fixtures/project_with_git_dev_dependency/pyproject.toml
new file mode 100644
--- /dev/null
+++ b/tests/fixtures/project_with_git_dev_dependency/pyproject.toml
@@ -0,0 +1,37 @@
+[tool.poetry]
+name = "my-package"
+version = "1.2.3"
+description = "Some description."
+authors = [
+    "Sébastien Eustace <sebastien@eustace.io>"
+]
+license = "MIT"
+
+homepage = "https://poetry.eustace.io"
+repository = "https://github.com/sdispater/poetry"
+documentation = "https://poetry.eustace.io/docs"
+
+keywords = ["packaging", "dependency", "poetry"]
+
+classifiers = [
+    "Topic :: Software Development :: Build Tools",
+    "Topic :: Software Development :: Libraries :: Python Modules"
+]
+
+# Requirements
+[tool.poetry.dependencies]
+python = "~2.7 || ^3.6"
+cachy = "^0.1.0"
+pendulum = "^2.0.0"
+
+[tool.poetry.dev-dependencies]
+pytest = "~3.4"
+demo = { git = "https://github.com/demo/demo.git", rev = "9cf87a285a2d3fbb0b9fa621997b3acc3631ed24" }
+
+
+[tool.poetry.scripts]
+my-script = "my_package:main"
+
+
+[tool.poetry.plugins."blogtool.parsers"]
+".rst" = "some_module::SomeClass"
diff --git a/tests/fixtures/project_with_local_dependencies/pyproject.toml b/tests/fixtures/project_with_local_dependencies/pyproject.toml
new file mode 100644
--- /dev/null
+++ b/tests/fixtures/project_with_local_dependencies/pyproject.toml
@@ -0,0 +1,38 @@
+[tool.poetry]
+name = "my-package"
+version = "1.2.3"
+description = "Some description."
+authors = [
+    "Sébastien Eustace <sebastien@eustace.io>"
+]
+license = "MIT"
+
+readme = "README.rst"
+
+homepage = "https://poetry.eustace.io"
+repository = "https://github.com/sdispater/poetry"
+documentation = "https://poetry.eustace.io/docs"
+
+keywords = ["packaging", "dependency", "poetry"]
+
+classifiers = [
+    "Topic :: Software Development :: Build Tools",
+    "Topic :: Software Development :: Libraries :: Python Modules"
+]
+
+# Requirements
+[tool.poetry.dependencies]
+python = "~2.7 || ^3.6"
+# File dependency
+demo = { path = "../distributions/demo-0.1.0-py2.py3-none-any.whl" }
+
+# Dir dependency with setup.py
+my-package = { path = "../project_with_setup/" }
+
+
+[tool.poetry.scripts]
+my-script = "my_package:main"
+
+
+[tool.poetry.plugins."blogtool.parsers"]
+".rst" = "some_module::SomeClass"