Skip to content

Commit

Permalink
Point mypy at redwood type stub directly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
legoktm committed Oct 3, 2023
1 parent f71895a commit 7711c81
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion redwood/redwood/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
5 changes: 3 additions & 2 deletions securedrop/bin/run-mypy
Original file line number Diff line number Diff line change
Expand Up @@ -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
# <https://mypy.readthedocs.io/en/stable/stubs.html#creating-a-stub>.
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
Expand Down

0 comments on commit 7711c81

Please sign in to comment.