prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Include strtobool in utils.extras to speed up the shell command
  # Pull Request Check List
  
  <!-- This is just a reminder about the most common mistakes. Please make sure that you tick all *appropriate* boxes.  But please read our [contribution guide](https://python-poetry.org/docs/contributing/) at least once, it will save you unnecessary review cycles! -->
  
  - [x] Added **tests** for changed code.
  - [ ] Updated **documentation** for changed code. (The change doesn't reflect in the current doc)
  
  <!-- If you have *any* questions to *any* of the points above, just **submit and ask**!  This checklist is here to *help* you, not to deter you from contributing! -->
  
  # What does this PR do?
  
  This line `from distutils.util import strtobool` in  `console.commands.shell` is slow and makes poetry shell command slow, since importing `distutils.util` also does a bunch of other things. 
  
  `strtobool` is a very simple function (~10 lines), if poetry includes this function itself, for example, putting it in utils.extras.py and use from poetry.utils.extras import strtobool, poetry shell would run faster.
  
  [Discord discussion link](https://discord.com/channels/487711540787675139/974839878669987840/988024065933594704)
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `src/poetry/console/commands/shell.py`
  Content:
  ```
  1 from __future__ import annotations
  2 
  3 import sys
  4 
  5 from distutils.util import strtobool
  6 from os import environ
  7 from typing import TYPE_CHECKING
  8 from typing import cast
  9 
  10 from poetry.console.commands.env_command import EnvCommand
  11 
  12 
  13 if TYPE_CHECKING:
  14     from poetry.utils.env import VirtualEnv
  15 
  16 
  17 class ShellCommand(EnvCommand):
  18     name = "shell"
  19     description = "Spawns a shell within the virtual environment."
  20 
  21     help = """The <info>shell</> command spawns a shell, according to the
  22 <comment>$SHELL</> environment variable, within the virtual environment.
  23 If one doesn't exist yet, it will be created.
  24 """
  25 
  26     def handle(self) -> int:
  27         from poetry.utils.shell import Shell
  28 
  29         # Check if it's already activated or doesn't exist and won't be created
  30         venv_activated = strtobool(environ.get("POETRY_ACTIVE", "0")) or getattr(
  31             sys, "real_prefix", sys.prefix
  32         ) == str(self.env.path)
  33         if venv_activated:
  34             self.line(
  35                 f"Virtual environment already activated: <info>{self.env.path}</>"
  36             )
  37 
  38             return 0
  39 
  40         self.line(f"Spawning shell within <info>{self.env.path}</>")
  41 
  42         # Be sure that we have the right type of environment.
  43         env = self.env
  44         assert env.is_venv()
  45         env = cast("VirtualEnv", env)
  46 
  47         # Setting this to avoid spawning unnecessary nested shells
  48         environ["POETRY_ACTIVE"] = "1"
  49         shell = Shell.get()
  50         shell.activate(env)
  51         environ.pop("POETRY_ACTIVE")
  52 
  53         return 0
  54
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/src/poetry/console/commands/shell.py b/src/poetry/console/commands/shell.py
  --- a/src/poetry/console/commands/shell.py
  +++ b/src/poetry/console/commands/shell.py
  @@ -2,7 +2,6 @@
   
   import sys
   
  -from distutils.util import strtobool
   from os import environ
   from typing import TYPE_CHECKING
   from typing import cast
  @@ -27,10 +26,7 @@
           from poetry.utils.shell import Shell
   
           # Check if it's already activated or doesn't exist and won't be created
  -        venv_activated = strtobool(environ.get("POETRY_ACTIVE", "0")) or getattr(
  -            sys, "real_prefix", sys.prefix
  -        ) == str(self.env.path)
  -        if venv_activated:
  +        if self._is_venv_activated():
               self.line(
                   f"Virtual environment already activated: <info>{self.env.path}</>"
               )
  @@ -51,3 +47,8 @@
           environ.pop("POETRY_ACTIVE")
   
           return 0
  +
  +    def _is_venv_activated(self) -> bool:
  +        return bool(environ.get("POETRY_ACTIVE")) or getattr(
  +            sys, "real_prefix", sys.prefix
  +        ) == str(self.env.path)
  
verification_info: {"golden_diff": "diff --git a/src/poetry/console/commands/shell.py b/src/poetry/console/commands/shell.py\n--- a/src/poetry/console/commands/shell.py\n+++ b/src/poetry/console/commands/shell.py\n@@ -2,7 +2,6 @@\n \n import sys\n \n-from distutils.util import strtobool\n from os import environ\n from typing import TYPE_CHECKING\n from typing import cast\n@@ -27,10 +26,7 @@\n         from poetry.utils.shell import Shell\n \n         # Check if it's already activated or doesn't exist and won't be created\n-        venv_activated = strtobool(environ.get(\"POETRY_ACTIVE\", \"0\")) or getattr(\n-            sys, \"real_prefix\", sys.prefix\n-        ) == str(self.env.path)\n-        if venv_activated:\n+        if self._is_venv_activated():\n             self.line(\n                 f\"Virtual environment already activated: <info>{self.env.path}</>\"\n             )\n@@ -51,3 +47,8 @@\n         environ.pop(\"POETRY_ACTIVE\")\n \n         return 0\n+\n+    def _is_venv_activated(self) -> bool:\n+        return bool(environ.get(\"POETRY_ACTIVE\")) or getattr(\n+            sys, \"real_prefix\", sys.prefix\n+        ) == str(self.env.path)\n", "issue": "Include strtobool in utils.extras to speed up the shell command\n# Pull Request Check List\r\n\r\n<!-- This is just a reminder about the most common mistakes. Please make sure that you tick all *appropriate* boxes.  But please read our [contribution guide](https://python-poetry.org/docs/contributing/) at least once, it will save you unnecessary review cycles! -->\r\n\r\n- [x] Added **tests** for changed code.\r\n- [ ] Updated **documentation** for changed code. (The change doesn't reflect in the current doc)\r\n\r\n<!-- If you have *any* questions to *any* of the points above, just **submit and ask**!  This checklist is here to *help* you, not to deter you from contributing! -->\r\n\r\n# What does this PR do?\r\n\r\nThis line `from distutils.util import strtobool` in  `console.commands.shell` is slow and makes poetry shell command slow, since importing `distutils.util` also does a bunch of other things. \r\n\r\n`strtobool` is a very simple function (~10 lines), if poetry includes this function itself, for example, putting it in utils.extras.py and use from poetry.utils.extras import strtobool, poetry shell would run faster.\r\n\r\n[Discord discussion link](https://discord.com/channels/487711540787675139/974839878669987840/988024065933594704)\n", "before_files": [{"content": "from __future__ import annotations\n\nimport sys\n\nfrom distutils.util import strtobool\nfrom os import environ\nfrom typing import TYPE_CHECKING\nfrom typing import cast\n\nfrom poetry.console.commands.env_command import EnvCommand\n\n\nif TYPE_CHECKING:\n    from poetry.utils.env import VirtualEnv\n\n\nclass ShellCommand(EnvCommand):\n    name = \"shell\"\n    description = \"Spawns a shell within the virtual environment.\"\n\n    help = \"\"\"The <info>shell</> command spawns a shell, according to the\n<comment>$SHELL</> environment variable, within the virtual environment.\nIf one doesn't exist yet, it will be created.\n\"\"\"\n\n    def handle(self) -> int:\n        from poetry.utils.shell import Shell\n\n        # Check if it's already activated or doesn't exist and won't be created\n        venv_activated = strtobool(environ.get(\"POETRY_ACTIVE\", \"0\")) or getattr(\n            sys, \"real_prefix\", sys.prefix\n        ) == str(self.env.path)\n        if venv_activated:\n            self.line(\n                f\"Virtual environment already activated: <info>{self.env.path}</>\"\n            )\n\n            return 0\n\n        self.line(f\"Spawning shell within <info>{self.env.path}</>\")\n\n        # Be sure that we have the right type of environment.\n        env = self.env\n        assert env.is_venv()\n        env = cast(\"VirtualEnv\", env)\n\n        # Setting this to avoid spawning unnecessary nested shells\n        environ[\"POETRY_ACTIVE\"] = \"1\"\n        shell = Shell.get()\n        shell.activate(env)\n        environ.pop(\"POETRY_ACTIVE\")\n\n        return 0\n", "path": "src/poetry/console/commands/shell.py"}], "after_files": [{"content": "from __future__ import annotations\n\nimport sys\n\nfrom os import environ\nfrom typing import TYPE_CHECKING\nfrom typing import cast\n\nfrom poetry.console.commands.env_command import EnvCommand\n\n\nif TYPE_CHECKING:\n    from poetry.utils.env import VirtualEnv\n\n\nclass ShellCommand(EnvCommand):\n    name = \"shell\"\n    description = \"Spawns a shell within the virtual environment.\"\n\n    help = \"\"\"The <info>shell</> command spawns a shell, according to the\n<comment>$SHELL</> environment variable, within the virtual environment.\nIf one doesn't exist yet, it will be created.\n\"\"\"\n\n    def handle(self) -> int:\n        from poetry.utils.shell import Shell\n\n        # Check if it's already activated or doesn't exist and won't be created\n        if self._is_venv_activated():\n            self.line(\n                f\"Virtual environment already activated: <info>{self.env.path}</>\"\n            )\n\n            return 0\n\n        self.line(f\"Spawning shell within <info>{self.env.path}</>\")\n\n        # Be sure that we have the right type of environment.\n        env = self.env\n        assert env.is_venv()\n        env = cast(\"VirtualEnv\", env)\n\n        # Setting this to avoid spawning unnecessary nested shells\n        environ[\"POETRY_ACTIVE\"] = \"1\"\n        shell = Shell.get()\n        shell.activate(env)\n        environ.pop(\"POETRY_ACTIVE\")\n\n        return 0\n\n    def _is_venv_activated(self) -> bool:\n        return bool(environ.get(\"POETRY_ACTIVE\")) or getattr(\n            sys, \"real_prefix\", sys.prefix\n        ) == str(self.env.path)\n", "path": "src/poetry/console/commands/shell.py"}]}