use mypy for automatic type checks in Python

This commit adds mypy [0] as build dependency and ensures it is
invoked during the package build process.

mypy can also be manually invoked via `make lint`.

A mypy.ini file [1] is also added to disable errors regarding missing
type stubs for pyVmomi and pyVim.

[0]: https://www.mypy-lang.org/
[1]: https://mypy.readthedocs.io/en/stable/config_file.html

Signed-off-by: Max Carrara <m.carrara@proxmox.com>
This commit is contained in:
Max Carrara 2024-03-22 19:06:24 +01:00 committed by Wolfgang Bumiller
parent 1563eddb55
commit c7bd6d9ba7
3 changed files with 21 additions and 1 deletions

View File

@ -28,6 +28,7 @@ BINARY = $(COMPILEDIR)/esxi-folder-fuse
SCRIPT = listvms.py SCRIPT = listvms.py
CARGO ?= cargo CARGO ?= cargo
MYPY ?= mypy
.PHONY: all .PHONY: all
all: $(BINARY) all: $(BINARY)
@ -40,8 +41,17 @@ check: test
test: test:
$(CARGO) test $(CARGO_BUILD_ARGS) $(CARGO) test $(CARGO_BUILD_ARGS)
.lint-incremental: $(SCRIPT)
$(MYPY) $?
touch "$@"
.PHONY: lint
lint: $(SCRIPT)
$(MYPY) $(SCRIPT)
touch ".lint-incremental"
.PHONY: install .PHONY: install
install: $(BINARY) $(SCRIPT) install: $(BINARY) $(SCRIPT) .lint-incremental
install -m755 -d $(DESTDIR)$(LIBEXECDIR)/pve-esxi-import-tools install -m755 -d $(DESTDIR)$(LIBEXECDIR)/pve-esxi-import-tools
install -m755 -t $(DESTDIR)$(LIBEXECDIR)/pve-esxi-import-tools $(BINARY) install -m755 -t $(DESTDIR)$(LIBEXECDIR)/pve-esxi-import-tools $(BINARY)
install -m755 -t $(DESTDIR)$(LIBEXECDIR)/pve-esxi-import-tools $(SCRIPT) install -m755 -t $(DESTDIR)$(LIBEXECDIR)/pve-esxi-import-tools $(SCRIPT)
@ -55,6 +65,7 @@ $(BUILD_DIR):
cp -t $@.tmp -a \ cp -t $@.tmp -a \
debian \ debian \
Makefile \ Makefile \
mypy.ini \
listvms.py \ listvms.py \
Cargo.toml \ Cargo.toml \
src src

1
debian/control vendored
View File

@ -30,6 +30,7 @@ Build-Depends: cargo:native (>= 0.65.0~),
librust-tokio-1+rt-multi-thread-dev, librust-tokio-1+rt-multi-thread-dev,
librust-tokio-1+time-dev, librust-tokio-1+time-dev,
libstd-rust-dev, libstd-rust-dev,
mypy,
rustc:native, rustc:native,
Maintainer: Proxmox Support Team <support@proxmox.com> Maintainer: Proxmox Support Team <support@proxmox.com>
Standards-Version: 4.6.2 Standards-Version: 4.6.2

8
mypy.ini Normal file
View File

@ -0,0 +1,8 @@
[mypy]
[mypy-pyVmomi]
ignore_missing_imports = True
[mypy-pyVim.*]
ignore_missing_imports = True