Repository: python-poetry/poetry

Issue:
Poetry always detects venvs created by mingw-w64-x86_64-python (MSYS2) as broken
<!-- Checked checkbox should look like this: [x] -->
- [X] I am on the [latest](https://github.com/python-poetry/poetry/releases/latest) Poetry version.
- [X] I have searched the [issues](https://github.com/python-poetry/poetry/issues) of this repo and believe that this is not a duplicate.
- [X] If an exception occurs when executing a command, I executed it again in debug mode (`-vvv` option).

<!--
  Once those are done, if you're able to fill in the following list with your information,
  it'd be very helpful to whoever handles the issue.
-->

- **OS version and name**: Windows 10
- **Poetry version**: 1.0.10
- **Link of a [Gist](https://gist.github.com/) with the contents of your pyproject.toml file**: 

```toml
[tool.poetry]
name = "poetry-demo2"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]

[tool.poetry.dependencies]
python = "^3.8"
pendulum = "^2.1.2"

[tool.poetry.dev-dependencies]
pytest = "^5.2"

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
```

## Issue
<!-- Now feel free to write your issue, but please be descriptive! Thanks again 🙌 ❤️ -->

When using MSYS2, package `mingw-w64-x86_64-python`  (https://packages.msys2.org/package/mingw-w64-x86_64-python) venvs are created with POSIX-style layout :

```
 daniel@GALILEO ~/A/L/p/C/v/poetry-demo2-raCoCXDb-py3.8> pwd
/c/Users/Daniel/AppData/Local/pypoetry/Cache/virtualenvs/poetry-demo2-raCoCXDb-py3.8
daniel@GALILEO ~/A/L/p/C/v/poetry-demo2-raCoCXDb-py3.8> ls -al
total 5
drwxr-xr-x 1 daniel daniel   0 Aug 29 23:05 ./
drwxr-xr-x 1 daniel daniel   0 Aug 29 23:05 ../
drwxr-xr-x 1 daniel daniel   0 Aug 29 23:06 bin/
drwxr-xr-x 1 daniel daniel   0 Aug 29 23:05 include/
drwxr-xr-x 1 daniel daniel   0 Aug 29 23:05 lib/
-rw-r--r-- 1 daniel daniel 106 Aug 29 23:05 pyvenv.cfg
```

Every subsequent command will display the message "The virtual environment found in <path> seems to be broken" and the venv will be recreated. I

**Steps to reproduce**

1 - Install MSYS2
2 - From MSYS shell, install python mingw64 build : `pacman -S mingw-w64-x86_64-python`
3 - Install poetry
4 - `poetry new poetry-demo`
5 - `poetry install` 
6 - `poetry show` . The message will be displayed and venv will be recreated.

The cause seems to be in  https://github.com/python-poetry/poetry/blob/c22052cb7a37dfe45c3cb02650eb7b5e8450b940/poetry/utils/env.py#L746

As the system is detected to be Windows it expects the bin dir to be `Scripts` which is not the case for venvs created with this python distro. 

I changed this line to be `bin_dir = "bin"` and it seems to work correctly. 

it is possible to detect this python distro with `sysconfig.get_platform()` . It will return `mingw` . See https://stackoverflow.com/questions/35956180/how-to-determine-the-python-is-mingw-or-official-build



Discussion:
I can reproduce this issue with poetry 1.1.4. If this seems like a change that would be merged, I can submit a PR.

A short term work around is that mingw users can disable poetry managing virtualens with `poetry config virtualenvs.create false`.
Possibly related: #3598

Resolving patch:
diff --git a/poetry/utils/env.py b/poetry/utils/env.py
--- a/poetry/utils/env.py
+++ b/poetry/utils/env.py
@@ -879,9 +879,13 @@ class Env(object):
 
     def __init__(self, path: Path, base: Optional[Path] = None) -> None:
         self._is_windows = sys.platform == "win32"
+        self._is_mingw = sysconfig.get_platform() == "mingw"
 
+        if not self._is_windows or self._is_mingw:
+            bin_dir = "bin"
+        else:
+            bin_dir = "Scripts"
         self._path = path
-        bin_dir = "bin" if not self._is_windows else "Scripts"
         self._bin_dir = self._path / bin_dir
 
         self._base = base or path


Test patch: