prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  poetry script: unable to find entry point module, if package resides in src
  `poetry script` is unable to find the entry point module in `src`
  
  ```
  [NameError]
  name 'Module' is not defined
  script <script-name> [<args>]...
  ```
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `poetry/console/commands/script.py`
  Content:
  ```
  1 import sys
  2 
  3 from .venv_command import VenvCommand
  4 
  5 
  6 class ScriptCommand(VenvCommand):
  7     """
  8     Executes a script defined in <comment>pyproject.toml</comment>
  9 
  10     script
  11         { script-name : The name of the script to execute }
  12         { args?* : The command and arguments/options to pass to the script. }
  13     """
  14 
  15     def handle(self):
  16         script = self.argument('script-name')
  17         argv = [script] + self.argument('args')
  18 
  19         scripts = self.poetry.local_config.get('scripts')
  20         if not scripts:
  21             raise RuntimeError('No scripts defined in pyproject.toml')
  22 
  23         if script not in scripts:
  24             raise ValueError('Script {} is not defined'.format(script))
  25 
  26         module, callable_ = scripts[script].split(':')
  27 
  28         cmd = ['python', '-c']
  29 
  30         cmd += [
  31             '"import sys; '
  32             'from importlib import import_module; '
  33             'sys.argv = {!r}; '
  34             'import_module(\'{}\').{}()"'.format(
  35                argv, module, callable_
  36             )
  37         ]
  38 
  39         self.venv.run(*cmd, shell=True, call=True)
  40 
  41     def merge_application_definition(self, merge_args=True):
  42         if self._application is None \
  43                 or (self._application_definition_merged
  44                     and (self._application_definition_merged_with_args or not merge_args)):
  45             return
  46 
  47         if merge_args:
  48             current_arguments = self._definition.get_arguments()
  49             self._definition.set_arguments(self._application.get_definition().get_arguments())
  50             self._definition.add_arguments(current_arguments)
  51 
  52         self._application_definition_merged = True
  53         if merge_args:
  54             self._application_definition_merged_with_args = True
  55
  ```
  --- 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/poetry/console/commands/script.py b/poetry/console/commands/script.py
  --- a/poetry/console/commands/script.py
  +++ b/poetry/console/commands/script.py
  @@ -1,5 +1,6 @@
   import sys
   
  +from ...masonry.utils.module import Module
   from .venv_command import VenvCommand
   
   
  @@ -25,19 +26,32 @@
   
           module, callable_ = scripts[script].split(':')
   
  +        src_in_sys_path = 'sys.path.append(\'src\'); '\
  +            if self._module.is_in_src() else ''
  +
           cmd = ['python', '-c']
   
           cmd += [
               '"import sys; '
               'from importlib import import_module; '
  -            'sys.argv = {!r}; '
  +            'sys.argv = {!r}; {}'
               'import_module(\'{}\').{}()"'.format(
  -               argv, module, callable_
  +               argv, src_in_sys_path, module, callable_
               )
           ]
   
           self.venv.run(*cmd, shell=True, call=True)
   
  +    @property
  +    def _module(self):
  +        poetry = self.poetry
  +        package = poetry.package
  +        path = poetry.file.parent
  +        module = Module(
  +            package.name, path.as_posix()
  +        )
  +        return module
  +
       def merge_application_definition(self, merge_args=True):
           if self._application is None \
                   or (self._application_definition_merged
  
verification_info: {"golden_diff": "diff --git a/poetry/console/commands/script.py b/poetry/console/commands/script.py\n--- a/poetry/console/commands/script.py\n+++ b/poetry/console/commands/script.py\n@@ -1,5 +1,6 @@\n import sys\n \n+from ...masonry.utils.module import Module\n from .venv_command import VenvCommand\n \n \n@@ -25,19 +26,32 @@\n \n         module, callable_ = scripts[script].split(':')\n \n+        src_in_sys_path = 'sys.path.append(\\'src\\'); '\\\n+            if self._module.is_in_src() else ''\n+\n         cmd = ['python', '-c']\n \n         cmd += [\n             '\"import sys; '\n             'from importlib import import_module; '\n-            'sys.argv = {!r}; '\n+            'sys.argv = {!r}; {}'\n             'import_module(\\'{}\\').{}()\"'.format(\n-               argv, module, callable_\n+               argv, src_in_sys_path, module, callable_\n             )\n         ]\n \n         self.venv.run(*cmd, shell=True, call=True)\n \n+    @property\n+    def _module(self):\n+        poetry = self.poetry\n+        package = poetry.package\n+        path = poetry.file.parent\n+        module = Module(\n+            package.name, path.as_posix()\n+        )\n+        return module\n+\n     def merge_application_definition(self, merge_args=True):\n         if self._application is None \\\n                 or (self._application_definition_merged\n", "issue": "poetry script: unable to find entry point module, if package resides in src\n`poetry script` is unable to find the entry point module in `src`\r\n\r\n```\r\n[NameError]\r\nname 'Module' is not defined\r\nscript <script-name> [<args>]...\r\n```\n", "before_files": [{"content": "import sys\n\nfrom .venv_command import VenvCommand\n\n\nclass ScriptCommand(VenvCommand):\n    \"\"\"\n    Executes a script defined in <comment>pyproject.toml</comment>\n\n    script\n        { script-name : The name of the script to execute }\n        { args?* : The command and arguments/options to pass to the script. }\n    \"\"\"\n\n    def handle(self):\n        script = self.argument('script-name')\n        argv = [script] + self.argument('args')\n\n        scripts = self.poetry.local_config.get('scripts')\n        if not scripts:\n            raise RuntimeError('No scripts defined in pyproject.toml')\n\n        if script not in scripts:\n            raise ValueError('Script {} is not defined'.format(script))\n\n        module, callable_ = scripts[script].split(':')\n\n        cmd = ['python', '-c']\n\n        cmd += [\n            '\"import sys; '\n            'from importlib import import_module; '\n            'sys.argv = {!r}; '\n            'import_module(\\'{}\\').{}()\"'.format(\n               argv, module, callable_\n            )\n        ]\n\n        self.venv.run(*cmd, shell=True, call=True)\n\n    def merge_application_definition(self, merge_args=True):\n        if self._application is None \\\n                or (self._application_definition_merged\n                    and (self._application_definition_merged_with_args or not merge_args)):\n            return\n\n        if merge_args:\n            current_arguments = self._definition.get_arguments()\n            self._definition.set_arguments(self._application.get_definition().get_arguments())\n            self._definition.add_arguments(current_arguments)\n\n        self._application_definition_merged = True\n        if merge_args:\n            self._application_definition_merged_with_args = True\n", "path": "poetry/console/commands/script.py"}], "after_files": [{"content": "import sys\n\nfrom ...masonry.utils.module import Module\nfrom .venv_command import VenvCommand\n\n\nclass ScriptCommand(VenvCommand):\n    \"\"\"\n    Executes a script defined in <comment>pyproject.toml</comment>\n\n    script\n        { script-name : The name of the script to execute }\n        { args?* : The command and arguments/options to pass to the script. }\n    \"\"\"\n\n    def handle(self):\n        script = self.argument('script-name')\n        argv = [script] + self.argument('args')\n\n        scripts = self.poetry.local_config.get('scripts')\n        if not scripts:\n            raise RuntimeError('No scripts defined in pyproject.toml')\n\n        if script not in scripts:\n            raise ValueError('Script {} is not defined'.format(script))\n\n        module, callable_ = scripts[script].split(':')\n\n        src_in_sys_path = 'sys.path.append(\\'src\\'); '\\\n            if self._module.is_in_src() else ''\n\n        cmd = ['python', '-c']\n\n        cmd += [\n            '\"import sys; '\n            'from importlib import import_module; '\n            'sys.argv = {!r}; {}'\n            'import_module(\\'{}\\').{}()\"'.format(\n               argv, src_in_sys_path, module, callable_\n            )\n        ]\n\n        self.venv.run(*cmd, shell=True, call=True)\n\n    @property\n    def _module(self):\n        poetry = self.poetry\n        package = poetry.package\n        path = poetry.file.parent\n        module = Module(\n            package.name, path.as_posix()\n        )\n        return module\n\n    def merge_application_definition(self, merge_args=True):\n        if self._application is None \\\n                or (self._application_definition_merged\n                    and (self._application_definition_merged_with_args or not merge_args)):\n            return\n\n        if merge_args:\n            current_arguments = self._definition.get_arguments()\n            self._definition.set_arguments(self._application.get_definition().get_arguments())\n            self._definition.add_arguments(current_arguments)\n\n        self._application_definition_merged = True\n        if merge_args:\n            self._application_definition_merged_with_args = True\n", "path": "poetry/console/commands/script.py"}]}