internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: pypa/pipenv

Issue:
Pipenv produces traceback error on running "pipenv shell" after new install
On Elementary OS 0.4.1, under a fresh install of pip (9.0.1) from the Ubuntu repository, running "pipenv shell" in an empty folder produced this:
```
kim@kimberly-whom-death-forgot:~$ pipenv shell
Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.5/dist-packages/pipenv/vendor/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/pipenv/vendor/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.5/dist-packages/pipenv/vendor/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.5/dist-packages/pipenv/vendor/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.5/dist-packages/pipenv/vendor/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/pipenv/cli.py", line 1785, in shell
    load_dot_env()
  File "/usr/local/lib/python3.5/dist-packages/pipenv/cli.py", line 117, in load_dot_env
    denv = dotenv.find_dotenv(os.sep.join([project.project_directory, '.env']))
  File "/usr/local/lib/python3.5/dist-packages/pipenv/project.py", line 62, in project_directory
    return os.path.abspath(os.path.join(self.pipfile_location, os.pardir))
  File "/usr/lib/python3.5/posixpath.py", line 89, in join
    genericpath._check_arg_types('join', a, *p)
  File "/usr/lib/python3.5/genericpath.py", line 143, in _check_arg_types
    (funcname, s.__class__.__name__)) from None
TypeError: join() argument must be str or bytes, not 'NoneType'

```

I expected it to install a default virtual environment, and would have preferred an error message to a stack trace.  I was able to explicitly create the environment using "pipenv install" and then start it with "pipenv shell" but I believe on another system I was able to automatically initially set up an environment with "pipenv shell."


Discussion:

