From 94368476267c209632c8272a6b407a3f08d5ec3d Mon Sep 17 00:00:00 2001 From: Bartek Sokorski Date: Sun, 1 May 2022 23:57:21 +0200 Subject: [PATCH 01/11] Remove mentions of Py2.7 from docs --- docs/dependency-specification.md | 8 ++++---- docs/managing-environments.md | 1 - docs/plugins.md | 2 +- docs/pyproject.md | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/dependency-specification.md b/docs/dependency-specification.md index c5efbb2a32d..0e381563aca 100644 --- a/docs/dependency-specification.md +++ b/docs/dependency-specification.md @@ -184,12 +184,12 @@ You can also specify that a dependency should be installed only for specific Pyt ```toml [tool.poetry.dependencies] -pathlib2 = { version = "^2.2", python = "~2.7" } +tomli = { version = "^2.0.1", python = "<3.11" } ``` ```toml [tool.poetry.dependencies] -pathlib2 = { version = "^2.2", python = "~2.7 || ^3.2" } +pathlib2 = { version = "^2.2", python = "^3.2" } ``` ## Using environment markers @@ -200,7 +200,7 @@ via the `markers` property: ```toml [tool.poetry.dependencies] -pathlib2 = { version = "^2.2", markers = "python_version ~= '2.7' or sys_platform == 'win32'" } +pathlib2 = { version = "^2.2", markers = "python_version <= '3.4' or sys_platform == 'win32'" } ``` ## Multiple constraints dependencies @@ -215,7 +215,7 @@ you would declare it like so: ```toml [tool.poetry.dependencies] foo = [ - {version = "<=1.9", python = "^2.7"}, + {version = "<=1.9", python = "^3.6"}, {version = "^2.0", python = "^3.8"} ] ``` diff --git a/docs/managing-environments.md b/docs/managing-environments.md index 751c53cf84b..4bb1d4f2ee2 100644 --- a/docs/managing-environments.md +++ b/docs/managing-environments.md @@ -114,7 +114,6 @@ poetry env list will output something like the following: ```text -test-O3eWbxRl-py2.7 test-O3eWbxRl-py3.6 test-O3eWbxRl-py3.7 (Activated) ``` diff --git a/docs/plugins.md b/docs/plugins.md index 96ca48e191b..f8d27b75b5c 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -38,7 +38,7 @@ version = "1.0.0" # ... [tool.poetry.dependencies] -python = "~2.7 || ^3.7" +python = "^3.7" poetry = "^1.0" [tool.poetry.plugins."poetry.plugin"] diff --git a/docs/pyproject.md b/docs/pyproject.md index 9147294f441..bfaca98fb52 100644 --- a/docs/pyproject.md +++ b/docs/pyproject.md @@ -290,7 +290,7 @@ mandatory = "^1.0" # A list of all of the optional dependencies, some of which are included in the # below `extras`. They can be opted into by apps. -psycopg2 = { version = "^2.7", optional = true } +psycopg2 = { version = "^2.9", optional = true } mysqlclient = { version = "^1.3", optional = true } [tool.poetry.extras] From ed2f9fbdd9d20e3b773c4695dbe11597e4a7dea1 Mon Sep 17 00:00:00 2001 From: Bartek Sokorski Date: Mon, 2 May 2022 00:06:08 +0200 Subject: [PATCH 02/11] Add note about dropped support for python 2.7 environments --- docs/managing-environments.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/managing-environments.md b/docs/managing-environments.md index 4bb1d4f2ee2..a3429e1d32e 100644 --- a/docs/managing-environments.md +++ b/docs/managing-environments.md @@ -41,6 +41,10 @@ poetry install ``` {{% /note %}} +{{% note %}} +Since version 1.2, Poetry no longer supports managing environments for Python 2.7. +{{% /note %}} + ## Switching between environments Sometimes this might not be feasible for your system, especially Windows where `pyenv` From ccc21fd00b90b3bc56536f0cae0c3a0b7840166f Mon Sep 17 00:00:00 2001 From: Bartek Sokorski Date: Thu, 19 May 2022 18:58:59 +0200 Subject: [PATCH 03/11] Raise error when 2.7 env --- src/poetry/utils/env.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 8c5867893fb..3499c16c37d 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -1637,9 +1637,12 @@ def get_pip_command(self, embedded: bool = False) -> list[str]: ] def get_supported_tags(self) -> list[Tag]: - output = self.run_python_script(GET_SYS_TAGS) + if self.get_version_info() < (3, 0, 0): + raise NotImplementedError("Poetry does not support python 2.7 environments") + else: + output = self.run_python_script(GET_SYS_TAGS) - return [Tag(*t) for t in json.loads(output)] + return [Tag(*t) for t in json.loads(output)] def get_marker_env(self) -> dict[str, Any]: output = self.run_python_script(GET_ENVIRONMENT_INFO) From e373958166b8343bc2704fbf081c21bdade567b5 Mon Sep 17 00:00:00 2001 From: Bartek Sokorski Date: Thu, 19 May 2022 19:41:41 +0200 Subject: [PATCH 04/11] More error handling --- src/poetry/utils/env.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 3499c16c37d..10ba5c92e49 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -4,6 +4,7 @@ import hashlib import itertools import json +import logging import os import platform import re @@ -38,6 +39,7 @@ from poetry.core.utils.helpers import temporary_directory from virtualenv.seed.wheels.embed import get_embed_wheel +from poetry.exceptions import PoetryException from poetry.locations import CACHE_DIR from poetry.utils._compat import decode from poetry.utils._compat import encode @@ -52,6 +54,7 @@ from cleo.io.io import IO from poetry.core.version.markers import BaseMarker +logger = logging.getLogger(__name__) P = TypeVar("P", bound=Poetry) @@ -1638,7 +1641,7 @@ def get_pip_command(self, embedded: bool = False) -> list[str]: def get_supported_tags(self) -> list[Tag]: if self.get_version_info() < (3, 0, 0): - raise NotImplementedError("Poetry does not support python 2.7 environments") + raise PoetryException("Poetry does not support python 2.7 environments") else: output = self.run_python_script(GET_SYS_TAGS) From 747464cadf2d302a7df427b0a69d7f6f8589352d Mon Sep 17 00:00:00 2001 From: Bartek Sokorski Date: Fri, 20 May 2022 22:59:30 +0200 Subject: [PATCH 05/11] WIP work on breaking 2.7 support --- src/poetry/utils/env.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 10ba5c92e49..5aa2f37d0dd 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -912,7 +912,7 @@ def create_venv( ) for python_to_try in sorted( - self._poetry.package.AVAILABLE_PYTHONS, + self._poetry.package.AVAILABLE_PYTHONS - {"2", "2.7"}, key=lambda v: (v.startswith("3"), -len(v), v), reverse=True, ): @@ -975,7 +975,7 @@ def create_venv( ) return self.get_system_env() - + # todo: this MF io.write_line(f"Creating virtualenv {name} in {venv_path!s}") else: create_venv = False @@ -1641,11 +1641,14 @@ def get_pip_command(self, embedded: bool = False) -> list[str]: def get_supported_tags(self) -> list[Tag]: if self.get_version_info() < (3, 0, 0): - raise PoetryException("Poetry does not support python 2.7 environments") - else: - output = self.run_python_script(GET_SYS_TAGS) + error_message = """ + Poetry no longer supports Python 2.7 environments. + + """ + raise PoetryException(error_message) - return [Tag(*t) for t in json.loads(output)] + output = self.run_python_script(GET_SYS_TAGS) + return [Tag(*t) for t in json.loads(output)] def get_marker_env(self) -> dict[str, Any]: output = self.run_python_script(GET_ENVIRONMENT_INFO) From e32dcaa0907d651da4d603739029996bdaa6be6e Mon Sep 17 00:00:00 2001 From: Bartek Sokorski Date: Tue, 31 May 2022 00:25:32 +0200 Subject: [PATCH 06/11] WIP --- src/poetry/utils/env.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 4d66384c31a..532086a0cb7 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -224,6 +224,12 @@ def _version_nodot(version): """ +# This should be dropped when Poetry removes python2 support completely +def _is_python2_exec(executable: str) -> bool: + print(f"HERE --------- {executable} -------------") + return re.match(r".2.|.2\..", executable) is not None + + class SitePackages: def __init__( self, @@ -948,6 +954,12 @@ def create_venv( python = "python" + python_to_try + if _is_python2_exec(python): + error_message = """ + Poetry no longer supports Python 2.7 environments. + """ + raise PoetryException(error_message) + if io.is_debug(): io.write_line(f"Trying {python}") @@ -1076,6 +1088,12 @@ def build_venv( if isinstance(executable, Path): executable = executable.resolve().as_posix() + if _is_python2_exec(executable): + error_message = """ + Poetry no longer supports Python 2.7 environments. + """ + raise PoetryException(error_message) + args = [ "--no-download", "--no-periodic-update", From b47d8b175865c53044d4c649af574eb1a0e40a0b Mon Sep 17 00:00:00 2001 From: Bartek Sokorski Date: Fri, 24 Jun 2022 20:06:22 +0200 Subject: [PATCH 07/11] Remove work comments --- src/poetry/utils/env.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 4e99aa18298..d21d856397b 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -228,7 +228,6 @@ def _version_nodot(version): # This should be dropped when Poetry removes python2 support completely def _is_python2_exec(executable: str) -> bool: - print(f"HERE --------- {executable} -------------") return re.match(r".2.|.2\..", executable) is not None @@ -977,7 +976,6 @@ def create_venv( ) return self.get_system_env() - # todo: this MF io.write_line(f"Creating virtualenv {name} in {venv_path!s}") else: create_venv = False From 73394433f2ee7132291bc0c67ed1c2aab8fd0235 Mon Sep 17 00:00:00 2001 From: Bartek Sokorski Date: Sat, 16 Jul 2022 21:07:40 +0200 Subject: [PATCH 08/11] WIP --- src/poetry/utils/env.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 0ea5cd2a577..2247809d447 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -230,7 +230,7 @@ def _version_nodot(version): # This should be dropped when Poetry removes python2 support completely def _is_python2_exec(executable: str) -> bool: - return re.match(r".2.|.2\..", executable) is not None + return re.match(r".*2.|.2\..", executable) is not None class SitePackages: @@ -578,6 +578,10 @@ def activate(self, python: str, io: IO) -> Env: python = self._full_python_path(python) + if _is_python2_exec(python): + io.write_line("check 1") + raise Exception("python 2 detected, can't use python 2") + try: python_version_string = decode( subprocess.check_output( From cc934add58bb90b4e497616355a8728a50e5d7b6 Mon Sep 17 00:00:00 2001 From: Bartek Sokorski Date: Sat, 16 Jul 2022 22:43:33 +0200 Subject: [PATCH 09/11] WIP... --- src/poetry/utils/env.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 2247809d447..6628a674cb0 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -233,6 +233,12 @@ def _is_python2_exec(executable: str) -> bool: return re.match(r".*2.|.2\..", executable) is not None +def _can_use_python2() -> bool: + if "py2" in {t.interpreter[:3] for t in Env(__file__).get_supported_tags()}: + return True + return False + + class SitePackages: def __init__( self, @@ -579,8 +585,7 @@ def activate(self, python: str, io: IO) -> Env: python = self._full_python_path(python) if _is_python2_exec(python): - io.write_line("check 1") - raise Exception("python 2 detected, can't use python 2") + raise PoetryException("Poetry no longer supports Python 2.7 environments") try: python_version_string = decode( @@ -907,7 +912,7 @@ def create_venv( ) for python_to_try in sorted( - self._poetry.package.AVAILABLE_PYTHONS - {"2", "2.7"}, + self._poetry.package.AVAILABLE_PYTHONS, key=lambda v: (v.startswith("3"), -len(v), v), reverse=True, ): @@ -924,9 +929,7 @@ def create_venv( python = "python" + python_to_try if _is_python2_exec(python): - error_message = """ - Poetry no longer supports Python 2.7 environments. - """ + error_message = "Poetry no longer supports Python 2.7 environments." raise PoetryException(error_message) if io.is_debug(): @@ -1066,9 +1069,7 @@ def build_venv( executable = executable.resolve().as_posix() if _is_python2_exec(executable): - error_message = """ - Poetry no longer supports Python 2.7 environments. - """ + error_message = "Poetry no longer supports Python 2.7 environments." raise PoetryException(error_message) args = [ From aad129121576f2cfa2a116fadd1dff47e9efe88a Mon Sep 17 00:00:00 2001 From: Bartek Sokorski Date: Fri, 22 Jul 2022 00:21:02 +0200 Subject: [PATCH 10/11] WIP --- src/poetry/utils/env.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 6628a674cb0..9cb38829d59 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -233,12 +233,6 @@ def _is_python2_exec(executable: str) -> bool: return re.match(r".*2.|.2\..", executable) is not None -def _can_use_python2() -> bool: - if "py2" in {t.interpreter[:3] for t in Env(__file__).get_supported_tags()}: - return True - return False - - class SitePackages: def __init__( self, @@ -585,7 +579,7 @@ def activate(self, python: str, io: IO) -> Env: python = self._full_python_path(python) if _is_python2_exec(python): - raise PoetryException("Poetry no longer supports Python 2.7 environments") + io.write_error_line("Poetry no longer supports Python 2.7 environments") try: python_version_string = decode( From 589a5e532e1558557dab29dc2aadaa6f4f3da294 Mon Sep 17 00:00:00 2001 From: Bartek Sokorski Date: Thu, 25 Aug 2022 12:49:01 +0200 Subject: [PATCH 11/11] Revert changes to env logic --- src/poetry/utils/env.py | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 79a78df9797..ab645bd7c08 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -5,7 +5,6 @@ import hashlib import itertools import json -import logging import os import platform import plistlib @@ -37,7 +36,6 @@ from poetry.core.utils.helpers import temporary_directory from virtualenv.seed.wheels.embed import get_embed_wheel -from poetry.exceptions import PoetryException from poetry.utils._compat import WINDOWS from poetry.utils._compat import decode from poetry.utils._compat import encode @@ -61,9 +59,6 @@ from poetry.poetry import Poetry -logger = logging.getLogger(__name__) - - GET_SYS_TAGS = f""" import importlib.util import json @@ -228,11 +223,6 @@ def _version_nodot(version): """ -# This should be dropped when Poetry removes python2 support completely -def _is_python2_exec(executable: str) -> bool: - return re.match(r".*2.|.2\..", executable) is not None - - class SitePackages: def __init__( self, @@ -578,9 +568,6 @@ def activate(self, python: str, io: IO) -> Env: python = self._full_python_path(python) - if _is_python2_exec(python): - io.write_error_line("Poetry no longer supports Python 2.7 environments") - try: python_version_string = decode( subprocess.check_output( @@ -923,10 +910,6 @@ def create_venv( python = "python" + python_to_try - if _is_python2_exec(python): - error_message = "Poetry no longer supports Python 2.7 environments." - raise PoetryException(error_message) - if io.is_debug(): io.write_line(f"Trying {python}") @@ -985,7 +968,6 @@ def create_venv( f"Creating virtualenv {name} in" f" {venv_path if not WINDOWS else get_real_windows_path(venv_path)!s}" ) - else: create_venv = False if force: @@ -1064,10 +1046,6 @@ def build_venv( if isinstance(executable, Path): executable = executable.resolve().as_posix() - if _is_python2_exec(executable): - error_message = "Poetry no longer supports Python 2.7 environments." - raise PoetryException(error_message) - args = [ "--no-download", "--no-periodic-update", @@ -1703,13 +1681,9 @@ def get_pip_command(self, embedded: bool = False) -> list[str]: ] def get_supported_tags(self) -> list[Tag]: - if self.get_version_info() < (3, 0, 0): - error_message = """ - Poetry no longer supports Python 2.7 environments. - """ - raise PoetryException(error_message) output = self.run_python_script(GET_SYS_TAGS) assert isinstance(output, str) + return [Tag(*t) for t in json.loads(output)] def get_marker_env(self) -> dict[str, Any]: