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

Add Monkeytype and Poe the Poet plugin for Poetry #1731

Merged
merged 33 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6ad6365
Add monkeytype and poe the poet plugin for poetry
whabanks Dec 1, 2023
660d5d9
Fix some wording
whabanks Dec 1, 2023
84370db
Merge branch 'main' into experiment-poe-monkeytype
whabanks Dec 5, 2023
2c2f8e9
Fix typo in trace-tests task
whabanks Dec 5, 2023
091378c
Merge branch 'main' into experiment-poe-monkeytype
whabanks Jan 30, 2024
bd1f20c
Merge branch 'main' into experiment-poe-monkeytype
whabanks Feb 6, 2024
2cd6d79
Improve poe tasks
whabanks Apr 6, 2024
cf8d496
Only allow monkeytype to trace our modules
whabanks Apr 19, 2024
66ba254
Merge remote-tracking branch 'origin/main' into experiment-poe-monkey…
whabanks Apr 19, 2024
8bfac9d
Update lock file
whabanks Apr 19, 2024
d992b08
Merge branch 'main' into experiment-poe-monkeytype
whabanks May 17, 2024
fb772c8
Refresh lock file
whabanks May 17, 2024
63aa8f9
Formatting
whabanks May 17, 2024
81b76d9
Update build backend
whabanks May 17, 2024
e63be36
Update pip before running installs
whabanks May 17, 2024
883cfaf
Quick typo fix
whabanks May 17, 2024
8727b61
Messing with build deps
whabanks May 17, 2024
290c96b
Test updated alpine image
whabanks May 17, 2024
52388ad
Migrate make targets to poe
whabanks May 28, 2024
dd26fda
Merge branch 'main' into experiment-poe-monkeytype
whabanks May 28, 2024
d2ab8d9
Update poetry lock file
whabanks May 28, 2024
98e908d
Merge branch 'main' into experiment-poe-monkeytype
whabanks Jun 14, 2024
8c633c2
Fix Dockerfile.lambda
whabanks Jun 14, 2024
932ff76
Add rust and cargo to Dockerfile
whabanks Jun 14, 2024
8c100f1
Bump docker image to 3.18
whabanks Jun 14, 2024
0c30657
Merge branch 'main' into experiment-poe-monkeytype
whabanks Jun 21, 2024
de5a2c2
Update lock file
whabanks Jun 21, 2024
937294e
Merge branch 'main' into experiment-poe-monkeytype
whabanks Jul 5, 2024
57586b0
Merge branch 'main' into experiment-poe-monkeytype
jzbahrai Jul 10, 2024
70e7393
Merge branch 'main' into experiment-poe-monkeytype
whabanks Jul 30, 2024
7e641f2
Merge branch 'main' into experiment-poe-monkeytype
whabanks Sep 12, 2024
3f25813
Merge branch 'main' into experiment-poe-monkeytype
whabanks Sep 12, 2024
eb8de39
update lock file
whabanks Sep 12, 2024
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/installations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ echo -e "alias ls='exa'" >> ~/.zshrc
echo -e "alias l='exa -alh'" >> ~/.zshrc
echo -e "alias ll='exa -alh@ --git'" >> ~/.zshrc
echo -e "alias lt='exa -al -T -L 2'" >> ~/.zshrc
echo -e "alias poe='poetry run poe'" >> ~/.zshrc

# Poetry autocomplete
echo -e "fpath+=/.zfunc" >> ~/.zshrc
Expand All @@ -33,6 +34,10 @@ poetry completions zsh > ~/.zfunc/_poetry
cd /workspaces/notification-admin
poetry install

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

npm rebuild node-sass
make generate-version-file
make babel
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ test_results.xml
*.pot
app/translations/csv/en.csv

# MonkeyType
monkeytype.sqlite3

# Django stuff:
*.log

Expand Down
9 changes: 8 additions & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
from app.models.organisation import Organisation
from app.models.service import Service
from app.models.user import AnonymousUser, User
from app.monkeytype_config import MonkeytypeConfig
from app.navigation import (
AdminNavigation,
HeaderNavigation,
Expand Down Expand Up @@ -92,7 +93,6 @@
login_manager = LoginManager()
csrf = CSRFProtect()


# The current service attached to the request stack.
current_service: Service = LocalProxy(lambda: g.current_service) # type: ignore

Expand Down Expand Up @@ -231,6 +231,13 @@ def get_locale():
application.config["CRM_ORG_LIST_URL"], application.config["CRM_GITHUB_PERSONAL_ACCESS_TOKEN"], application.logger
)

