Repository: pypa/pipenv

Issue:
easy-install.pth contains incomplete number of paths for editable = true packages.
##### Describe your environment

1. OS Type: Debian Stable 9.2
1. Python version: Python 2.7.13
1. Pipenv version: pipenv, version 8.3.2

##### Expected result

When running pipenv install with a Pipfile containing 15 local editable packages:

```
pyramid-mustache = {path = "vendor/pyramid-mustache/", editable = true}
Dalton = {path = "vendor/Dalton/", editable = true}
pyelasticsearch = {path = "vendor/pyelasticsearch/", editable = true}
deus_lib = {path = "deus_lib/", editable = true}
lexdb = {path = "lexdb/", editable = true}
bias = {path = "bias/", editable = true}
winslow = {path = "winslow/", editable = true}
usertool = {path = "usertool/", editable = true}
analytics_services = {path = "analytics_services/", editable = true}
citadel = {path = "citadel/", editable = true}
lex-nlp-scripts = {path = "lexnlp-product/core/scripts/", editable = true}
dashboarding = {path = "dashboarding/", editable = true}
east = {path = "east/", editable = true}
webhook_handler = {path = "webhook_handler/", editable = true}
qatool = {path = "qatool/", editable = true}
```

I expect 15 entries in `easy-install.pth`. 

##### Actual result

I get 13, 11, etc, and each time you run it you get a different set of local pth entries.

No changes to Pipfile or to Pipfile.lock, just rerunning pipenv install

Examples:
```
/home/gavin/LexMachina/src/deus_lex/vendor/Dalton
/home/gavin/LexMachina/src/deus_lex/east
/home/gavin/LexMachina/src/deus_lex/vendor/pyramid-mustache
/home/gavin/LexMachina/src/deus_lex/citadel
/home/gavin/LexMachina/src/deus_lex/vendor/pyelasticsearch
/home/gavin/LexMachina/src/deus_lex/webhook_handler
/home/gavin/LexMachina/src/deus_lex/usertool
/home/gavin/LexMachina/src/deus_lex/analytics_services
/home/gavin/LexMachina/src/deus_lex/lexdb
/home/gavin/LexMachina/src/deus_lex/deus_lib
/home/gavin/LexMachina/src/deus_lex/winslow
/home/gavin/LexMachina/src/deus_lex/lexnlp-product/core/scripts
/home/gavin/LexMachina/src/deus_lex/qatool
```

