# Buggy code
def install_directory(self, package):
    from poetry.core.masonry.builder import SdistBuilder
    from poetry.factory import Factory
    from poetry.utils._compat import decode
    from poetry.utils.env import NullEnv
    from poetry.utils.toml_file import TomlFile

    if package.root_dir:
        req = os.path.join(package.root_dir, package.source_url)
    else:
        req = os.path.realpath(package.source_url)

    args = ["install", "--no-deps", "-U"]

    pyproject = TomlFile(os.path.join(req, "pyproject.toml"))

    has_poetry = False
    has_build_system = False
    if pyproject.exists():
        pyproject_content = pyproject.read()
        has_poetry = (
            "tool" in pyproject_content and "poetry" in pyproject_content["tool"]
        )
        # Even if there is a build system specified
        # pip as of right now does not support it fully
        # TODO: Check for pip version when proper PEP-517 support lands
        # has_build_system = ("build-system" in pyproject_content)

    setup = os.path.join(req, "setup.py")
    has_setup = os.path.exists(setup)
    if not has_setup and has_poetry and (package.develop or not has_build_system):
        # We actually need to rely on creating a temporary setup.py
        # file since pip, as of this comment, does not support
        # build-system for editable packages
        # We also need it for non-PEP-517 packages
        builder = SdistBuilder(
            Factory().create_poetry(pyproject.parent), NullEnv(), NullIO()
        )

        with open(setup, "w", encoding="utf-8") as f:
            f.write(decode(builder.build_setup()))

    if package.develop:
        args.append("-e")

    args.append(req)

    try:
        return self.run(*args)
    finally:
        if not has_setup and os.path.exists(setup):
            os.remove(setup)


# Traceback (ModuleNotFoundError)
Installing dependencies from lock file


Package operations: 1 install, 0 updates, 0 removals

- Installing package-a (0.1.0 package-a)

[EnvCommandError]
Command ['/Users/alisue/Library/Caches/pypoetry/virtualenvs/poetry-test-MDzUKMz
t-py3.7/bin/pip', 'install', '--no-deps', '-U', '-e', '/Users/alisue/.ghq/githu
b.com/lambdalisue/poetry-test/package-a'] errored with the following return cod
e 1, and output:
Obtaining file:///Users/alisue/.ghq/github.com/lambdalisue/poetry-test/package-
a
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'done'
Preparing wheel metadata: started
Preparing wheel metadata: finished with status 'done'
Installing collected packages: package-a
Running setup.py develop for package-a
ERROR: Command errored out with exit status 1:
command: /Users/alisue/Library/Caches/pypoetry/virtualenvs/poetry-test-MDz
UKMzt-py3.7/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"
'/Users/alisue/.ghq/github.com/lambdalisue/poetry-test/package-a/setup.py'"'"';
__file__='"'"'/Users/alisue/.ghq/github.com/lambdalisue/poetry-test/package-a/
setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read()
.replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '
"'"'exec'"'"'))' develop --no-deps
cwd: /Users/alisue/.ghq/github.com/lambdalisue/poetry-test/package-a/
Complete output (3 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'setuptools'
----------------------------------------
ERROR: Command errored out with exit status 1: /Users/alisue/Library/Caches/pyp
oetry/virtualenvs/poetry-test-MDzUKMzt-py3.7/bin/python -c 'import sys, setupto
ols, tokenize; sys.argv[0] = '"'"'/Users/alisue/.ghq/github.com/lambdalisue/poe
try-test/package-a/setup.py'"'"'; __file__='"'"'/Users/alisue/.ghq/github.com/l
ambdalisue/poetry-test/package-a/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'
"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close
();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps Check the l
ogs for full command output.
WARNING: You are using pip version 19.2.3, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

# Fixed code
def install_directory(self, package):
    from poetry.core.masonry.builder import SdistBuilder
    from poetry.factory import Factory
    from poetry.utils._compat import decode
    from poetry.utils.toml_file import TomlFile

    if package.root_dir:
        req = os.path.join(package.root_dir, package.source_url)
    else:
        req = os.path.realpath(package.source_url)

    args = ["install", "--no-deps", "-U"]

    pyproject = TomlFile(os.path.join(req, "pyproject.toml"))

    has_poetry = False
    has_build_system = False
    if pyproject.exists():
        pyproject_content = pyproject.read()
        has_poetry = (
            "tool" in pyproject_content and "poetry" in pyproject_content["tool"]
        )
        # Even if there is a build system specified
        # pip as of right now does not support it fully
        # TODO: Check for pip version when proper PEP-517 support lands
        # has_build_system = ("build-system" in pyproject_content)

    setup = os.path.join(req, "setup.py")
    has_setup = os.path.exists(setup)
    if not has_setup and has_poetry and (package.develop or not has_build_system):
        # We actually need to rely on creating a temporary setup.py
        # file since pip, as of this comment, does not support
        # build-system for editable packages
        # We also need it for non-PEP-517 packages
        builder = SdistBuilder(
            Factory().create_poetry(pyproject.parent),
        )

        with open(setup, "w", encoding="utf-8") as f:
            f.write(decode(builder.build_setup()))

    if package.develop:
        args.append("-e")

    args.append(req)

    try:
        return self.run(*args)
    finally:
        if not has_setup and os.path.exists(setup):
            os.remove(setup)