Resolving patch:
diff --git a/pipenv/cli.py b/pipenv/cli.py
--- a/pipenv/cli.py
+++ b/pipenv/cli.py
@@ -1674,9 +1674,6 @@ def lock(three=None, python=False, verbose=False, requirements=False, clear=Fals
 
 def do_shell(three=None, python=False, compat=False, shell_args=None):
 
-    # Ensure that virtualenv is available.
-    ensure_project(three=three, python=python, validate=False)
-
     # Set an environment variable, so we know we're in the environment.
     os.environ['PIPENV_ACTIVE'] = '1'
 
@@ -1781,6 +1778,9 @@ def shell(three=None, python=False, compat=False, shell_args=None, anyway=False)
 
             sys.exit(1)
 
+    # Ensure that virtualenv is available.
+    ensure_project(three=three, python=python, validate=False)
+
     # Load .env file.
     load_dot_env()
 


Test patch:
Repository: pypa/pipenv

Issue:
Missing --index in parse_requirements
Hi guys, I think here:

https://github.com/kennethreitz/pipenv/blob/master/pipenv/cli.py#L236

the `--index` should be tested as well, not only `-i`. I'm not sure though. I can make a PR if I'm correct.

Regards!


Discussion:
it's normally used as -i, but --index would be nice too. send a pr!

Resolving patch:
diff --git a/pipenv/cli.py b/pipenv/cli.py
--- a/pipenv/cli.py
+++ b/pipenv/cli.py
@@ -233,7 +233,7 @@ def import_requirements(r=None, dev=False):
     indexes = []
     # Find and add extra indexes.
     for line in contents.split('\n'):
-        if line.startswith('-i '):
+        if line.startswith(('-i ', '--index ')):
             indexes.append(line.split()[1])
 
     reqs = [f for f in parse_requirements(r, session=pip._vendor.requests)]


Test patch:
Repository: pypa/pipenv

Issue:
should factory-boy be factory_boy?
```
$ pipenv install factory_boy --dev
Did you mean factory-boy? [Y/n]: ^CAborted!
```

https://pypi.python.org/pypi/factory_boy

https://github.com/kennethreitz/pipenv/blob/f994103507d6ccdfdc73aef8b598647ac50560ac/pipenv/utils.py#L135



Discussion:
@AlJohri yeah it looks like it should be according to the pypi and github links.  Can you submit a PR?

Resolving patch:
diff --git a/pipenv/utils.py b/pipenv/utils.py
--- a/pipenv/utils.py
+++ b/pipenv/utils.py
@@ -132,7 +132,7 @@
     'multi-key-dict', 'fuzzywuzzy', 'fasteners', 'youtube-dl',
     'pycryptodome', 'smmap', 'gitdb', 'setuptools-git', 'pager',
     'python-subunit', 'warlock', 'extras', 'capstone', 'httpretty',
-    'factory-boy', 'webtest', 'django-cors-headers', 'codeintel', 'suds',
+    'factory_boy', 'webtest', 'django-cors-headers', 'codeintel', 'suds',
     'pyodbc', 'geoip2', 'filechunkio', 'fixtures', 'pysocks', 'statsmodels',
     'google-auth-httplib2', 'kafka-python', 'applicationinsights', 'yarl',
     'cassandra-driver', 'azure-mgmt-compute', 'pathlib', 'python-jwt', 'sh',


Test patch:
Repository: pypa/pipenv

Issue:
Editable dependencies have a race condition when installing
When installing editable dependencies, they must update `site-packages/easy-install.pth` with the path to the src of the repo checkout, for it to be able to be imported. By default pipenv installed all dependencies in blocks that run concurrently, but since multiple editable installs edit the same file this creates a race condition where multiple files may be trying to edit at the same time, resulting in some not being included.

In about 10 runs of `pipenv install` with the Pipfile below, 4 only included the second (variant) path, 2 only included the first (affect) path, and 4 included both paths. This can be worked around using `--sequential` at the cost of installs being much slower.

Ideally, pipenv could gather all editable dependencies and run them all sequentially at the end of the install process so as to not cause the race condition.

Python 2.7
Pipenv 8.2.7

Pipfile:
```
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[dev-packages]

[packages]
django-affect = {ref = "master", git = "https://github.com/jsatt/django-affect.git", editable = true}
django-variant = {ref = "master", git = "https://github.com/jsatt/django-variant.git", editable = true}
```


Discussion:
This is correct.  Feel free to submit a PR if you have a fix.  Otherwise I'm marking it for fixing!  Thanks for the report @jsatt 

Resolving patch:
diff --git a/pipenv/cli.py b/pipenv/cli.py
--- a/pipenv/cli.py
+++ b/pipenv/cli.py
@@ -783,11 +783,11 @@ def cleanup_procs(procs, concurrent):
                 del v['hash']
 
     # Convert the deps to pip-compatible arguments.
-    deps_list = [(d, ignore_hashes) for d in convert_deps_to_pip(deps, project, r=False, include_index=True)]
+    deps_list = [(d, ignore_hashes, blocking) for d in convert_deps_to_pip(deps, project, r=False, include_index=True)]
     failed_deps_list = []
 
     if len(vcs_deps):
-        deps_list.extend((d, True) for d in convert_deps_to_pip(vcs_deps, project, r=False))
+        deps_list.extend((d, True, True) for d in convert_deps_to_pip(vcs_deps, project, r=False))
 
     # --requirements was passed.
     if requirements:
@@ -798,7 +798,7 @@ def cleanup_procs(procs, concurrent):
 
     deps_list_bar = progress.bar(deps_list, label=INSTALL_LABEL if os.name != 'nt' else '')
 
-    for dep, ignore_hash in deps_list_bar:
+    for dep, ignore_hash, block in deps_list_bar:
         if len(procs) < PIPENV_MAX_SUBPROCESS:
             # Use a specific index, if specified.
             index = None
@@ -814,7 +814,7 @@ def cleanup_procs(procs, concurrent):
                 allow_global=allow_global,
                 no_deps=no_deps,
                 verbose=verbose,
-                block=blocking,
+                block=block,
                 index=index
             )
 


Test patch:
Repository: pypa/pipenv

Issue:
`Using /usr/local/bin/python3.6m to create virtualenv…` is printed to stdout when executing `pipenv lock -r > requirements.txt` if there's no existing virtualenv.
This can be observed when `pipenv lock -r > requirements.txt` is used to generate `requirements.txt` in an environment without an existing virtualenv.

##### My environment
1. OS: CI(Docker Image) `python:3.6`(based on `Debian 9.0 stretch`)
1. Python version: `Python 3.6.3`
1. Pipenv version: `pipenv, version 8.3.2`

##### Expected result
Only dependencies from `Pipfile` should be printed into `requirements.txt`.

##### Actual result
When the former command is executed under an environment without an existing virtualenv, it not only prints the dependencies but also prints `Using /usr/local/bin/python3.6m to create virtualenv…` into the file.

##### Steps to replicate
As described above.

##### Workarounds or Solutions
The current workaround I found is to execute any `PipEnv` commands prior to the generation of `requirements.txt` as this would let `PipEnv` create the Virtual Environment.

The solution would be to suppress the output.

Moreover, IMO, `PipEnv` should only create virtualenvs when it's needed. `pipenv lock -r` shouldn't create virtualenvs since there's no actual use of the virtualenv under this situation and it consumes a long time and a lot of resources to create a virtualenv and install dependencies.



