Repository: pypa/pipenv

Issue:
my library is being built for some reason?
### Issue description

I have a library called `lib` with a setup.py:

```python
from setuptools import setup

setup(
    name='lib',
    packages=['lib'])
```

My Pipfile has this library listed as editable:

```toml
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
jupyter = "*"
requests = "*"
numpy = "*"
elasticsearch = "*"
"requests-aws4auth" = "*"
"boto3" = "*"
arrow = "*"
elasticsearch-dsl = ">=6.0.0,<7.0.0"
"html2text" = "*"
requests-cache = "*"
lib = {editable = true, path = "."}
plotly = "*"
scipy = "*"

[dev-packages]
pylint = "*"

[requires]
python_version = "3.7"
```

For some reason, the `lib` gets built complete with a `dist` and `build` folder? Even though its an editable package? Why is this happening?

### Expected result

I expect not `build` or `dist` folder to be created.

### Actual result

```
Installing dependencies from Pipfile.lock (539eef)…
running install▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 65/66 — 00:00:01
running bdist_egg
running egg_info
writing lib.egg-info/PKG-INFO
writing dependency_links to lib.egg-info/dependency_links.txt
writing top-level names to lib.egg-info/top_level.txt
reading manifest file 'lib.egg-info/SOURCES.txt'
writing manifest file 'lib.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.13-x86_64/egg
running install_lib
running build_py
creating build
creating build/lib
creating build/lib/lib
copying lib/textrazor.py -> build/lib/lib
copying lib/story.py -> build/lib/lib
copying lib/content_api.py -> build/lib/lib
copying lib/__init__.py -> build/lib/lib
copying lib/utils.py -> build/lib/lib
copying lib/meaningcloud.py -> build/lib/lib
copying lib/aylien.py -> build/lib/lib
creating build/bdist.macosx-10.13-x86_64
creating build/bdist.macosx-10.13-x86_64/egg
creating build/bdist.macosx-10.13-x86_64/egg/lib
copying build/lib/lib/textrazor.py -> build/bdist.macosx-10.13-x86_64/egg/lib
copying build/lib/lib/story.py -> build/bdist.macosx-10.13-x86_64/egg/lib
copying build/lib/lib/content_api.py -> build/bdist.macosx-10.13-x86_64/egg/lib
copying build/lib/lib/__init__.py -> build/bdist.macosx-10.13-x86_64/egg/lib
copying build/lib/lib/utils.py -> build/bdist.macosx-10.13-x86_64/egg/lib
copying build/lib/lib/meaningcloud.py -> build/bdist.macosx-10.13-x86_64/egg/lib
copying build/lib/lib/aylien.py -> build/bdist.macosx-10.13-x86_64/egg/lib
byte-compiling build/bdist.macosx-10.13-x86_64/egg/lib/textrazor.py to textrazor.cpython-37.pyc
byte-compiling build/bdist.macosx-10.13-x86_64/egg/lib/story.py to story.cpython-37.pyc
byte-compiling build/bdist.macosx-10.13-x86_64/egg/lib/content_api.py to content_api.cpython-37.pyc
byte-compiling build/bdist.macosx-10.13-x86_64/egg/lib/__init__.py to __init__.cpython-37.pyc
byte-compiling build/bdist.macosx-10.13-x86_64/egg/lib/utils.py to utils.cpython-37.pyc
byte-compiling build/bdist.macosx-10.13-x86_64/egg/lib/meaningcloud.py to meaningcloud.cpython-37.pyc
byte-compiling build/bdist.macosx-10.13-x86_64/egg/lib/aylien.py to aylien.cpython-37.pyc
creating build/bdist.macosx-10.13-x86_64/egg/EGG-INFO
copying lib.egg-info/PKG-INFO -> build/bdist.macosx-10.13-x86_64/egg/EGG-INFO
copying lib.egg-info/SOURCES.txt -> build/bdist.macosx-10.13-x86_64/egg/EGG-INFO
copying lib.egg-info/dependency_links.txt -> build/bdist.macosx-10.13-x86_64/egg/EGG-INFO
copying lib.egg-info/top_level.txt -> build/bdist.macosx-10.13-x86_64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist/lib-0.0.0-py3.7.egg' and adding 'build/bdist.macosx-10.13-x86_64/egg' to it
removing 'build/bdist.macosx-10.13-x86_64/egg' (and everything under it)
Processing lib-0.0.0-py3.7.egg
Copying lib-0.0.0-py3.7.egg to /Users/johria/.pyenv/versions/3.7.0/lib/python3.7/site-packages
Adding lib 0.0.0 to easy-install.pth file

Installed /Users/johria/.pyenv/versions/3.7.0/lib/python3.7/site-packages/lib-0.0.0-py3.7.egg
Processing dependencies for lib==0.0.0
Finished processing dependencies for lib==0.0.0
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 66/66 — 00:01:08
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
```

### Steps to replicate

Provide the steps to replicate (which usually at least includes the commands and the Pipfile).

-------------------------------------------------------------------------------

<details><summary>$ pipenv --support</summary>

Pipenv version: `'2018.10.13'`

