We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Allow for custom setup folders


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `veros/cli/veros_copy_setup.py`
Content:
```
1 #!/usr/bin/env python
2 
3 import os
4 import shutil
5 import pkg_resources
6 import functools
7 
8 import click
9 
10 SETUPDIR = pkg_resources.resource_filename('veros', 'setup')
11 SETUPS = sorted([
12     setup for setup in os.listdir(SETUPDIR)
13     if os.path.isdir(os.path.join(SETUPDIR, setup))
14     and not setup.startswith('_')
15 ])
16 IGNORE_PATTERNS = ['__init__.py', '*.pyc', '__pycache__/']
17 
18 
19 def copy_setup(setup, to=None):
20     """Copy a standard setup to another directory"""
21     if to is None:
22         to = os.path.join(os.getcwd(), setup)
23 
24     parent = os.path.dirname(os.path.realpath(to))
25 
26     if not os.path.exists(parent):
27         os.makedirs(parent)
28 
29     ignore = shutil.ignore_patterns(*IGNORE_PATTERNS)
30     shutil.copytree(
31         os.path.join(SETUPDIR, setup), to, ignore=ignore
32     )
33 
34 
35 @click.command('veros-copy-setup')
36 @click.argument('setup', type=click.Choice(SETUPS), metavar='SETUP')
37 @click.option('--to', type=click.Path(dir_okay=False, file_okay=False), required=False,
38               default=None, help='Target directory (default: copy to current working directory)')
39 @functools.wraps(copy_setup)
40 def cli(*args, **kwargs):
41     copy_setup(*args, **kwargs)
42 
43 
44 if __name__ == '__main__':
45     cli()
46
```
--- 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()

