Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add separate workflow for type checking #4872

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

elParaguayo
Copy link
Member

This would be my preferred way for running our mypy-dependent tests. However, I've no idea why mypy is failing (before even running the specific tests) but our pre-commit script shows no mypy errors.

@jwijenbergh
Copy link
Contributor

Pre-commit runs a different mypy version maybe?

@jwijenbergh
Copy link
Contributor

Pre-commit runs a different mypy version maybe?

Nvm looks like the same version

@elParaguayo
Copy link
Member Author

@jwijenbergh so, the problem is actually that our pre-commit hook isn't working properly. It's running in a virtual environment that doesn't have multiple packages installed (dbus-next, pywlroots etc) and it ignores the missing libraries error.

If we add these to the environment then we actually see the errors!

@elParaguayo elParaguayo force-pushed the ci-mypy branch 2 times, most recently from 240ae31 to bd47275 Compare June 9, 2024 10:58
We have reports of the stack trace:

[ 1845s] Checking Qtile config at: /tmp/tmpmddmh3ov/config.py
[ 1845s] Checking if config is valid python...
[ 1845s] Traceback (most recent call last):
[ 1845s]   File "/home/abuild/rpmbuild/BUILD/qtile-0.26.0/libqtile/scripts/check.py", line 122, in check_config
[ 1845s]     config.load()
[ 1845s]   File "/home/abuild/rpmbuild/BUILD/qtile-0.26.0/libqtile/confreader.py", line 134, in load
[ 1845s]     config = importlib.import_module(name)
[ 1845s]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[ 1845s]   File "/usr/lib64/python3.11/importlib/__init__.py", line 126, in import_module
[ 1845s]     return _bootstrap._gcd_import(name[level:], package, level)
[ 1845s]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[ 1845s]   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
[ 1845s]   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
[ 1845s]   File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
[ 1845s]   File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
[ 1845s]   File "<frozen importlib._bootstrap_external>", line 940, in exec_module
[ 1845s]   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
[ 1845s]   File "/tmp/tmpmddmh3ov/config.py", line 10, in <module>
[ 1845s]     tb.set_font(fontsize=12)
[ 1845s]   File "/home/abuild/rpmbuild/BUILD/qtile-0.26.0/libqtile/widget/base.py", line 733, in set_font
[ 1845s]     self.bar.draw()
[ 1845s]     ^^^^^^^^
[ 1845s]   File "/home/abuild/rpmbuild/BUILD/qtile-0.26.0/libqtile/command/base.py", line 281, in __getattr__
[ 1845s]     raise AttributeError(f"{self.__class__} has no attribute {name}")
[ 1845s] AttributeError: <class 'libqtile.widget.textbox.TextBox'> has no attribute bar

the problem here is that the test actually calls set_font() when imported,
which we can't do since we haven't actually configured a bar yet.

This is part of qtile#4868 and suggests that we are somehow not running the
migration tests correctly in our CI.

Signed-off-by: Tycho Andersen <[email protected]>
@tych0
Copy link
Member

tych0 commented Jun 11, 2024

Ok, I pushed my patch to your branch, but I'm actually wondering if we shouldn't run qtile check in CI right now (at least on all the migrations, probably we should do some small simple config just to verify it works). My reasoning is that we end up with stack traces like this:

------------------------------------------ Captured stdout call ------------------------------------------
<test.migrate.conftest.SourceCode object at 0x7f25a35b9870>
Saved!
Finished. Backup files have not been deleted.
Checking Qtile config at: /tmp/tmpbqfuvj4c/config.py
Checking if config is valid python...
Traceback (most recent call last):
  File "/home/tycho/packages/qtile/libqtile/scripts/check.py", line 122, in check_config
    config.load()
  File "/home/tycho/packages/qtile/libqtile/confreader.py", line 134, in load
    config = importlib.import_module(name)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/tmp/tmpbqfuvj4c/config.py", line 3, in <module>
    qtile.spawn("alacritty")
AttributeError: '_UndefinedQtile' object has no attribute 'spawn'

for e.g. the tests in remove_command_prefix.py, after I add the obvious from libqtile import qtile which is missing. This is because when we import a config, it actually runs all the code.

We could go through and make all the configs not actually call qtile.spawn() like I did in my patch, but I'd rather land something quickly so we can get these tests passing for packaging folks, and it looked like a fair amount of work to change everything.

it makes me wonder though: what happens if people have naked qtile object accesses in their configs now? presumably they can't actually run qtile check either. I guess either nobody has these accesses, or nobody uses qtile check.

@elParaguayo
Copy link
Member Author

That example above should not be run. The Change tests should just be confirming that the text is equal without running the code. Check tests are the ones that need valid import.

@tych0
Copy link
Member

tych0 commented Jun 11, 2024

That example above should not be run. The Change tests should just be confirming that the text is equal without running the code. Check tests are the ones that need valid import.

I don't think this branch is enough, then. The at least one failure from #4868 was a Check test. I think we need tests of that file to pass (i.e. we have to run it in CI and make whatever it runs pass) so that it will work when people run the tests as part of packaging.

@elParaguayo
Copy link
Member Author

The Change tests should be run as part of the normal test suite. The Check tests need mypy.

Could be a mistake in how I've set up the tests so I'll take a look later.

@tych0
Copy link
Member

tych0 commented Jun 11, 2024

The change tests are all skipped because the normal environment doesn't ship mypy; when I added it in #4869 we started getting the same failures that packagers do.

@elParaguayo
Copy link
Member Author

Then I need to fix that. Change tests shouldn't need mypy.

@tych0
Copy link
Member

tych0 commented Jun 11, 2024

Maybe it's as simple as:

diff --git a/test/migrate/test_check_migrations.py b/test/migrate/test_check_migrations.py
index a66f773f..4b0fd336 100644
--- a/test/migrate/test_check_migrations.py
+++ b/test/migrate/test_check_migrations.py
@@ -19,9 +19,9 @@
 import pytest

 from libqtile.scripts.migrations import MIGRATIONS, load_migrations
-from test.test_check import have_mypy, is_cpython
+from test.test_check import is_cpython

-pytestmark = pytest.mark.skipif(not is_cpython() or not have_mypy(), reason="needs mypy")
+pytestmark = pytest.mark.skipif(not is_cpython(), reason="needs cpython")

 migration_tests = []

to reproduce, then?

@tych0
Copy link
Member

tych0 commented Jun 11, 2024

but qtile check runs stubtest (which IIUC is the slow part), and that comes from mypy, right? So isn't it a real dependency?

@elParaguayo
Copy link
Member Author

qtile check skips all type checking if mypy and/or stubtest aren't available. In that scenario, it essentially just checks for syntax errors.

I don't think qtile check touches the migrations.

@tych0
Copy link
Member

tych0 commented Jun 11, 2024

qtile check skips all type checking if mypy and/or stubtest aren't available. In that scenario, it essentially just checks for syntax errors.

i see, ok, that's the bit i was missing.

Copy link

This PR is stale because it has been open 90 days with no activity. Remove the status: stale label or comment, or this will be closed in 30 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants