We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Copy entire config folder for qtile check
<!--
Please do not ask general questions here! There are [community
contact](https://github.com/qtile/qtile#community) options for that.
-->

# Issue description
My config is split across two files, `config.py` (main config) and `custom.py` (custom widgets), but `qtile check` only copies the `config.py` file to the `/tmp/tmp…/` folder; therefore, the `mypy` check fails because it cannot find the `custom` module. I can work around this by quickly copying the `custom.py` file to the folder, but this gets annoying.

This could be fixed by automatically copying the entire `~/.config/qtile` folder to the temporary folder, instead of just the `config.py`. It might also be necessary to remove the `__pycache__` folder if it is present.
<!--
A brief discussion of what failed and how it failed. A description of
what you tried is helpful, i.e. "When I use lazy.kill() on a window I get
the following stack trace" instead of "Closing windows doesn't work".
-->

# Qtile version
The latest version on the Archlinux repos, `v0.17.0-1` (not sure about exact commit hash, sadly).
<!--
Please include the exact commit hash of the version of Qtile that failed.
-->

# Configuration
https://github.com/MithicSpirit/dotfiles/tree/master/.config/qtile
<!--
Please include a link or attach your configuration to the issue.
-->


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `libqtile/scripts/check.py`
Content:
```
1 # Copyright (c) 2020, Tycho Andersen. All rights reserved.
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
9 #
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
12 #
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 # SOFTWARE.
20 
21 # Set the locale before any widgets or anything are imported, so any widget
22 # whose defaults depend on a reasonable locale sees something reasonable.
23 import shutil
24 import subprocess
25 import sys
26 import tempfile
27 from os import environ, getenv, path
28 
29 from libqtile import confreader
30 
31 
32 def type_check_config_vars(tempdir, config_name):
33     if shutil.which("stubtest") is None:
34         print("stubtest not found, can't type check config file\n"
35               "install it and try again")
36         return
37 
38     # write a .pyi file to tempdir:
39     f = open(path.join(tempdir, config_name+".pyi"), "w")
40     f.write(confreader.config_pyi_header)
41     for (name, type_) in confreader.Config.settings_keys:
42         f.write(name)
43         f.write(": ")
44         f.write(type_)
45         f.write("\n")
46     f.close()
47 
48     # need to tell python to look in pwd for modules
49     newenv = environ.copy()
50     newenv["PYTHONPATH"] = newenv.get("PYTHONPATH", "") + ":"
51 
52     p = subprocess.Popen(
53         ["stubtest", "--concise", config_name],
54         stdout=subprocess.PIPE,
55         stderr=subprocess.PIPE,
56         cwd=tempdir,
57         text=True,
58         env=newenv,
59     )
60     stdout, stderr = p.communicate()
61     missing_vars = []
62     for line in (stdout+stderr).split("\n"):
63         # filter out stuff that users didn't specify; they'll be imported from
64         # the default config
65         if "is not present at runtime" in line:
66             missing_vars.append(line.split()[0])
67 
68     # write missing vars to a tempfile
69     whitelist = open(path.join(tempdir, "stubtest_whitelist"), "w")
70     for var in missing_vars:
71         whitelist.write(var)
72         whitelist.write("\n")
73     whitelist.close()
74 
75     p = subprocess.Popen([
76             "stubtest",
77             # ignore variables that the user creates in their config that
78             # aren't in our default config list
79             "--ignore-missing-stub",
80             # use our whitelist to ignore stuff users didn't specify
81             "--whitelist", whitelist.name,
82             config_name,
83         ],
84         cwd=tempdir,
85         text=True,
86         env=newenv,
87     )
88     p.wait()
89     if p.returncode != 0:
90         sys.exit(1)
91 
92 
93 def type_check_config_args(config_file):
94     if shutil.which("mypy") is None:
95         print("mypy not found, can't type check config file"
96               "install it and try again")
97         return
98     try:
99         # we want to use Literal, which is in 3.8. If people have a mypy that
100         # is too old, they can upgrade; this is an optional check anyways.
101         subprocess.check_call(["mypy", "--python-version=3.8", config_file])
102         print("config file type checking succeeded")
103     except subprocess.CalledProcessError as e:
104         print("config file type checking failed: {}".format(e))
105         sys.exit(1)
106 
107 
108 def check_config(args):
109     print("checking qtile config file {}".format(args.configfile))
110 
111     # need to do all the checking in a tempdir because we need to write stuff
112     # for stubtest
113     with tempfile.TemporaryDirectory() as tempdir:
114         tmp_path = path.join(tempdir, "config.py")
115         shutil.copy(args.configfile, tmp_path)
116 
117         # are the top level config variables the right type?
118         type_check_config_vars(tempdir, "config")
119 
120         # are arguments passed to qtile APIs correct?
121         type_check_config_args(tmp_path)
122 
123     # can we load the config?
124     config = confreader.Config(args.configfile)
125     config.load()
126     config.validate()
127     print("config file can be loaded by qtile")
128 
129 
130 def add_subcommand(subparsers):
131     parser = subparsers.add_parser("check", help="Check a configuration file for errors")
132     parser.add_argument(
133         "-c", "--config",
134         action="store",
135         default=path.expanduser(path.join(
136             getenv('XDG_CONFIG_HOME', '~/.config'), 'qtile', 'config.py')),
137         dest="configfile",
138         help='Use the specified configuration file',
139     )
140     parser.set_defaults(func=check_config)
141
```
--- 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/libqtile/scripts/check.py b/libqtile/scripts/check.py
--- a/libqtile/scripts/check.py
+++ b/libqtile/scripts/check.py
@@ -111,11 +111,12 @@
     # need to do all the checking in a tempdir because we need to write stuff
     # for stubtest
     with tempfile.TemporaryDirectory() as tempdir:
-        tmp_path = path.join(tempdir, "config.py")
-        shutil.copy(args.configfile, tmp_path)
+        shutil.copytree(path.dirname(args.configfile), tempdir, dirs_exist_ok=True)
+        tmp_path = path.join(tempdir, path.basename(args.configfile))
 
         # are the top level config variables the right type?
-        type_check_config_vars(tempdir, "config")
+        module_name = path.splitext(path.basename(args.configfile))[0]
+        type_check_config_vars(tempdir, module_name)
 
         # are arguments passed to qtile APIs correct?
         type_check_config_args(tmp_path)

{"golden_diff": "diff --git a/libqtile/scripts/check.py b/libqtile/scripts/check.py\n--- a/libqtile/scripts/check.py\n+++ b/libqtile/scripts/check.py\n@@ -111,11 +111,12 @@\n     # need to do all the checking in a tempdir because we need to write stuff\n     # for stubtest\n     with tempfile.TemporaryDirectory() as tempdir:\n-        tmp_path = path.join(tempdir, \"config.py\")\n-        shutil.copy(args.configfile, tmp_path)\n+        shutil.copytree(path.dirname(args.configfile), tempdir, dirs_exist_ok=True)\n+        tmp_path = path.join(tempdir, path.basename(args.configfile))\n \n         # are the top level config variables the right type?\n-        type_check_config_vars(tempdir, \"config\")\n+        module_name = path.splitext(path.basename(args.configfile))[0]\n+        type_check_config_vars(tempdir, module_name)\n \n         # are arguments passed to qtile APIs correct?\n         type_check_config_args(tmp_path)\n", "issue": "Copy entire config folder for qtile check\n<!--\r\nPlease do not ask general questions here! There are [community\r\ncontact](https://github.com/qtile/qtile#community) options for that.\r\n-->\r\n\r\n# Issue description\r\nMy config is split across two files, `config.py` (main config) and `custom.py` (custom widgets), but `qtile check` only copies the `config.py` file to the `/tmp/tmp\u2026/` folder; therefore, the `mypy` check fails because it cannot find the `custom` module. I can work around this by quickly copying the `custom.py` file to the folder, but this gets annoying.\r\n\r\nThis could be fixed by automatically copying the entire `~/.config/qtile` folder to the temporary folder, instead of just the `config.py`. It might also be necessary to remove the `__pycache__` folder if it is present.\r\n<!--\r\nA brief discussion of what failed and how it failed. A description of\r\nwhat you tried is helpful, i.e. \"When I use lazy.kill() on a window I get\r\nthe following stack trace\" instead of \"Closing windows doesn't work\".\r\n-->\r\n\r\n# Qtile version\r\nThe latest version on the Archlinux repos, `v0.17.0-1` (not sure about exact commit hash, sadly).\r\n<!--\r\nPlease include the exact commit hash of the version of Qtile that failed.\r\n-->\r\n\r\n# Configuration\r\nhttps://github.com/MithicSpirit/dotfiles/tree/master/.config/qtile\r\n<!--\r\nPlease include a link or attach your configuration to the issue.\r\n-->\r\n\n", "before_files": [{"content": "# Copyright (c) 2020, Tycho Andersen. All rights reserved.\n#\n# Permission is hereby granted, free of charge, to any person obtaining a copy\n# of this software and associated documentation files (the \"Software\"), to deal\n# in the Software without restriction, including without limitation the rights\n# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n# copies of the Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice shall be included in\n# all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n# SOFTWARE.\n\n# Set the locale before any widgets or anything are imported, so any widget\n# whose defaults depend on a reasonable locale sees something reasonable.\nimport shutil\nimport subprocess\nimport sys\nimport tempfile\nfrom os import environ, getenv, path\n\nfrom libqtile import confreader\n\n\ndef type_check_config_vars(tempdir, config_name):\n    if shutil.which(\"stubtest\") is None:\n        print(\"stubtest not found, can't type check config file\\n\"\n              \"install it and try again\")\n        return\n\n    # write a .pyi file to tempdir:\n    f = open(path.join(tempdir, config_name+\".pyi\"), \"w\")\n    f.write(confreader.config_pyi_header)\n    for (name, type_) in confreader.Config.settings_keys:\n        f.write(name)\n        f.write(\": \")\n        f.write(type_)\n        f.write(\"\\n\")\n    f.close()\n\n    # need to tell python to look in pwd for modules\n    newenv = environ.copy()\n    newenv[\"PYTHONPATH\"] = newenv.get(\"PYTHONPATH\", \"\") + \":\"\n\n    p = subprocess.Popen(\n        [\"stubtest\", \"--concise\", config_name],\n        stdout=subprocess.PIPE,\n        stderr=subprocess.PIPE,\n        cwd=tempdir,\n        text=True,\n        env=newenv,\n    )\n    stdout, stderr = p.communicate()\n    missing_vars = []\n    for line in (stdout+stderr).split(\"\\n\"):\n        # filter out stuff that users didn't specify; they'll be imported from\n        # the default config\n        if \"is not present at runtime\" in line:\n            missing_vars.append(line.split()[0])\n\n    # write missing vars to a tempfile\n    whitelist = open(path.join(tempdir, \"stubtest_whitelist\"), \"w\")\n    for var in missing_vars:\n        whitelist.write(var)\n        whitelist.write(\"\\n\")\n    whitelist.close()\n\n    p = subprocess.Popen([\n            \"stubtest\",\n            # ignore variables that the user creates in their config that\n            # aren't in our default config list\n            \"--ignore-missing-stub\",\n            # use our whitelist to ignore stuff users didn't specify\n            \"--whitelist\", whitelist.name,\n            config_name,\n        ],\n        cwd=tempdir,\n        text=True,\n        env=newenv,\n    )\n    p.wait()\n    if p.returncode != 0:\n        sys.exit(1)\n\n\ndef type_check_config_args(config_file):\n    if shutil.which(\"mypy\") is None:\n        print(\"mypy not found, can't type check config file\"\n              \"install it and try again\")\n        return\n    try:\n        # we want to use Literal, which is in 3.8. If people have a mypy that\n        # is too old, they can upgrade; this is an optional check anyways.\n        subprocess.check_call([\"mypy\", \"--python-version=3.8\", config_file])\n        print(\"config file type checking succeeded\")\n    except subprocess.CalledProcessError as e:\n        print(\"config file type checking failed: {}\".format(e))\n        sys.exit(1)\n\n\ndef check_config(args):\n    print(\"checking qtile config file {}\".format(args.configfile))\n\n    # need to do all the checking in a tempdir because we need to write stuff\n    # for stubtest\n    with tempfile.TemporaryDirectory() as tempdir:\n        tmp_path = path.join(tempdir, \"config.py\")\n        shutil.copy(args.configfile, tmp_path)\n\n        # are the top level config variables the right type?\n        type_check_config_vars(tempdir, \"config\")\n\n        # are arguments passed to qtile APIs correct?\n        type_check_config_args(tmp_path)\n\n    # can we load the config?\n    config = confreader.Config(args.configfile)\n    config.load()\n    config.validate()\n    print(\"config file can be loaded by qtile\")\n\n\ndef add_subcommand(subparsers):\n    parser = subparsers.add_parser(\"check\", help=\"Check a configuration file for errors\")\n    parser.add_argument(\n        \"-c\", \"--config\",\n        action=\"store\",\n        default=path.expanduser(path.join(\n            getenv('XDG_CONFIG_HOME', '~/.config'), 'qtile', 'config.py')),\n        dest=\"configfile\",\n        help='Use the specified configuration file',\n    )\n    parser.set_defaults(func=check_config)\n", "path": "libqtile/scripts/check.py"}], "after_files": [{"content": "# Copyright (c) 2020, Tycho Andersen. All rights reserved.\n#\n# Permission is hereby granted, free of charge, to any person obtaining a copy\n# of this software and associated documentation files (the \"Software\"), to deal\n# in the Software without restriction, including without limitation the rights\n# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n# copies of the Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice shall be included in\n# all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n# SOFTWARE.\n\n# Set the locale before any widgets or anything are imported, so any widget\n# whose defaults depend on a reasonable locale sees something reasonable.\nimport shutil\nimport subprocess\nimport sys\nimport tempfile\nfrom os import environ, getenv, path\n\nfrom libqtile import confreader\n\n\ndef type_check_config_vars(tempdir, config_name):\n    if shutil.which(\"stubtest\") is None:\n        print(\"stubtest not found, can't type check config file\\n\"\n              \"install it and try again\")\n        return\n\n    # write a .pyi file to tempdir:\n    f = open(path.join(tempdir, config_name+\".pyi\"), \"w\")\n    f.write(confreader.config_pyi_header)\n    for (name, type_) in confreader.Config.settings_keys:\n        f.write(name)\n        f.write(\": \")\n        f.write(type_)\n        f.write(\"\\n\")\n    f.close()\n\n    # need to tell python to look in pwd for modules\n    newenv = environ.copy()\n    newenv[\"PYTHONPATH\"] = newenv.get(\"PYTHONPATH\", \"\") + \":\"\n\n    p = subprocess.Popen(\n        [\"stubtest\", \"--concise\", config_name],\n        stdout=subprocess.PIPE,\n        stderr=subprocess.PIPE,\n        cwd=tempdir,\n        text=True,\n        env=newenv,\n    )\n    stdout, stderr = p.communicate()\n    missing_vars = []\n    for line in (stdout+stderr).split(\"\\n\"):\n        # filter out stuff that users didn't specify; they'll be imported from\n        # the default config\n        if \"is not present at runtime\" in line:\n            missing_vars.append(line.split()[0])\n\n    # write missing vars to a tempfile\n    whitelist = open(path.join(tempdir, \"stubtest_whitelist\"), \"w\")\n    for var in missing_vars:\n        whitelist.write(var)\n        whitelist.write(\"\\n\")\n    whitelist.close()\n\n    p = subprocess.Popen([\n            \"stubtest\",\n            # ignore variables that the user creates in their config that\n            # aren't in our default config list\n            \"--ignore-missing-stub\",\n            # use our whitelist to ignore stuff users didn't specify\n            \"--whitelist\", whitelist.name,\n            config_name,\n        ],\n        cwd=tempdir,\n        text=True,\n        env=newenv,\n    )\n    p.wait()\n    if p.returncode != 0:\n        sys.exit(1)\n\n\ndef type_check_config_args(config_file):\n    if shutil.which(\"mypy\") is None:\n        print(\"mypy not found, can't type check config file\"\n              \"install it and try again\")\n        return\n    try:\n        # we want to use Literal, which is in 3.8. If people have a mypy that\n        # is too old, they can upgrade; this is an optional check anyways.\n        subprocess.check_call([\"mypy\", \"--python-version=3.8\", config_file])\n        print(\"config file type checking succeeded\")\n    except subprocess.CalledProcessError as e:\n        print(\"config file type checking failed: {}\".format(e))\n        sys.exit(1)\n\n\ndef check_config(args):\n    print(\"checking qtile config file {}\".format(args.configfile))\n\n    # need to do all the checking in a tempdir because we need to write stuff\n    # for stubtest\n    with tempfile.TemporaryDirectory() as tempdir:\n        shutil.copytree(path.dirname(args.configfile), tempdir, dirs_exist_ok=True)\n        tmp_path = path.join(tempdir, path.basename(args.configfile))\n\n        # are the top level config variables the right type?\n        module_name = path.splitext(path.basename(args.configfile))[0]\n        type_check_config_vars(tempdir, module_name)\n\n        # are arguments passed to qtile APIs correct?\n        type_check_config_args(tmp_path)\n\n    # can we load the config?\n    config = confreader.Config(args.configfile)\n    config.load()\n    config.validate()\n    print(\"config file can be loaded by qtile\")\n\n\ndef add_subcommand(subparsers):\n    parser = subparsers.add_parser(\"check\", help=\"Check a configuration file for errors\")\n    parser.add_argument(\n        \"-c\", \"--config\",\n        action=\"store\",\n        default=path.expanduser(path.join(\n            getenv('XDG_CONFIG_HOME', '~/.config'), 'qtile', 'config.py')),\n        dest=\"configfile\",\n        help='Use the specified configuration file',\n    )\n    parser.set_defaults(func=check_config)\n", "path": "libqtile/scripts/check.py"}]}