Repository: qtile/qtile

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.
-->



Discussion:
+1, I had not thought about this at all, but it's a very good point. Thanks for the report!

Resolving patch:
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 @@ def check_config(args):
     # 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)


Test patch:
diff --git a/test/test_check.py b/test/test_check.py
--- a/test/test_check.py
+++ b/test/test_check.py
@@ -63,10 +63,11 @@ def test_check_default_config():
 
 
 def check_literal_config(config):
-    with tempfile.NamedTemporaryFile(suffix=".py") as temp:
-        temp.write(textwrap.dedent(config).encode('utf-8'))
-        temp.flush()
-        return run_qtile_check(temp.name)
+    with tempfile.TemporaryDirectory() as tempdir:
+        with tempfile.NamedTemporaryFile(dir=tempdir, suffix=".py") as temp:
+            temp.write(textwrap.dedent(config).encode('utf-8'))
+            temp.flush()
+            return run_qtile_check(temp.name)
 
 
 def test_check_bad_syntax():
@@ -102,3 +103,13 @@ def test_extra_vars_are_ok():
     assert check_literal_config("""
         this_is_an_extra_config_var = "yes it is"
     """)
+
+
+def test_extra_files_are_ok():
+    with tempfile.TemporaryDirectory() as tempdir:
+        config_file = os.path.join(tempdir, "config.py")
+        with open(config_file, "w") as config:
+            config.write("from bar import foo\n")
+        with open(os.path.join(tempdir, "bar.py"), "w") as config:
+            config.write("foo = 42")
+        assert run_qtile_check(config_file)