Repository: pypa/pipenv

Issue:
Collisions of virtual environments
### Issue description
On OS which handles file systems in case-sensitive manner (e.g. Linux based), `pipenv` mistakenly uses virtual environment which corresponds to similar-named directory if it exists.

### Expected result
`pipenv` creates and uses different virtual environments for projects in different directories which names are equals when they are normalized to lower or upper case.

### Actual result
`pipenv` uses single virtual environment for different projects.

### Steps to replicate
```bash
mkdir pipenv-tests/{test,TEST} -p
cd pipenv-tests/test
pipenv shell
pipenv --venv
exit
cd ../TEST
pipenv shell
pipenv --venv
```
Here is what I've got using d985784dee94a8b54d870ec4e923be11592ceb10 revision of `pipenv` (current `master`):
```bash
~/projects $ mkdir pipenv-tests/{test,TEST} -p
~/projects $ cd pipenv-tests/test
~/projects/pipenv-tests/test $ pipenv shell
Creating a virtualenv for this project…
Pipfile: /home/mim/projects/pipenv-tests/test/Pipfile
Using /usr/bin/python3 (3.6.6) to create virtualenv…
✔ Complete Running... Installing setuptools, pip, wheel...done.
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/mim/.local/share/virtualenvs/test-Ic8GqeXz/bin/python3
Also creating executable in /home/mim/.local/share/virtualenvs/test-Ic8GqeXz/bin/python
Installing setuptools, pip, wheel...done.
Virtualenv location: /home/mim/.local/share/virtualenvs/test-Ic8GqeXz
Creating a Pipfile for this project…
Launching subshell in virtual environment…
~/projects/pipenv-tests/test $  . /home/mim/.local/share/virtualenvs/test-Ic8GqeXz/bin/activate
(test) ~/projects/pipenv-tests/test $ pipenv --venv
/home/mim/.local/share/virtualenvs/test-Ic8GqeXz
(test) ~/projects/pipenv-tests/test $ exit
exit
~/projects/pipenv-tests/test $ cd ../TEST
~/projects/pipenv-tests/TEST $ pipenv shell
Creating a Pipfile for this project…
Launching subshell in virtual environment…
~/projects/pipenv-tests/TEST $  . /home/mim/.local/share/virtualenvs/test-Ic8GqeXz/bin/activate
(test) ~/projects/pipenv-tests/TEST $ pipenv --venv
/home/mim/.local/share/virtualenvs/test-Ic8GqeXz
```
As you can see, `/home/mim/.local/share/virtualenvs/test-Ic8GqeXz` was used for both `test` and `TEST` projects.

### Environment
```bash
$ lsb_release -d
Description:	Ubuntu 18.04.1 LTS
```

<details><summary>$ pipenv --support</summary>

Pipenv version: `'2018.10.14.dev0'`

Pipenv location: `'/home/mim/.local/lib/python3.6/site-packages/pipenv'`

Python location: `'/usr/bin/python3'`

Python installations found:

  - `3.7.0`: `/usr/bin/python3.7m`
  - `3.7.0`: `/usr/bin/python3.7`
  - `3.6.6`: `/usr/bin/python3.6`
  - `3.6.6`: `/usr/bin/python3.6m`
  - `2.7.15rc1`: `/usr/bin/python2`

PEP 508 Information:

```
{'implementation_name': 'cpython',
 'implementation_version': '3.6.6',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '4.15.0-38-generic',
 'platform_system': 'Linux',
 'platform_version': '#41-Ubuntu SMP Wed Oct 10 10:59:38 UTC 2018',
 'python_full_version': '3.6.6',
 'python_version': '3.6',
 'sys_platform': 'linux'}
```