```
/home/gavin/LexMachina/src/deus_lex/webhook_handler
/home/gavin/LexMachina/src/deus_lex/vendor/Dalton
/home/gavin/LexMachina/src/deus_lex/east
/home/gavin/LexMachina/src/deus_lex/dashboarding
/home/gavin/LexMachina/src/deus_lex/vendor/pyramid-mustache
/home/gavin/LexMachina/src/deus_lex/citadel
/home/gavin/LexMachina/src/deus_lex/bias
/home/gavin/LexMachina/src/deus_lex/usertool
/home/gavin/LexMachina/src/deus_lex/lexdb
/home/gavin/LexMachina/src/deus_lex/analytics_services
/home/gavin/LexMachina/src/deus_lex/winslow
/home/gavin/LexMachina/src/deus_lex/lexnlp-product/core/scripts
/home/gavin/LexMachina/src/deus_lex/qatool
/home/gavin/LexMachina/src/deus_lex/vendor/pyelasticsearch
```
[OUTPUT.txt](https://github.com/kennethreitz/pipenv/files/1497769/OUTPUT.txt)



##### Steps to replicate

Sadly I have no idea how to make a smaller test case as I have 0 idea what is going on. Happy to try and create one if someone can give me some hint as to how the heck this is even possible.


Discussion:
@gcarothers I would be willing to bet this is related to how pipenv used to handle local path installations... I'm fairly confident it was fixed in #958 and will be working in master.  Can you install pipenv from master and see if it works?
@techalchemy giving that shot, removing lock file before reinstalling as well.
Nope, each run of pipenv install still produces a different set of lines in `easy-install.pth`, I should note that it changes a few times while the install is running too :D

```
(deus_lex-hgZwqY0d) ~/L/s/deus_lex (cleanup/requirements-to-pipenv|✚2…) $ sort /home/gavin/.local/share/virtualenvs/deus_lex-hgZwqY0d/local/lib/python2.7/site-packages/easy-install.pth
/home/gavin/LexMachina/src/deus_lex/analytics_services
/home/gavin/LexMachina/src/deus_lex/bias
/home/gavin/LexMachina/src/deus_lex/citadel
/home/gavin/LexMachina/src/deus_lex/dashboarding
/home/gavin/LexMachina/src/deus_lex/deus_lib
/home/gavin/LexMachina/src/deus_lex/east
/home/gavin/LexMachina/src/deus_lex/lexdb
/home/gavin/LexMachina/src/deus_lex/lexnlp-product/core/scripts
/home/gavin/LexMachina/src/deus_lex/qatool
/home/gavin/LexMachina/src/deus_lex/usertool
/home/gavin/LexMachina/src/deus_lex/vendor/Dalton
/home/gavin/LexMachina/src/deus_lex/vendor/pyelasticsearch
/home/gavin/LexMachina/src/deus_lex/vendor/pyramid-mustache
/home/gavin/LexMachina/src/deus_lex/winslow
```
vs.

```
(deus_lex-hgZwqY0d) ~/L/s/deus_lex (cleanup/requirements-to-pipenv|✚2…) $ sort /home/gavin/.local/share/virtualenvs/deus_lex-hgZwqY0d/local/lib/python2.7/site-packages/easy-install.pth
/home/gavin/LexMachina/src/deus_lex/analytics_services
/home/gavin/LexMachina/src/deus_lex/bias
/home/gavin/LexMachina/src/deus_lex/deus_lib
/home/gavin/LexMachina/src/deus_lex/lexdb
/home/gavin/LexMachina/src/deus_lex/lexnlp-product/core/scripts
/home/gavin/LexMachina/src/deus_lex/qatool
/home/gavin/LexMachina/src/deus_lex/usertool
/home/gavin/LexMachina/src/deus_lex/webhook_handler
/home/gavin/LexMachina/src/deus_lex/winslow
```

hrm, may not have the version from master, hard to tell given master is 8.3.2 as well ;) pip seems to think it replaced it.
```
~/L/s/d/deus_lib (cleanup/requirements-to-pipenv|✚2…) $ pip install --user --upgrade https://github.com/kennethreitz/pipenv/archive/master.zip
Collecting https://github.com/kennethreitz/pipenv/archive/master.zip
  Downloading https://github.com/kennethreitz/pipenv/archive/master.zip (7.1MB)
    100% |████████████████████████████████| 7.1MB 236kB/s 
Requirement already up-to-date: virtualenv in /home/gavin/.local/lib/python2.7/site-packages (from pipenv==8.3.2)
Requirement already up-to-date: pew>=0.1.26 in /home/gavin/.local/lib/python2.7/site-packages (from pipenv==8.3.2)
Requirement already up-to-date: pip>=9.0.1 in /home/gavin/.local/lib/python2.7/site-packages (from pipenv==8.3.2)
Requirement already up-to-date: requests>2.18.0 in /home/gavin/.local/lib/python2.7/site-packages (from pipenv==8.3.2)
Requirement already up-to-date: flake8>=3.0.0 in /home/gavin/.local/lib/python2.7/site-packages (from pipenv==8.3.2)
Requirement already up-to-date: urllib3>=1.21.1 in /home/gavin/.local/lib/python2.7/site-packages (from pipenv==8.3.2)
Requirement already up-to-date: pathlib; python_version == "2.7" in /home/gavin/.local/lib/python2.7/site-packages (from pew>=0.1.26->pipenv==8.3.2)
Requirement already up-to-date: virtualenv-clone>=0.2.5 in /home/gavin/.local/lib/python2.7/site-packages (from pew>=0.1.26->pipenv==8.3.2)
Requirement already up-to-date: shutilwhich; python_version == "2.7" in /home/gavin/.local/lib/python2.7/site-packages (from pew>=0.1.26->pipenv==8.3.2)
Requirement already up-to-date: backports.shutil-get-terminal-size; python_version == "2.7" in /home/gavin/.local/lib/python2.7/site-packages (from pew>=0.1.26->pipenv==8.3.2)
Requirement already up-to-date: setuptools>=17.1 in /home/gavin/.local/lib/python2.7/site-packages (from pew>=0.1.26->pipenv==8.3.2)
Requirement already up-to-date: idna<2.7,>=2.5 in /home/gavin/.local/lib/python2.7/site-packages (from requests>2.18.0->pipenv==8.3.2)
Requirement already up-to-date: chardet<3.1.0,>=3.0.2 in /home/gavin/.local/lib/python2.7/site-packages (from requests>2.18.0->pipenv==8.3.2)
Requirement already up-to-date: certifi>=2017.4.17 in /home/gavin/.local/lib/python2.7/site-packages (from requests>2.18.0->pipenv==8.3.2)
Requirement already up-to-date: mccabe<0.7.0,>=0.6.0 in /home/gavin/.local/lib/python2.7/site-packages (from flake8>=3.0.0->pipenv==8.3.2)
Requirement already up-to-date: enum34; python_version < "3.4" in /home/gavin/.local/lib/python2.7/site-packages (from flake8>=3.0.0->pipenv==8.3.2)
Requirement already up-to-date: configparser; python_version < "3.2" in /home/gavin/.local/lib/python2.7/site-packages (from flake8>=3.0.0->pipenv==8.3.2)
Requirement already up-to-date: pycodestyle<2.4.0,>=2.0.0 in /home/gavin/.local/lib/python2.7/site-packages (from flake8>=3.0.0->pipenv==8.3.2)
Requirement already up-to-date: pyflakes<1.7.0,>=1.5.0 in /home/gavin/.local/lib/python2.7/site-packages (from flake8>=3.0.0->pipenv==8.3.2)
Installing collected packages: pipenv
  Found existing installation: pipenv 8.3.2
    Uninstalling pipenv-8.3.2:
      Successfully uninstalled pipenv-8.3.2
  Running setup.py install for pipenv ... done
Successfully installed pipenv-8.3.2
```
@gcarothers did you run pipenv --rm before each install?  If it's still generating separately, try `pipenv install --sequential`?
`--sequential` does seem to correctly generate all 15 entries!
So this is the same race condition we've discusssd previously. I thought we had a patch merged that forced editable installs to be always done sequentially.