Pipenv location: `'/Users/johria/.pyenv/versions/3.7.0/lib/python3.7/site-packages/pipenv'`

Python location: `'/Users/johria/.pyenv/versions/3.7.0/bin/python3.7'`

Python installations found:

Error %s while executing command %s name 'WindowsError' is not defined /usr/local/bin/pythonz -c import sys; print(sys.version.split()[0])



Discussion:
Editable dependencies are built to determine their dependencies — this is not new or exclusive to pipenv. We can remove the folders though. 

The other issue is already reported and a fix is in progress. Sorry for the trouble. 
@techalchemy got it, yeah, I think deleting the extra folders would be great
hm we should actually be building this in a tempdir, can you try `pip install -e git+https://github.com/pypa/pipenv.git@update-vendor#egg=pipenv` and see if this still happens?

Resolving patch:
diff --git a/pipenv/utils.py b/pipenv/utils.py
--- a/pipenv/utils.py
+++ b/pipenv/utils.py
@@ -221,7 +221,10 @@ def actually_resolve_deps(
     from pipenv.patched.piptools import logging as piptools_logging
     from pipenv.patched.piptools.exceptions import NoCandidateFound
     from .vendor.requirementslib.models.requirements import Requirement
-    from .vendor.vistir.path import create_tracked_tempdir, create_tracked_tempfile
+    from .vendor.vistir.path import (
+        create_tracked_tempdir, create_tracked_tempfile, url_to_path,
+    )
+    from .vendor.vistir.compat import Path, to_native_string
 
     class PipCommand(Command):
         """Needed for pip-tools."""
@@ -229,6 +232,7 @@ class PipCommand(Command):
         name = "PipCommand"
 
     constraints = []
+    needs_hash = []
     if not req_dir:
         req_dir = create_tracked_tempdir(suffix="-requirements", prefix="pipenv-")
     for dep in deps:
@@ -240,6 +244,9 @@ class PipCommand(Command):
             url = indexes[0]
         dep = " ".join(remainder)
         req = Requirement.from_line(dep)
+        new_ireq = req.as_ireq()
+        if getattr(new_ireq, "link", None) and new_ireq.link.is_wheel and new_ireq.link.scheme == 'file':
+            needs_hash.append(new_ireq)
 
         # extra_constraints = []
 
@@ -288,10 +295,17 @@ class PipCommand(Command):
         constraints=constraints, repository=pypi, clear_caches=clear, prereleases=pre
     )
     # pre-resolve instead of iterating to avoid asking pypi for hashes of editable packages
-    hashes = None
+    hashes = {
+        ireq: pypi._hash_cache.get_hash(ireq.link)
+        for ireq in constraints if (getattr(ireq, "link", None)
+        # We can only hash artifacts, but we don't want normal pypi artifcats since the
+        # normal resolver handles those
+        and ireq.link.is_artifact and not (is_pypi_url(ireq.link.url) or
+        # We also don't want to try to hash directories as this will fail (editable deps)
+        (ireq.link.scheme == "file" and Path(to_native_string(url_to_path(ireq.link.url))).is_dir())))
+    }
     try:
         results = resolver.resolve(max_rounds=environments.PIPENV_MAX_ROUNDS)
-        hashes = resolver.resolve_hashes(results)
         resolved_tree.update(results)
     except (NoCandidateFound, DistributionNotFound, HTTPError) as e:
         click_echo(
@@ -318,6 +332,11 @@ class PipCommand(Command):
                 ), err=True
             )
         raise RuntimeError
+    else:
+        resolved_hashes = resolver.resolve_hashes(results)
+        for ireq, ireq_hashes in resolved_hashes.items():
+            if ireq not in hashes:
+                hashes[ireq] = ireq_hashes
     return (resolved_tree, hashes, markers_lookup, resolver)
 
 
diff --git a/pipenv/vendor/requirementslib/__init__.py b/pipenv/vendor/requirementslib/__init__.py
--- a/pipenv/vendor/requirementslib/__init__.py
+++ b/pipenv/vendor/requirementslib/__init__.py
@@ -1,5 +1,5 @@
 # -*- coding=utf-8 -*-
-__version__ = '1.2.3'
+__version__ = '1.2.4'
 
 import logging
 
diff --git a/pipenv/vendor/requirementslib/utils.py b/pipenv/vendor/requirementslib/utils.py
--- a/pipenv/vendor/requirementslib/utils.py
+++ b/pipenv/vendor/requirementslib/utils.py
@@ -186,7 +186,14 @@ def ensure_setup_py(base_dir):
     if not base_dir:
         base_dir = create_tracked_tempdir(prefix="requirementslib-setup")
     base_dir = Path(base_dir)
+    if base_dir.exists() and base_dir.name == "setup.py":
+        base_dir = base_dir.parent
+    elif not (base_dir.exists() and base_dir.is_dir()):
+        base_dir = base_dir.parent
+        if not (base_dir.exists() and base_dir.is_dir()):
+            base_dir = base_dir.parent
     setup_py = base_dir.joinpath("setup.py")
+
     is_new = False if setup_py.exists() else True
     if not setup_py.exists():
         setup_py.write_text(u"")


Test patch: