Add the tools directory to the mypy pre-commit configuration.
bpf_inspect.py has a bunch of mypy errors, so we'll opt it out for now.
Signed-off-by: Omar Sandoval <osandov@osandov.com>
Vermin 1.6.0 was recently released, which contains a fix for
netromdk/vermin#230. This was a rather odd corner case, in which Vermin
would fail when code was compatible with 2.x and 3.x, yet the command
line only required compatibility with 3.x. Since pre-commit runs against
only files that changed, this was possible, for example with small test
files. I'm not sure if I encountered it in drgn (I know I did with
drgn-tools), but it's good to have the fix.
I used pre-commit autoupdate, so we have the latest version of each hook
now. In particular, this commit surpasses mypy 0.971, which is the last
version to support Python 3.6 at runtime. Mypy still supports targeting
Python 3.6[1].
[1]: https://mypy-lang.blogspot.com/2022/07/mypy-0971-released.html
Two new errors were surfaced with the new hooks:
1. Mypy complained about the pattern "os.exit(exception)". I've replaced
these so they explicitly use str: "os.exit(str(exception))".
drgn/cli.py:283: error: Argument 1 to "exit" has incompatible type "OSError"; expected "str | int | None" [arg-type]
2. Vermin complained that "int.is_integer()" was introduced 3.12. I
surmised that it was unable to infer that its usage was guaranteed to
be against a float, and the reason was due to the division operation
against an integer. I changed the integer literal to a float literal,
which resolved the issue.
!2, 3.12 drgn/helpers/common/format.py
'int.is_integer' member requires !2, 3.12
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
The only error is about typing.Literal, which we already have guarded in
a sys.version_info check, so we can add novermin.
Signed-off-by: Omar Sandoval <osandov@osandov.com>
The "pre-commit-hooks" repo contains a few hooks that enforce some nice,
common sense guidelines. The "vermin" hook checks compatibility with a
supplied minimum Python version requirement, both checking the syntax
and standard library usage. It's very helpful for identifying
incompatible code before getting to the CI steps.
Rather than repeatedly excluding the contrib directory, set it to be
excluded at the top-level.
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
Currently on Ubuntu 22.04 LTS, pre-commit hook installation is broken
for isort, with an error that can be seen at [1]. The solution is to
update isort to 5.12.0.
[1]: https://github.com/PyCQA/isort/issues/2077
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
It's come up several times that it'd be nice to have somewhere to dump
drgn scripts that people write while debugging without requiring them to
be cleaned up and scrutinized in code review. Serapheim Dimitropoulos
noted that several projects have a "contrib" directory for this purpose.
See [1]. Let's create one, document it, exclude it from pre-commit, and
move our (mostly unmaintained) examples there.
1: https://drewdevault.com/2020/06/06/Add-a-contrib-directory.html
Signed-off-by: Omar Sandoval <osandov@osandov.com>
This has been useful to run manually before, but I haven't added it to
the CI because it was somewhat noisy. But, it reports some really useful
warnings, so let's configure it for our needs and add it to pre-commit.
Signed-off-by: Omar Sandoval <osandov@osandov.com>
pre-commit/mirrors-mypy@d37f9c4f0c added
"from __future__ import annotations", which doesn't work on Python 3.6.
Python 3.6 is EOL, so it's probably time to drop it, but that should be
a different, intentional change.
Signed-off-by: Omar Sandoval <osandov@osandov.com>
Black 22.3.0 fixespsf/black#2964, which was breaking the CI with:
ImportError: cannot import name '_unicodefun' from 'click'
mypy v0.942 doesn't complain about anything new.
Signed-off-by: Omar Sandoval <osandov@osandov.com>
Black 22.1.0 has some style changes: string prefixes are normalized and
spaces around the power operator are removed.
Signed-off-by: Omar Sandoval <osandov@osandov.com>
During PRs, lint and mypy errors can show up in the CI tests, which is
useful, but can introduce unnecessary churn on the PR as small lint
fixes are pushed. This commit adds (optional) support for pre-commit, a
tool which can be configured to run as a git pre-commit hook, running
linters on all changed code to catch issues before you push your code.
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>