System environment variables:

  - `CLUTTER_IM_MODULE`
  - `LS_COLORS`
  - `LC_MEASUREMENT`
  - `LESSCLOSE`
  - `LC_PAPER`
  - `LC_MONETARY`
  - `XDG_MENU_PREFIX`
  - `LANG`
  - `DISPLAY`
  - `GNOME_SHELL_SESSION_MODE`
  - `COLORTERM`
  - `USERNAME`
  - `XDG_VTNR`
  - `SSH_AUTH_SOCK`
  - `MANDATORY_PATH`
  - `LC_NAME`
  - `XDG_SESSION_ID`
  - `USER`
  - `DESKTOP_SESSION`
  - `QT4_IM_MODULE`
  - `TEXTDOMAINDIR`
  - `GNOME_TERMINAL_SCREEN`
  - `DEFAULTS_PATH`
  - `PWD`
  - `HOME`
  - `TEXTDOMAIN`
  - `SSH_AGENT_PID`
  - `QT_ACCESSIBILITY`
  - `XDG_SESSION_TYPE`
  - `XDG_DATA_DIRS`
  - `XDG_SESSION_DESKTOP`
  - `LC_ADDRESS`
  - `GJS_DEBUG_OUTPUT`
  - `LC_NUMERIC`
  - `GTK_MODULES`
  - `PAPERSIZE`
  - `WINDOWPATH`
  - `VTE_VERSION`
  - `TERM`
  - `SHELL`
  - `QT_IM_MODULE`
  - `XMODIFIERS`
  - `IM_CONFIG_PHASE`
  - `XDG_CURRENT_DESKTOP`
  - `GPG_AGENT_INFO`
  - `GNOME_TERMINAL_SERVICE`
  - `XDG_SEAT`
  - `SHLVL`
  - `LC_TELEPHONE`
  - `GDMSESSION`
  - `GNOME_DESKTOP_SESSION_ID`
  - `LOGNAME`
  - `DBUS_SESSION_BUS_ADDRESS`
  - `XDG_RUNTIME_DIR`
  - `XAUTHORITY`
  - `XDG_CONFIG_DIRS`
  - `PATH`
  - `LC_IDENTIFICATION`
  - `GJS_DEBUG_TOPICS`
  - `SESSION_MANAGER`
  - `LESSOPEN`
  - `GTK_IM_MODULE`
  - `LC_TIME`
  - `_`
  - `OLDPWD`
  - `PIP_DISABLE_PIP_VERSION_CHECK`
  - `PIP_SHIMS_BASE_MODULE`
  - `PYTHONDONTWRITEBYTECODE`
  - `PIP_PYTHON_PATH`
  - `PYTHONFINDER_IGNORE_UNSUPPORTED`

Pipenv–specific environment variables:


Debug–specific environment variables:

  - `PATH`: `/home/mim/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin`
  - `SHELL`: `/bin/bash`
  - `LANG`: `en_US.UTF-8`
  - `PWD`: `/home/mim/projects`


---------------------------

</details>

