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

Use MonkeyType to partially automate typing the codebase #1951

Merged
merged 15 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .devcontainer/scripts/notify-dev-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ echo -e "alias k-staging='aws eks --region ca-central-1 update-kubeconfig --name
echo -e "alias k-prod='aws eks --region ca-central-1 update-kubeconfig --name notification-canada-ca-production-eks-cluster'" >> ~/.zshrc
echo -e "source <(kubectl completion zsh)" >> ~/.zshrc
echo -e "complete -F __start_kubectl k" >> ~/.zshrc
echo -e "alias poe='poetry run poe'" >> ~/.zshrc

# Smoke test
# requires adding files .env_staging and .env_prod to the root of the project
Expand Down Expand Up @@ -50,6 +51,10 @@ make generate-version-file
# Install dependencies
poetry install

# Poe the Poet plugin tab completions
touch ~/.zfunc/_poe
poetry run poe _zsh_completion > ~/.zfunc/_poe

# Upgrade schema of the notification_api database.
poetry run flask db upgrade

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ target/
.idea/
.vscode/settings.json

# MonkeyType
monkeytype.sqlite3

# Mac
*.DS_Store
environment.sh
Expand Down
111 changes: 110 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,52 @@ types-python-dateutil = "2.8.19.20240106"
types-pytz = "2022.7.1.2"
types-requests = "2.31.0.20240406"
types-redis = "4.6.0.20240425"
monkeytype = "^23.3.0"
poethepoet = "^0.24.4"

# Poe the Poet tasks
[tool.poe.tasks.trace-app]
help = "Runs the app with monkeytype type collection enabled."
shell = """
monkeytype run -m flask run -p 6012 --host=0.0.0.0
"""

[tool.poe.tasks.trace-tests]
help = "Runs a test suite or single test through MonkeyType, generating a record of type annotation traces monkeytype.sqlite3"
shell = """
if [ -z "${method}" ]; then
monkeytype run -m pytest '/tests/app/${test-path}::${method}'
else
monkeytype run -m pytest '/tests/app/${test-path}'
fi

"""
# Define arguments for trace-tests
[tool.poe.tasks.trace-tests.args.test-path]
help = "Path to the test file to run. /tests/app/ can be omitted. e.g. poe trace-tests -p main/test_contact.py"
options = ["-p", "--path"]
type = "string"
required = true

[tool.poe.tasks.trace-tests.args.method]
help = "Name of the test method to execute and trace"
options = ["-m", "--method"]
type = "string"
default = ""
required = false

[tool.poe.tasks.list-modules]
help = "Lists all files and modules that have trace data associated with them in monkeytype.sqlite3"
cmd = "monkeytype list-modules"

# Composite task that uses list-modules to obtain a list of files and modules
[tool.poe.tasks.apply-annotations]
help = "Applies ALL known type annotations stored in monkeytype.sqlite3"
shell = """
for trace in ${TRACES}
do
monkeytype apply $trace
done
"""
deps = ["list-modules"]
uses = { TRACES = "list-modules"}
Loading