```

diff --git a/veros/cli/veros_copy_setup.py b/veros/cli/veros_copy_setup.py
--- a/veros/cli/veros_copy_setup.py
+++ b/veros/cli/veros_copy_setup.py
@@ -7,35 +7,69 @@
 
 import click
 
-SETUPDIR = pkg_resources.resource_filename('veros', 'setup')
-SETUPS = sorted([
-    setup for setup in os.listdir(SETUPDIR)
-    if os.path.isdir(os.path.join(SETUPDIR, setup))
-    and not setup.startswith('_')
-])
+SETUPDIR_ENVVAR = 'VEROS_SETUP_DIR'
 IGNORE_PATTERNS = ['__init__.py', '*.pyc', '__pycache__/']
+SETUPS = {}
+
+setup_dirs = [pkg_resources.resource_filename('veros', 'setup')]
+
+for setup_dir in os.environ.get(SETUPDIR_ENVVAR, '').split(';'):
+    if os.path.isdir(setup_dir):
+        setup_dirs.append(setup_dir)
+
+# populate {setup_name: path} mapping
+for setup_dir in setup_dirs:
+    for setup in os.listdir(setup_dir):
+        setup_path = os.path.join(setup_dir, setup)
+        if not os.path.isdir(setup_path):
+            continue
+        if setup.startswith(('_', '.')):
+            continue
+        SETUPS[setup] = setup_path
+
+SETUP_NAMES = sorted(SETUPS.keys())
 
 
 def copy_setup(setup, to=None):
-    """Copy a standard setup to another directory"""
+    """Copy a standard setup to another directory.
+
+    Argument must be one of: {setups}
+
+    Example:
+
+        $ veros copy-setup global_4deg --to ~/veros-setups/4deg-lowfric
+
+    Further directories containing setup templates can be added to this command
+    via the {setup_envvar} environment variable.
+    """
     if to is None:
         to = os.path.join(os.getcwd(), setup)
 
-    parent = os.path.dirname(os.path.realpath(to))
+    if os.path.exists(to):
+        raise RuntimeError('Target directory must not exist')
+
+    to_parent = os.path.dirname(os.path.realpath(to))
 
-    if not os.path.exists(parent):
-        os.makedirs(parent)
+    if not os.path.exists(to_parent):
+        os.makedirs(to_parent)
 
     ignore = shutil.ignore_patterns(*IGNORE_PATTERNS)
     shutil.copytree(
-        os.path.join(SETUPDIR, setup), to, ignore=ignore
+        SETUPS[setup], to, ignore=ignore
     )
 
 
+copy_setup.__doc__ = copy_setup.__doc__.format(
+    setups=', '.join(SETUP_NAMES), setup_envvar=SETUPDIR_ENVVAR
+)
+
+
 @click.command('veros-copy-setup')
-@click.argument('setup', type=click.Choice(SETUPS), metavar='SETUP')
-@click.option('--to', type=click.Path(dir_okay=False, file_okay=False), required=False,
-              default=None, help='Target directory (default: copy to current working directory)')
+@click.argument('setup', type=click.Choice(SETUP_NAMES), metavar='SETUP')
+@click.option('--to', required=False, default=None,
+              type=click.Path(dir_okay=False, file_okay=False, writable=True),
+              help=('Target directory, must not exist '
+                    '(default: copy to current working directory)'))
 @functools.wraps(copy_setup)
 def cli(*args, **kwargs):
     copy_setup(*args, **kwargs)

{"golden_diff": "diff --git a/veros/cli/veros_copy_setup.py b/veros/cli/veros_copy_setup.py\n--- a/veros/cli/veros_copy_setup.py\n+++ b/veros/cli/veros_copy_setup.py\n@@ -7,35 +7,69 @@\n \n import click\n \n-SETUPDIR = pkg_resources.resource_filename('veros', 'setup')\n-SETUPS = sorted([\n-    setup for setup in os.listdir(SETUPDIR)\n-    if os.path.isdir(os.path.join(SETUPDIR, setup))\n-    and not setup.startswith('_')\n-])\n+SETUPDIR_ENVVAR = 'VEROS_SETUP_DIR'\n IGNORE_PATTERNS = ['__init__.py', '*.pyc', '__pycache__/']\n+SETUPS = {}\n+\n+setup_dirs = [pkg_resources.resource_filename('veros', 'setup')]\n+\n+for setup_dir in os.environ.get(SETUPDIR_ENVVAR, '').split(';'):\n+    if os.path.isdir(setup_dir):\n+        setup_dirs.append(setup_dir)\n+\n+# populate {setup_name: path} mapping\n+for setup_dir in setup_dirs:\n+    for setup in os.listdir(setup_dir):\n+        setup_path = os.path.join(setup_dir, setup)\n+        if not os.path.isdir(setup_path):\n+            continue\n+        if setup.startswith(('_', '.')):\n+            continue\n+        SETUPS[setup] = setup_path\n+\n+SETUP_NAMES = sorted(SETUPS.keys())\n \n \n def copy_setup(setup, to=None):\n-    \"\"\"Copy a standard setup to another directory\"\"\"\n+    \"\"\"Copy a standard setup to another directory.\n+\n+    Argument must be one of: {setups}\n+\n+    Example:\n+\n+        $ veros copy-setup global_4deg --to ~/veros-setups/4deg-lowfric\n+\n+    Further directories containing setup templates can be added to this command\n+    via the {setup_envvar} environment variable.\n+    \"\"\"\n     if to is None:\n         to = os.path.join(os.getcwd(), setup)\n \n-    parent = os.path.dirname(os.path.realpath(to))\n+    if os.path.exists(to):\n+        raise RuntimeError('Target directory must not exist')\n+\n+    to_parent = os.path.dirname(os.path.realpath(to))\n \n-    if not os.path.exists(parent):\n-        os.makedirs(parent)\n+    if not os.path.exists(to_parent):\n+        os.makedirs(to_parent)\n \n     ignore = shutil.ignore_patterns(*IGNORE_PATTERNS)\n     shutil.copytree(\n-        os.path.join(SETUPDIR, setup), to, ignore=ignore\n+        SETUPS[setup], to, ignore=ignore\n     )\n \n \n+copy_setup.__doc__ = copy_setup.__doc__.format(\n+    setups=', '.join(SETUP_NAMES), setup_envvar=SETUPDIR_ENVVAR\n+)\n+\n+\n @click.command('veros-copy-setup')\n-@click.argument('setup', type=click.Choice(SETUPS), metavar='SETUP')\n-@click.option('--to', type=click.Path(dir_okay=False, file_okay=False), required=False,\n-              default=None, help='Target directory (default: copy to current working directory)')\n+@click.argument('setup', type=click.Choice(SETUP_NAMES), metavar='SETUP')\n+@click.option('--to', required=False, default=None,\n+              type=click.Path(dir_okay=False, file_okay=False, writable=True),\n+              help=('Target directory, must not exist '\n+                    '(default: copy to current working directory)'))\n @functools.wraps(copy_setup)\n def cli(*args, **kwargs):\n     copy_setup(*args, **kwargs)\n", "issue": "Allow for custom setup folders\n\n", "before_files": [{"content": "#!/usr/bin/env python\n\nimport os\nimport shutil\nimport pkg_resources\nimport functools\n\nimport click\n\nSETUPDIR = pkg_resources.resource_filename('veros', 'setup')\nSETUPS = sorted([\n    setup for setup in os.listdir(SETUPDIR)\n    if os.path.isdir(os.path.join(SETUPDIR, setup))\n    and not setup.startswith('_')\n])\nIGNORE_PATTERNS = ['__init__.py', '*.pyc', '__pycache__/']\n\n\ndef copy_setup(setup, to=None):\n    \"\"\"Copy a standard setup to another directory\"\"\"\n    if to is None:\n        to = os.path.join(os.getcwd(), setup)\n\n    parent = os.path.dirname(os.path.realpath(to))\n\n    if not os.path.exists(parent):\n        os.makedirs(parent)\n\n    ignore = shutil.ignore_patterns(*IGNORE_PATTERNS)\n    shutil.copytree(\n        os.path.join(SETUPDIR, setup), to, ignore=ignore\n    )\n\n\n@click.command('veros-copy-setup')\n@click.argument('setup', type=click.Choice(SETUPS), metavar='SETUP')\n@click.option('--to', type=click.Path(dir_okay=False, file_okay=False), required=False,\n              default=None, help='Target directory (default: copy to current working directory)')\n@functools.wraps(copy_setup)\ndef cli(*args, **kwargs):\n    copy_setup(*args, **kwargs)\n\n\nif __name__ == '__main__':\n    cli()\n", "path": "veros/cli/veros_copy_setup.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\nimport os\nimport shutil\nimport pkg_resources\nimport functools\n\nimport click\n\nSETUPDIR_ENVVAR = 'VEROS_SETUP_DIR'\nIGNORE_PATTERNS = ['__init__.py', '*.pyc', '__pycache__/']\nSETUPS = {}\n\nsetup_dirs = [pkg_resources.resource_filename('veros', 'setup')]\n\nfor setup_dir in os.environ.get(SETUPDIR_ENVVAR, '').split(';'):\n    if os.path.isdir(setup_dir):\n        setup_dirs.append(setup_dir)\n\n# populate {setup_name: path} mapping\nfor setup_dir in setup_dirs:\n    for setup in os.listdir(setup_dir):\n        setup_path = os.path.join(setup_dir, setup)\n        if not os.path.isdir(setup_path):\n            continue\n        if setup.startswith(('_', '.')):\n            continue\n        SETUPS[setup] = setup_path\n\nSETUP_NAMES = sorted(SETUPS.keys())\n\n\ndef copy_setup(setup, to=None):\n    \"\"\"Copy a standard setup to another directory.\n\n    Argument must be one of: {setups}\n\n    Example:\n\n        $ veros copy-setup global_4deg --to ~/veros-setups/4deg-lowfric\n\n    Further directories containing setup templates can be added to this command\n    via the {setup_envvar} environment variable.\n    \"\"\"\n    if to is None:\n        to = os.path.join(os.getcwd(), setup)\n\n    if os.path.exists(to):\n        raise RuntimeError('Target directory must not exist')\n\n    to_parent = os.path.dirname(os.path.realpath(to))\n\n    if not os.path.exists(to_parent):\n        os.makedirs(to_parent)\n\n    ignore = shutil.ignore_patterns(*IGNORE_PATTERNS)\n    shutil.copytree(\n        SETUPS[setup], to, ignore=ignore\n    )\n\n\ncopy_setup.__doc__ = copy_setup.__doc__.format(\n    setups=', '.join(SETUP_NAMES), setup_envvar=SETUPDIR_ENVVAR\n)\n\n\n@click.command('veros-copy-setup')\n@click.argument('setup', type=click.Choice(SETUP_NAMES), metavar='SETUP')\n@click.option('--to', required=False, default=None,\n              type=click.Path(dir_okay=False, file_okay=False, writable=True),\n              help=('Target directory, must not exist '\n                    '(default: copy to current working directory)'))\n@functools.wraps(copy_setup)\ndef cli(*args, **kwargs):\n    copy_setup(*args, **kwargs)\n\n\nif __name__ == '__main__':\n    cli()\n", "path": "veros/cli/veros_copy_setup.py"}]}