We should look into that and if it was regressed/never worked. I don't have the issue numbers off hand but will try to dig them up tonight.
#919 I think and patch https://github.com/jsatt/pipenv/commit/7c831342f9e6f10d4e55b1ba6cd1573c6bd805e2 ?
@gcarothers that was the original patch which I believe was reverted because it didn't actually do what we wanted.

I thought this was resolved in 8.3.1 but perhaps we prematurely reverted the #919 fix. We need to determine why we're not blocking in this case.
@nateprewitt I helped work on the sequential code, I'll try and find the relevant info tonight.
@nateprewitt the patch in question only attempted to block for VCS dependencies, I think it's simple enough to tack on editable ones as well

Resolving patch:
diff --git a/pipenv/cli.py b/pipenv/cli.py
--- a/pipenv/cli.py
+++ b/pipenv/cli.py
@@ -33,7 +33,7 @@
 from .project import Project
 from .utils import (
     convert_deps_from_pip, convert_deps_to_pip, is_required_version,
-    proper_case, pep423_name, split_vcs, resolve_deps, shellquote, is_vcs,
+    proper_case, pep423_name, split_file, merge_deps, resolve_deps, shellquote, is_vcs,
     python_version, suggest_package, find_windows_executable, is_file,
     prepare_pip_source_args, temp_environ, is_valid_url, download_file,
     get_requirement, need_update_check, touch_update_stamp
@@ -765,10 +765,10 @@ def cleanup_procs(procs, concurrent):
     if skip_lock or only or not project.lockfile_exists:
         if not bare:
             click.echo(crayons.normal(u'Installing dependencies from Pipfile…', bold=True))
-            lockfile = split_vcs(project._lockfile)
+            lockfile = split_file(project._lockfile)
     else:
         with open(project.lockfile_location) as f:
-            lockfile = split_vcs(simplejson.load(f))
+            lockfile = split_file(simplejson.load(f))
 
         if not bare:
             click.echo(
@@ -783,42 +783,16 @@ def cleanup_procs(procs, concurrent):
     # Allow pip to resolve dependencies when in skip-lock mode.
     no_deps = (not skip_lock)
 
-    deps = {}
-    vcs_deps = {}
-
-    # Store dev only deps for a requirements output
-    dev_deps = {}
-    dev_vcs_deps = {}
-
-    # Add development deps if --dev was passed.
-    if dev:
-        deps.update(lockfile['develop'])
-        vcs_deps.update(lockfile.get('develop-vcs', {}))
-
-        # Add only dev deps if requirements was passed
-        if requirements:
-            dev_deps.update(lockfile['develop'])
-            dev_vcs_deps.update(lockfile.get('develop-vcs', {}))
-
-
-    # Install default dependencies, always.
-    deps.update(lockfile['default'] if not only else {})
-    vcs_deps.update(lockfile.get('default-vcs', {}))
-
-    if ignore_hashes:
-        # Remove hashes from generated requirements.
-        for k, v in deps.items():
-            if 'hash' in v:
-                del v['hash']
-
-    # Convert the deps to pip-compatible arguments.
-    deps_list = [(d, ignore_hashes, blocking) for d in convert_deps_to_pip(deps, project, r=False, include_index=True)]
+    deps_list, dev_deps_list = merge_deps(
+        lockfile,
+        project,
+        dev=dev,
+        requirements=requirements,
+        ignore_hashes=ignore_hashes,
+        blocking=blocking,
+        only=only
+    )
     failed_deps_list = []
-
-    if len(vcs_deps):
-        deps_list.extend((d, True, True) for d in convert_deps_to_pip(vcs_deps, project, r=False))
-
-    # --requirements was passed.
     if requirements:
         # Output only default dependencies
         if not dev:
@@ -827,14 +801,9 @@ def cleanup_procs(procs, concurrent):
 
         # Output only dev dependencies
         if dev:
-            dev_deps_list = [(d, ignore_hashes, blocking) for d in convert_deps_to_pip(dev_deps, project, r=False, include_index=True)]
-            if len(dev_vcs_deps):
-                dev_deps_list.extend((d, True, True) for d in convert_deps_to_pip(dev_vcs_deps, project, r=False))
-
             click.echo('\n'.join(d[0] for d in dev_deps_list))
             sys.exit(0)
 
-
     procs = []
 
     deps_list_bar = progress.bar(deps_list, label=INSTALL_LABEL if os.name != 'nt' else '')
diff --git a/pipenv/utils.py b/pipenv/utils.py
--- a/pipenv/utils.py
+++ b/pipenv/utils.py
@@ -919,21 +919,100 @@ def proper_case(package_name):
     return good_name
 
 
-def split_vcs(split_file):
-    """Split VCS dependencies out from file."""
-
-    if 'packages' in split_file or 'dev-packages' in split_file:
-        sections = ('packages', 'dev-packages')
-    elif 'default' in split_file or 'develop' in split_file:
-        sections = ('default', 'develop')
+def split_section(input_file, section_suffix, test_function):
+    """
+    Split a pipfile or a lockfile section out by section name and test function
+    
+        :param dict input_file: A dictionary containing either a pipfile or lockfile
+        :param str section_suffix: A string of the name of the section
+        :param func test_function: A test function to test against the value in the key/value pair
+    
+    >>> split_section(my_lockfile, 'vcs', is_vcs)
+    {
+        'default': {
+            "six": {
+                "hashes": [
+                    "sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb",
+                    "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9"
+                ],
+                "version": "==1.11.0"
+            }
+        },
+        'default-vcs': {
+            "e1839a8": {
+                "editable": true,
+                "path": "."
+            }
+        }
+    }
+    """
+    pipfile_sections = ('packages', 'dev-packages')
+    lockfile_sections = ('default', 'develop')
+    if any(section in input_file for section in pipfile_sections):
+        sections = pipfile_sections
+    elif any(section in input_file for section in lockfile_sections):
+        sections = lockfile_sections
+    else:
+        # return the original file if we can't find any pipfile or lockfile sections
+        return input_file
 
-    # For each vcs entry in a given section, move it to section-vcs.
     for section in sections:
-        entries = split_file.get(section, {})
-        vcs_dict = dict((k, entries.pop(k)) for k in list(entries.keys()) if is_vcs(entries[k]))
-        split_file[section + '-vcs'] = vcs_dict
+        split_dict = {}
+        entries = input_file.get(section, {})
+        for k in list(entries.keys()):
+            if test_function(entries.get(k)):
+                split_dict[k] = entries.pop(k)
+        input_file['-'.join([section, section_suffix])] = split_dict
+    return input_file
+
+
+def split_file(file_dict):
+    """Split VCS and editable dependencies out from file."""
+    sections = {
+        'vcs': is_vcs,
+        'editable': lambda x: hasattr(x, 'keys') and x.get('editable')
+    }
+    for k, func in sections.items():
+        file_dict = split_section(file_dict, k, func)
+    return file_dict
 
-    return split_file
+
+def merge_deps(file_dict, project, dev=False, requirements=False, ignore_hashes=False, blocking=False, only=False):
+    """
+    Given a file_dict, merges dependencies and converts them to pip dependency lists.
+        :param dict file_dict: The result of calling :func:`pipenv.utils.split_file`
+        :param :class:`pipenv.project.Project` project: Pipenv project
+        :param bool dev=False: Flag indicating whether dev dependencies are to be installed 
+        :param bool requirements=False: Flag indicating whether to use a requirements file
+        :param bool ignore_hashes=False:
+        :param bool blocking=False:
+        :param bool only=False:
+        :return: Pip-converted 3-tuples of [deps, requirements_deps]
+    """
+    deps = []
+    requirements_deps = []
+
+    for section in list(file_dict.keys()):
+        # Turn develop-vcs into ['develop', 'vcs']
+        section_name, suffix = section.rsplit('-', 1) if '-' in section and not section == 'dev-packages' else (section, None)
+        if not file_dict[section] or section_name not in ('dev-packages', 'packages', 'default', 'develop'):
+            continue
+        is_dev = section_name in ('dev-packages', 'develop')
+
+        if ignore_hashes:
+            for k, v in file_dict[section]:
+                if 'hash' in v:
+                    del v['hash']
+
+        # Block and ignore hashes for all suffixed sections (vcs/editable)
+        no_hashes = True if suffix else ignore_hashes
+        block = True if suffix else blocking
+        include_index = True if not suffix else False
+        converted = convert_deps_to_pip(file_dict[section], project, r=False, include_index=include_index)
+        deps.extend((d, no_hashes, block) for d in converted)
+        if dev and is_dev and requirements:
+            requirements_deps.extend((d, no_hashes, block) for d in converted)
+    return deps, requirements_deps
 
 
 def recase_file(file_dict):


Test patch:
diff --git a/tests/test_utils.py b/tests/test_utils.py
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -131,11 +131,12 @@ def test_is_required_version(self, version, specified_ver, expected):
     def test_is_vcs(self, entry, expected):
         assert pipenv.utils.is_vcs(entry) is expected
 
-    def test_split_vcs(self):
+    def test_split_file(self):
         pipfile_dict = {
             'packages': {
                 'requests': {'git': 'https://github.com/kennethreitz/requests.git'},
-                'Flask': '*'
+                'Flask': '*',
+                'tablib': {'path': '.', 'editable': True}
             },
             'dev-packages': {
                 'Django': '==1.10',
@@ -143,10 +144,11 @@ def test_split_vcs(self):
                 'crayons': {'hg': 'https://hg.alsonotreal.com/crayons'}
             }
         }
-        split_dict = pipenv.utils.split_vcs(pipfile_dict)
+        split_dict = pipenv.utils.split_file(pipfile_dict)
 
         assert list(split_dict['packages'].keys()) == ['Flask']
         assert split_dict['packages-vcs'] == {'requests': {'git': 'https://github.com/kennethreitz/requests.git'}}
+        assert split_dict['packages-editable'] == {'tablib': {'path': '.', 'editable': True}}
         assert list(split_dict['dev-packages'].keys()) == ['Django']
         assert 'click' in split_dict['dev-packages-vcs']
         assert 'crayons' in split_dict['dev-packages-vcs']