### Root cause
I tried to investigate this bug and found that it was introduced by #2513.
The root cause of the issue is that `os.name != "nt"` condition [was mistakenly converted](https://github.com/pypa/pipenv/pull/2513/files#diff-7c0c15ee4eba8c237e3318a395816a13R283) to `fnmatch.fnmatch('A', 'a')` when it should have been converted to `not fnmatch.fnmatch('A', 'a')`.

### Solution
I created a PR #2883 that fixes this issue.
Collisions of virtual environments
### Issue description
On OS which handles file systems in case-sensitive manner (e.g. Linux based), `pipenv` mistakenly uses virtual environment which corresponds to similar-named directory if it exists.

### Expected result
`pipenv` creates and uses different virtual environments for projects in different directories which names are equals when they are normalized to lower or upper case.

### Actual result
`pipenv` uses single virtual environment for different projects.

### Steps to replicate
```bash
mkdir pipenv-tests/{test,TEST} -p
cd pipenv-tests/test
pipenv shell
pipenv --venv
exit
cd ../TEST
pipenv shell
pipenv --venv
```
Here is what I've got using d985784dee94a8b54d870ec4e923be11592ceb10 revision of `pipenv` (current `master`):
```bash
~/projects $ mkdir pipenv-tests/{test,TEST} -p
~/projects $ cd pipenv-tests/test
~/projects/pipenv-tests/test $ pipenv shell
Creating a virtualenv for this project…
Pipfile: /home/mim/projects/pipenv-tests/test/Pipfile
Using /usr/bin/python3 (3.6.6) to create virtualenv…
✔ Complete Running... Installing setuptools, pip, wheel...done.
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/mim/.local/share/virtualenvs/test-Ic8GqeXz/bin/python3
Also creating executable in /home/mim/.local/share/virtualenvs/test-Ic8GqeXz/bin/python
Installing setuptools, pip, wheel...done.
Virtualenv location: /home/mim/.local/share/virtualenvs/test-Ic8GqeXz
Creating a Pipfile for this project…
Launching subshell in virtual environment…
~/projects/pipenv-tests/test $  . /home/mim/.local/share/virtualenvs/test-Ic8GqeXz/bin/activate
(test) ~/projects/pipenv-tests/test $ pipenv --venv
/home/mim/.local/share/virtualenvs/test-Ic8GqeXz
(test) ~/projects/pipenv-tests/test $ exit
exit
~/projects/pipenv-tests/test $ cd ../TEST
~/projects/pipenv-tests/TEST $ pipenv shell
Creating a Pipfile for this project…
Launching subshell in virtual environment…
~/projects/pipenv-tests/TEST $  . /home/mim/.local/share/virtualenvs/test-Ic8GqeXz/bin/activate
(test) ~/projects/pipenv-tests/TEST $ pipenv --venv
/home/mim/.local/share/virtualenvs/test-Ic8GqeXz
```
As you can see, `/home/mim/.local/share/virtualenvs/test-Ic8GqeXz` was used for both `test` and `TEST` projects.

### Environment
```bash
$ lsb_release -d
Description:	Ubuntu 18.04.1 LTS
```

<details><summary>$ pipenv --support</summary>

Pipenv version: `'2018.10.14.dev0'`

Pipenv location: `'/home/mim/.local/lib/python3.6/site-packages/pipenv'`

Python location: `'/usr/bin/python3'`

Python installations found:

  - `3.7.0`: `/usr/bin/python3.7m`
  - `3.7.0`: `/usr/bin/python3.7`
  - `3.6.6`: `/usr/bin/python3.6`
  - `3.6.6`: `/usr/bin/python3.6m`
  - `2.7.15rc1`: `/usr/bin/python2`

PEP 508 Information:

```
{'implementation_name': 'cpython',
 'implementation_version': '3.6.6',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '4.15.0-38-generic',
 'platform_system': 'Linux',
 'platform_version': '#41-Ubuntu SMP Wed Oct 10 10:59:38 UTC 2018',
 'python_full_version': '3.6.6',
 'python_version': '3.6',
 'sys_platform': 'linux'}
```

System environment variables:

  - `CLUTTER_IM_MODULE`
  - `LS_COLORS`
  - `LC_MEASUREMENT`
  - `LESSCLOSE`
  - `LC_PAPER`
  - `LC_MONETARY`
  - `XDG_MENU_PREFIX`
  - `LANG`
  - `DISPLAY`
  - `GNOME_SHELL_SESSION_MODE`
  - `COLORTERM`
  - `USERNAME`
  - `XDG_VTNR`
  - `SSH_AUTH_SOCK`
  - `MANDATORY_PATH`
  - `LC_NAME`
  - `XDG_SESSION_ID`
  - `USER`
  - `DESKTOP_SESSION`
  - `QT4_IM_MODULE`
  - `TEXTDOMAINDIR`
  - `GNOME_TERMINAL_SCREEN`
  - `DEFAULTS_PATH`
  - `PWD`
  - `HOME`
  - `TEXTDOMAIN`
  - `SSH_AGENT_PID`
  - `QT_ACCESSIBILITY`
  - `XDG_SESSION_TYPE`
  - `XDG_DATA_DIRS`
  - `XDG_SESSION_DESKTOP`
  - `LC_ADDRESS`
  - `GJS_DEBUG_OUTPUT`
  - `LC_NUMERIC`
  - `GTK_MODULES`
  - `PAPERSIZE`
  - `WINDOWPATH`
  - `VTE_VERSION`
  - `TERM`
  - `SHELL`
  - `QT_IM_MODULE`
  - `XMODIFIERS`
  - `IM_CONFIG_PHASE`
  - `XDG_CURRENT_DESKTOP`
  - `GPG_AGENT_INFO`
  - `GNOME_TERMINAL_SERVICE`
  - `XDG_SEAT`
  - `SHLVL`
  - `LC_TELEPHONE`
  - `GDMSESSION`
  - `GNOME_DESKTOP_SESSION_ID`
  - `LOGNAME`
  - `DBUS_SESSION_BUS_ADDRESS`
  - `XDG_RUNTIME_DIR`
  - `XAUTHORITY`
  - `XDG_CONFIG_DIRS`
  - `PATH`
  - `LC_IDENTIFICATION`
  - `GJS_DEBUG_TOPICS`
  - `SESSION_MANAGER`
  - `LESSOPEN`
  - `GTK_IM_MODULE`
  - `LC_TIME`
  - `_`
  - `OLDPWD`
  - `PIP_DISABLE_PIP_VERSION_CHECK`
  - `PIP_SHIMS_BASE_MODULE`
  - `PYTHONDONTWRITEBYTECODE`
  - `PIP_PYTHON_PATH`
  - `PYTHONFINDER_IGNORE_UNSUPPORTED`

Pipenv–specific environment variables:


Debug–specific environment variables:

  - `PATH`: `/home/mim/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin`
  - `SHELL`: `/bin/bash`
  - `LANG`: `en_US.UTF-8`
  - `PWD`: `/home/mim/projects`


---------------------------

</details>

### Root cause
I tried to investigate this bug and found that it was introduced by #2513.
The root cause of the issue is that `os.name != "nt"` condition [was mistakenly converted](https://github.com/pypa/pipenv/pull/2513/files#diff-7c0c15ee4eba8c237e3318a395816a13R283) to `fnmatch.fnmatch('A', 'a')` when it should have been converted to `not fnmatch.fnmatch('A', 'a')`.

### Solution
I created a PR #2883 that fixes this issue.


Discussion:

Resolving patch:
diff --git a/pipenv/project.py b/pipenv/project.py
--- a/pipenv/project.py
+++ b/pipenv/project.py
@@ -449,7 +449,7 @@ def get_name(name, location):
         #   In-project venv
         #   "Proper" path casing (on non-case-sensitive filesystems).
         if (
-            fnmatch.fnmatch("A", "a")
+            not fnmatch.fnmatch("A", "a")
             or self.is_venv_in_project()
             or get_workon_home().joinpath(venv_name).exists()
         ):


Test patch: