Repository: python-poetry/poetry

Issue:
Packaging 21.0
According to my testing in Fedora with more than 180 RPM packages, poetry and poetry-core packages are compatible with the latest packaging version 21.0. The main reason for the major release is that packaging 21 no longer supports Python < 3.6.

So I think that you can update it.

<!-- Checked checkbox should look like this: [x] -->
- [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] I have searched the [documentation](https://python-poetry.org/docs/) and believe that my question is not covered.


Discussion:
> According to my testing in Fedora with more than 180 RPM packages, poetry and poetry-core packages are compatible with the latest packaging version 21.0.

I am afraid there is a problem: https://src.fedoraproject.org/rpms/poetry/pull-request/17#comment-83627
Packaging 21.0 also drops support for Python 2.7 and Poetry executes a file from it with the venv's Python interpreter:

https://github.com/python-poetry/poetry/blob/cd511298a9a0c041ec365adb3cb1bbf3e8eab7d2/poetry/utils/env.py#L1491-L1519

Resolving patch:
diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py
--- a/src/poetry/utils/env.py
+++ b/src/poetry/utils/env.py
@@ -11,7 +11,6 @@
 import subprocess
 import sys
 import sysconfig
-import textwrap
 
 from contextlib import contextmanager
 from copy import deepcopy
@@ -54,6 +53,31 @@
     from poetry.poetry import Poetry
 
 
+GET_SYS_TAGS = f"""
+import importlib.util
+import json
+import sys
+
+from pathlib import Path
+
+spec = importlib.util.spec_from_file_location(
+    "packaging", Path(r"{packaging.__file__}")
+)
+packaging = importlib.util.module_from_spec(spec)
+sys.modules[spec.name] = packaging
+
+spec = importlib.util.spec_from_file_location(
+    "packaging.tags", Path(r"{packaging.tags.__file__}")
+)
+packaging_tags = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(packaging_tags)
+
+print(
+    json.dumps([(t.interpreter, t.abi, t.platform) for t in packaging_tags.sys_tags()])
+)
+"""
+
+
 GET_ENVIRONMENT_INFO = """\
 import json
 import os
@@ -1614,32 +1638,7 @@ def get_pip_command(self, embedded: bool = False) -> list[str]:
         ]
 
     def get_supported_tags(self) -> list[Tag]:
-        file_path = Path(packaging.tags.__file__)
-        if file_path.suffix == ".pyc":
-            # Python 2
-            file_path = file_path.with_suffix(".py")
-
-        with file_path.open(encoding="utf-8") as f:
-            script = decode(f.read())
-
-        script = script.replace(
-            "from ._typing import TYPE_CHECKING, cast",
-            "TYPE_CHECKING = False\ncast = lambda type_, value: value",
-        )
-        script = script.replace(
-            "from ._typing import MYPY_CHECK_RUNNING, cast",
-            "MYPY_CHECK_RUNNING = False\ncast = lambda type_, value: value",
-        )
-
-        script += textwrap.dedent(
-            """
-            import json
-
-            print(json.dumps([(t.interpreter, t.abi, t.platform) for t in sys_tags()]))
-            """
-        )
-
-        output = self.run_python_script(script)
+        output = self.run_python_script(GET_SYS_TAGS)
 
         return [Tag(*t) for t in json.loads(output)]
 


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
@@ -119,6 +119,18 @@ def test_env_shell_commands_with_stdinput_in_their_arg_work_as_expected(
     assert run_output_path.resolve() == venv_base_prefix_path.resolve()
 
 
+def test_env_get_supported_tags_matches_inside_virtualenv(
+    tmp_dir: str, manager: EnvManager
+):
+    venv_path = Path(tmp_dir) / "Virtual Env"
+    manager.build_venv(str(venv_path))
+    venv = VirtualEnv(venv_path)
+
+    import packaging.tags
+
+    assert venv.get_supported_tags() == list(packaging.tags.sys_tags())
+
+
 @pytest.fixture
 def in_project_venv_dir(poetry: Poetry) -> Iterator[Path]:
     os.environ.pop("VIRTUAL_ENV", None)