Discussion:

Resolving patch:
diff --git a/pipenv/cli.py b/pipenv/cli.py
--- a/pipenv/cli.py
+++ b/pipenv/cli.py
@@ -937,7 +937,7 @@ def do_create_virtualenv(python=None, site_packages=False):
             crayons.normal('Using', bold=True),
             crayons.red(python, bold=True),
             crayons.normal(u'to create virtualenv…', bold=True)
-        ))
+        ), err=True)
 
     # Use virtualenv's -p python.
     if python:


Test patch:
Repository: pypa/pipenv

Issue:
pipenv broken
![image](https://user-images.githubusercontent.com/2430381/32952777-45c9836e-cb7c-11e7-8fd0-ca42fb705b1e.png)

Occurred in 44053b52bbbda1884edd12baecbe7f3c4d251c98

could be because im on python 2 and FileNotFoundError doesnt exist? or maybe it just needs `from os import FileNotFoundError`


Discussion:
I just got a similar error when trying to run on Python 2. I believe `FileNotFoundError` was introduced in Python 3.5 as a subclass of OSError.
Another issue: `os.utime` needs a `None` second argument on Python 2.

Resolving patch:
diff --git a/pipenv/utils.py b/pipenv/utils.py
--- a/pipenv/utils.py
+++ b/pipenv/utils.py
@@ -1060,7 +1060,7 @@ def touch_update_stamp():
     mkdir_p(PIPENV_CACHE_DIR)
     p = os.sep.join((PIPENV_CACHE_DIR, '.pipenv_update_check'))
     try:
-        os.utime(p)
-    except FileNotFoundError:
+        os.utime(p, None)
+    except OSError:
         with open(p, 'w') as fh:
             fh.write('')


Test patch:
Repository: pypa/pipenv

Issue:
pipenv starts slow when IPython is installed.
IPython is imported when importing dotenv. 
(ref: theskumar/python-dotenv#84 and [import profile](https://paste.ubuntu.com/26409167/))

Since pipenv uses patched version of dotenv, pipenv should port upstream fix
or patch `dotenv/__init__.py` to stop importing dotenv.ipython.

##### Describe your environment

1. Ubuntu 17.10
1. Python version: 3.7.0a4
1. Pipenv version: 9.0.3

##### Steps to replicate

* Install Python 3.7.0a4 or newer
* ` PYTHONPROFILEIMPORTTIME=1 path/to/pipenv --version 2>pipenv-version`


Discussion:

Resolving patch:
diff --git a/pipenv/patched/dotenv/__init__.py b/pipenv/patched/dotenv/__init__.py
--- a/pipenv/patched/dotenv/__init__.py
+++ b/pipenv/patched/dotenv/__init__.py
@@ -1,8 +1,4 @@
 from .cli import get_cli_string
 from .main import load_dotenv, get_key, set_key, unset_key, find_dotenv
-try:
-    from .ipython import load_ipython_extension
-except ImportError:
-    pass
 
-__all__ = ['get_cli_string', 'load_dotenv', 'get_key', 'set_key', 'unset_key', 'find_dotenv', 'load_ipython_extension']
+__all__ = ['get_cli_string', 'load_dotenv', 'get_key', 'set_key', 'unset_key', 'find_dotenv']
diff --git a/pipenv/patched/dotenv/ipython.py b/pipenv/patched/dotenv/ipython.py
deleted file mode 100644
--- a/pipenv/patched/dotenv/ipython.py
+++ /dev/null
@@ -1,40 +0,0 @@
-from __future__ import print_function
-from .main import load_dotenv, find_dotenv
-
-from IPython.core.magic import Magics, magics_class, line_magic
-from IPython.core.magic_arguments import (argument, magic_arguments,
-                                          parse_argstring)
-
-
-@magics_class
-class IPythonDotEnv(Magics):
-
-    @magic_arguments()
-    @argument(
-        '-o', '--override', action='store_true',
-        help="Indicate to override existing variables"
-    )
-    @argument(
-        '-v', '--verbose', action='store_true',
-        help="Indicate function calls to be verbose"
-    )
-    @argument('dotenv_path', nargs='?', type=str, default='.env',
-              help='Search in increasingly higher folders for the `dotenv_path`')
-    @line_magic
-    def dotenv(self, line):
-        args = parse_argstring(self.dotenv, line)
-        # Locate the .env file
-        dotenv_path = args.dotenv_path
-        try:
-            dotenv_path = find_dotenv(dotenv_path, True, True)
-        except IOError:
-            print("cannot find .env file")
-            return
-
-        # Load the .env file
-        load_dotenv(dotenv_path, verbose=args.verbose, override=args.override)
-
-
-def load_ipython_extension(ipython):
-    """Register the %dotenv magic."""
-    ipython.register_magics(IPythonDotEnv)


Test patch:
Repository: pypa/pipenv

Issue:
'pipenv shell' fails if /bin/sh is not bash (depends on 'source')

##### Describe your environment

1. FreeBSD 11.1-RELEASE-p4 
1. Python version: Python 3.6.4
1. Pipenv version: pipenv, version 9.0.3

##### Expected result

pipenv should not assume /bin/sh is bash

##### Actual result

```
$ pipenv shell
pipenv shell
Spawning environment shell (/bin/sh). Use 'exit' to leave.
[paulc@dev6] /usr/home/paulc $ source /home/paulc/.local/share/virtualenvs/paulc-fQQTQRg4/bin/activate
source /home/paulc/.local/share/virtualenvs/paulc-fQQTQRg4/bin/activate
/bin/sh: source: not found
```

The following patch solves this (bash also supports .)

```
--- cli.py.old	2018-01-28 16:18:27.232506000 +0000
+++ cli.py	2018-01-28 16:18:53.234899000 +0000
@@ -1185,7 +1185,7 @@
     venv_location = project.virtualenv_location.replace(' ', r'\ ')
 
     if source:
-        return 'source {0}/bin/activate{1}'.format(venv_location, suffix)
+        return '. {0}/bin/activate{1}'.format(venv_location, suffix)
     else:
         return '{0}/bin/activate'.format(venv_location)
```
 




Discussion:

Resolving patch:
diff --git a/pipenv/core.py b/pipenv/core.py
--- a/pipenv/core.py
+++ b/pipenv/core.py
@@ -1173,7 +1173,7 @@ def activate_virtualenv(source=True):
     venv_location = project.virtualenv_location.replace(' ', r'\ ')
 
     if source:
-        return 'source {0}/bin/activate{1}'.format(venv_location, suffix)
+        return '. {0}/bin/activate{1}'.format(venv_location, suffix)
     else:
         return '{0}/bin/activate'.format(venv_location)
 


Test patch:
Repository: pypa/pipenv

Issue:
documentation links broken
Shocked at the version number jumps `pipenv` has made lately, I updated and `pip --envs` guided me to what I wanted (locating `venvs` *with* a project);
```
$ pipenv --envs
The following environment variables can be set, to do various things:

  - PIPENV_SHELL_FANCY
  - PIPENV_VENV_IN_PROJECT
  - PIPENV_COLORBLIND
  - PIPENV_NOSPIN
  - PIPENV_PIPFILE
  - PIPENV_DEFAULT_PYTHON_VERSION
  - PIPENV_DONT_LOAD_ENV
  - PIPENV_YES
  - PIPENV_MAX_SUBPROCESS
  - PIPENV_MAX_DEPTH
  - PIPENV_VIRTUALENV
  - PIPENV_USE_SYSTEM
  - PIPENV_USE_HASHES
  - PIPENV_SKIP_VALIDATION
  - PIPENV_DOTENV_LOCATION
  - PIPENV_HIDE_EMOJIS
  - PIPENV_TIMEOUT
  - PIPENV_INSTALL_TIMEOUT
  - PIPENV_DONT_USE_PYENV
  - PIPENV_SHELL

You can learn more at:
   http://docs.pipenv.org/en/latest/advanced.html#configuration-with-environment-variables
```

Problem is:   that link is broken ("Sorry - that page doesn't exist").

Ok - no problem.   I'll search for "configuration with environment variables" - great!  Two links found;  one that looks like a TOC entry, and one like the section I want.   But - **both** those links are broken too.

What gives?

Well, it turns out that taking the `/en/latest` out of any of those links gets you to the desired place.

And (in general!)  you might want to avoid locking links on to the *en* encoding, anyway.


Discussion:
thanks! this is for ssl reasons. we'll update the link. 
fixed in master
Looks like it is still broken in pipenv 0.9.3:
```
https://docs.pipenv.org/advanced.html#configuration-with-environment-variables
```
should be:

```
https://docs.pipenv.org/advanced/#configuration-with-environment-variables
```

Resolving patch:
diff --git a/pipenv/cli.py b/pipenv/cli.py
--- a/pipenv/cli.py
+++ b/pipenv/cli.py
@@ -108,7 +108,7 @@ def cli(
                 click.echo('  - {0}'.format(crayons.normal(key, bold=True)))
 
         click.echo('\nYou can learn more at:\n   {0}'.format(
-            crayons.green('http://docs.pipenv.org/advanced.html#configuration-with-environment-variables')
+            crayons.green('http://docs.pipenv.org/advanced/#configuration-with-environment-variables')
         ))
         sys.exit(0)
 


Test patch:
Repository: pypa/pipenv

Issue:
prettytoml deletes unrelated elements when removing items
From #1507.

prettytoml has a bug in `table.py::TableElement.__delitem__` that it deletes a key when the line before it contains inline comment. A minimal example:

```python
import pipenv   # noqa

from prettytoml import lexer
from prettytoml.elements.atomic import AtomicElement
from prettytoml.elements.metadata import (
    WhitespaceElement, PunctuationElement, CommentElement,
)
from prettytoml.elements.table import TableElement


def test_table():

    initial_toml = """id=42 # My id\nage=14"""
    tokens = tuple(lexer.tokenize(initial_toml))
    table = TableElement([
        AtomicElement(tokens[0:1]),
        PunctuationElement(tokens[1:2]),
        AtomicElement(tokens[2:3]),
        WhitespaceElement(tokens[3:4]),
        CommentElement(tokens[4:6]),

        AtomicElement(tokens[6:7]),
        PunctuationElement(tokens[7:8]),
        AtomicElement(tokens[8:9]),
    ])

    assert set(table.items()) == {('id', 42), ('age', 14)}

    del table['id']
    assert set(table.items()) == {('age', 14)}
```

This test case would fail on the final assertion. `table` at this point would be empty, but it should not.


Discussion:

Resolving patch:
diff --git a/pipenv/patched/prettytoml/elements/table.py b/pipenv/patched/prettytoml/elements/table.py
--- a/pipenv/patched/prettytoml/elements/table.py
+++ b/pipenv/patched/prettytoml/elements/table.py
@@ -105,7 +105,7 @@ def __delitem__(self, key):
         preceding_newline = self._find_preceding_newline(begin)
         if preceding_newline >= 0:
             begin = preceding_newline
-        end = self._find_following_newline(begin)
+        end = self._find_following_line_terminator(begin)
         if end < 0:
             end = len(tuple(self._sub_elements))
         self._sub_elements = self.sub_elements[:begin] + self.sub_elements[end:]
diff --git a/pipenv/patched/prettytoml/elements/traversal/__init__.py b/pipenv/patched/prettytoml/elements/traversal/__init__.py
--- a/pipenv/patched/prettytoml/elements/traversal/__init__.py
+++ b/pipenv/patched/prettytoml/elements/traversal/__init__.py
@@ -76,9 +76,9 @@ def _find_following_line_terminator(self, index):
         following_comment = self._find_following_comment(index)
         following_newline = self._find_following_newline(index)
 
-        if following_comment == float('-inf'):
+        if following_comment == float('inf'):
             return following_newline
-        if following_newline == float('inf'):
+        if following_newline == float('-inf'):
             return following_comment
 
         if following_newline < following_comment:


Test patch:
Repository: pypa/pipenv

Issue:
pipenv update --outdated crash on empty requirements
Not the most critical bug but:

```bash
$ pipenv install
(...)
```
```bash
$ pipenv update --outdated
Traceback (most recent call last):
  File "/usr/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/usr/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/pipenv/vendor/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/pipenv/cli.py", line 340, in update
    core.do_outdated()
  File "/usr/lib/python3.6/site-packages/pipenv/core.py", line 1705, in do_outdated
    packages.update(convert_deps_from_pip(result))
  File "/usr/lib/python3.6/site-packages/pipenv/utils.py", line 481, in convert_deps_from_pip
    req = get_requirement(dep)
  File "/usr/lib/python3.6/site-packages/pipenv/utils.py", line 128, in get_requirement
    req = [r for r in requirements.parse(dep)][0]
IndexError: list index out of range
```




Discussion:

Resolving patch:
diff --git a/pipenv/core.py b/pipenv/core.py
--- a/pipenv/core.py
+++ b/pipenv/core.py
@@ -1701,6 +1701,7 @@ def do_py(system=False):
 def do_outdated():
     packages = {}
     results = delegator.run('{0} freeze'.format(which('pip'))).out.strip().split('\n')
+    results = filter(bool, results)
     for result in results:
         packages.update(convert_deps_from_pip(result))
 


Test patch: