Repository: python-poetry/poetry

Issue:
Poetry complains that the current Python version is incompatible, then selects it for use
<!-- Checked checkbox should look like this: [x] -->
- [x] I am on the [latest](https://github.com/sdispater/poetry/releases/latest) Poetry version.
- [x] I have searched the [issues](https://github.com/sdispater/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**: Debian Buster
- **Poetry version**: 1.0.0.b9
- **Link of a [Gist](https://gist.github.com/) with the contents of your pyproject.toml file**: https://gist.github.com/stevegore/2b85e59e9a3d6b42729442d4cf5bfe63

## Issue
On doing `poetry install --no-interaction -vvv` I get the following output:

```
The currently activated Python version 3.6.9 is not supported by the project (>=3.6.4, <3.8).
Trying to find and use a compatible version.
Trying python3
Using python3 (3.6.9)
Creating virtualenv blah-QvsKRVY5-py3.6 in /root/.cache/pypoetry/virtualenvs
Using virtualenv: /root/.cache/pypoetry/virtualenvs/blah-QvsKRVY5-py3.6
Installing dependencies from lock file
```

Poetry complains about the Python version even though it's valid. It then goes on to select the current version.

This bug is not blocking us at all, but it should probably be resolved regardless.



Discussion:

Resolving patch:
diff --git a/poetry/utils/env.py b/poetry/utils/env.py
--- a/poetry/utils/env.py
+++ b/poetry/utils/env.py
@@ -508,7 +508,7 @@ def create_venv(
             )
 
         supported_python = self._poetry.package.python_constraint
-        if not supported_python.allows(Version.parse(python_minor)):
+        if not supported_python.allows(Version.parse(python_patch)):
             # The currently activated or chosen Python version
             # is not compatible with the Python constraint specified
             # for the project.


Test patch:
diff --git a/tests/utils/test_env.py b/tests/utils/test_env.py
--- a/tests/utils/test_env.py
+++ b/tests/utils/test_env.py
@@ -664,6 +664,42 @@ def test_create_venv_does_not_try_to_find_compatible_versions_with_executable(
     assert 0 == m.call_count
 
 
+def test_create_venv_uses_patch_version_to_detect_compatibility(
+    manager, poetry, config, mocker
+):
+    if "VIRTUAL_ENV" in os.environ:
+        del os.environ["VIRTUAL_ENV"]
+
+    version = Version.parse(".".join(str(c) for c in sys.version_info[:3]))
+    poetry.package.python_versions = "^{}".format(
+        ".".join(str(c) for c in sys.version_info[:3])
+    )
+    venv_name = manager.generate_env_name("simple-project", str(poetry.file.parent))
+
+    mocker.patch("sys.version_info", (version.major, version.minor, version.patch + 1))
+    check_output = mocker.patch(
+        "poetry.utils._compat.subprocess.check_output",
+        side_effect=check_output_wrapper(Version.parse("3.6.9")),
+    )
+    m = mocker.patch(
+        "poetry.utils.env.EnvManager.build_venv", side_effect=lambda *args, **kwargs: ""
+    )
+
+    manager.create_venv(NullIO())
+
+    assert not check_output.called
+    m.assert_called_with(
+        str(
+            Path(
+                "/foo/virtualenvs/{}-py{}.{}".format(
+                    venv_name, version.major, version.minor
+                )
+            )
+        ),
+        executable=None,
+    )
+
+
 def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
     manager, poetry, config, tmp_dir, mocker
 ):