# Specify packages to be traced by MonkeyType. This can be overriden
# via the MONKEYTYPE_TRACE_MODULES environment variable. e.g:
# MONKEYTYPE_TRACE_MODULES="app.,notifications_utils."
if application.config["NOTIFY_ENVIRONMENT"] == "development":
packages_prefix = ["app.", "notifications_utils."]
application.monkeytype_config = MonkeytypeConfig(packages_prefix)


def init_app(application):
application.after_request(useful_headers_after_request)
Expand Down
19 changes: 19 additions & 0 deletions app/monkeytype_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os

from monkeytype.config import DefaultConfig


class MonkeytypeConfig(DefaultConfig):
def __init__(self, package_prefixes):
self.package_prefixes = package_prefixes

def code_filter(self, code):
# Get the module name from the code object
# and convert the file path to a module name
module_name = code.co_filname.replace(os.path.sep, ".")[:-3]

for prefix in self.package_prefixes:
if module_name.startswith(prefix):
return True

return False
2 changes: 1 addition & 1 deletion ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV PYTHONDONTWRITEBYTECODE 1
ENV POETRY_VERSION="1.7.1"
ENV POETRY_VIRTUALENVS_CREATE false

RUN apk add --no-cache bash build-base libxml2-dev libxslt-dev git nodejs npm g++ make libffi-dev && rm -rf /var/cache/apk/*
RUN apk add --no-cache bash build-base libxml2-dev libxslt-dev git nodejs npm g++ make libffi-dev rust cargo && rm -rf /var/cache/apk/*

# update pip
RUN python -m pip install wheel poetry==${POETRY_VERSION}
Expand Down
21 changes: 14 additions & 7 deletions ci/Dockerfile.lambda
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ARG POETRY_VERSION="1.7.1"
ARG POETRY_VIRTUALENVS_CREATE="false"

# Build image
FROM python:3.10-alpine3.16@sha256:afe68972cc00883d70b3760ee0ffbb7375cf09706c122dda7063ffe64c5be21b as base
FROM python:3.10-alpine3.18@sha256:d5ee9613c89c9bd4c4112465d2136512ea8629bce6ff15fa27144f3cc16b5c6b as base

ARG APP_DIR
ARG APP_VENV
Expand All @@ -26,28 +26,35 @@ RUN apk add --no-cache \
cmake \
g++ \
git \
libexecinfo-dev \
libffi-dev \
libtool \
libxml2-dev \
libxslt-dev \
nodejs \
npm \
make
make \
rust \
cargo

# wheel requires rustc 1.70 or later so we'll pull it in from the 3.18 package repo
# We could update the base image to 3.18 but libexecinfo-dev was dropped in 3.17, so
# either way we need to pull a package in from a different repo to build the base image
RUN apk add --no-cache --update --repository=https://dl-cdn.alpinelinux.org/alpine/v3.16/main/ libexecinfo-dev

RUN mkdir -p ${APP_DIR}
WORKDIR ${APP_DIR}

# Install Poetry and isolate it from the project
RUN python -m venv ${POETRY_HOME} \
&& ${POETRY_HOME}/bin/pip3 install poetry==${POETRY_VERSION}
RUN python -m venv ${POETRY_HOME}
RUN ${POETRY_HOME}/bin/pip3 install --upgrade pip
RUN ${POETRY_HOME}/bin/pip3 install poetry==${POETRY_VERSION}

COPY pyproject.toml poetry.lock ${APP_DIR}/

RUN python -m venv ${APP_VENV} \
&& . ${APP_VENV}/bin/activate \
&& poetry install \
&& poetry add awslambdaric wheel
&& poetry add wheel awslambdaric

COPY package.json package-lock.json ${APP_DIR}/
RUN npm ci
Expand All @@ -61,7 +68,7 @@ RUN . ${APP_VENV}/bin/activate \
&& make generate-version-file

# Final image
FROM python:3.10-alpine3.16@sha256:afe68972cc00883d70b3760ee0ffbb7375cf09706c122dda7063ffe64c5be21b as lambda
FROM python:3.10-alpine3.18@sha256:d5ee9613c89c9bd4c4112465d2136512ea8629bce6ff15fa27144f3cc16b5c6b as lambda

ARG APP_DIR
ARG APP_VENV
Expand Down
Loading
Loading