From 7711c81045f6c9cfd4863919e3819380e7d3fd13 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Mon, 2 Oct 2023 15:17:28 -0400 Subject: [PATCH] Point mypy at redwood type stub directly Instead of the possibly slow process of compiling redwood and installing it into the virtualenv, we can just point mypy at the stub directly. (For some reason mypy wanted us to use an explicit "tuple" type.) Notably this means you can run the lint process without needing a Rust toolchain installed. --- redwood/redwood/__init__.pyi | 2 +- securedrop/bin/run-mypy | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/redwood/redwood/__init__.pyi b/redwood/redwood/__init__.pyi index 90a0ede213..d4179e740a 100644 --- a/redwood/redwood/__init__.pyi +++ b/redwood/redwood/__init__.pyi @@ -3,7 +3,7 @@ from pathlib import Path from typing import BinaryIO -def generate_source_key_pair(passphrase: str, email: str) -> (str, str, str): ... +def generate_source_key_pair(passphrase: str, email: str) -> tuple[str, str, str]: ... def encrypt_message(recipients: list[str], plaintext: str, destination: Path) -> None: ... def encrypt_stream(recipients: list[str], plaintext: BinaryIO, destination: Path) -> None: ... def decrypt(ciphertext: bytes, secret_key: str, passphrase: str) -> bytes: ... diff --git a/securedrop/bin/run-mypy b/securedrop/bin/run-mypy index a88dc335a6..25f9d8840c 100755 --- a/securedrop/bin/run-mypy +++ b/securedrop/bin/run-mypy @@ -7,8 +7,9 @@ REPOROOT=$(git rev-parse --show-toplevel) cd "${REPOROOT}" if [ "$(command -v mypy)" ]; then - source "securedrop/bin/dev-deps" - build_redwood + # Point mypy at the redwood package with type stub, see second option on + # . + export MYPYPATH="./redwood" mypy ./securedrop ./admin --namespace-packages --explicit-package-bases "$@" elif [ -d "/opt/venvs/securedrop-app-code/" ]; then # Inside the dev container, but no mypy