Skip to content

Commit

Permalink
Use devenv to manage python (#901)
Browse files Browse the repository at this point in the history
Switch from `pyenv` to `devenv`, sentry's dev tool, for manage the
pre-commit and non docker requirements.
  • Loading branch information
corps authored Jul 15, 2024
1 parent 6d13cb6 commit f576ad2
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 41 deletions.
23 changes: 12 additions & 11 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
venv_name="${PWD}/.venv"

expected_python_version=$(cat .python-version)
python_version=$(python3 -V 2>&1 | awk '{print $2}')
if [[ $python_version != $expected_python_version ]]; then
echo "Your python version is $python_version, but this project requires $expected_python_version, please switch your current python"
exit 1
if [ -f .env ]; then
dotenv
fi

if [[ ! -f "$venv_name" ]]; then
python3 -m venv "${venv_name}"
if ! command -v "devenv" >/dev/null; then
echo 'Sentry devenv can help simplify dev environment management.
Try out with an install from:
https://github.com/getsentry/devenv#install
'
else
devenv sync
fi

source "${venv_name}/bin/activate"
pip install -r requirements-precommit.txt
if [ -f .venv/bin/activate ]; then
source .venv/bin/activate
fi

if [[ ! -f .git/hooks/pre-commit ]]; then
pre-commit install
Expand Down
27 changes: 0 additions & 27 deletions .github/workflows/test-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,10 @@ jobs:
EXTRA_COMPOSE_TEST_OPTIONS: "-e NO_REAL_MODELS=1 -e NO_SENTRY_INTEGRATION=1"

steps:
- name: Remove unnecessary files
run: |
df / -h
sudo rm -rf /usr/share/dotnet
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
df / -h
- uses: actions/checkout@v3
- name: Clean for PR build
run: |
rm -rf ./models
mkdir models
while IFS= read -r line
do
sed -i.bak "/^$line/d" requirements.txt
done < model.requirements.txt
shell: bash
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build docker image (with cache)
uses: docker/build-push-action@v5
with:
context: .
load: true
cache-from: type=gha
cache-to: type=gha,mode=min

- name: Prepare docker compose environment
run: |
make update
- name: Typecheck with mypy
run: |
make mypy
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ COPY pyproject.toml .
# Copy the supervisord.conf file into the container
COPY supervisord.conf /etc/supervisord.conf

RUN pip install --default-timeout=120 -e . --no-cache-dir
# Ignore dependencies, as they are already installed and docker handles the caching
# this skips annoying rebuilds where requirements would technically be met anyways.
RUN pip install --default-timeout=120 -e . --no-cache-dir --no-deps

ENV FLASK_APP=src.seer.app
# Set in cloudbuild.yaml for production images
Expand Down
15 changes: 15 additions & 0 deletions devenv/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[venv.seer]
python = 3.11.8
path = .venv
requirements = requirements-precommit.txt
editable = .

[python3.11.8]
darwin_x86_64 = https://github.com/indygreg/python-build-standalone/releases/download/20240224/cpython-3.11.8+20240224-x86_64-apple-darwin-install_only.tar.gz
darwin_x86_64_sha256 = 097f467b0c36706bfec13f199a2eaf924e668f70c6e2bd1f1366806962f7e86e
darwin_arm64 = https://github.com/indygreg/python-build-standalone/releases/download/20240224/cpython-3.11.8+20240224-aarch64-apple-darwin-install_only.tar.gz
darwin_arm64_sha256 = 389a51139f5abe071a0d70091ca5df3e7a3dfcfcbe3e0ba6ad85fb4c5638421e
linux_x86_64 = https://github.com/indygreg/python-build-standalone/releases/download/20240224/cpython-3.11.8+20240224-x86_64-unknown-linux-gnu-install_only.tar.gz
linux_x86_64_sha256 = 94e13d0e5ad417035b80580f3e893a72e094b0900d5d64e7e34ab08e95439987
linux_arm64 = https://github.com/indygreg/python-build-standalone/releases/download/20240224/cpython-3.11.8+20240224-aarch64-unknown-linux-gnu-install_only.tar.gz
linux_arm64_sha256 = 389b9005fb78dd5a6f68df5ea45ab7b30d9a4b3222af96999e94fd20d4ad0c6a
18 changes: 18 additions & 0 deletions devenv/sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import annotations

from devenv.lib import config, proc, venv


def main(context: dict[str, str]) -> int:
repo = context["repo"]
reporoot = context["reporoot"]

venv_dir, python_version, requirements, editable_paths, bins = venv.get(reporoot, repo)
url, sha256 = config.get_python(reporoot, python_version)
print(f"ensuring {repo} venv at {venv_dir}...")
venv.ensure(venv_dir, python_version, url, sha256)
venv.sync(reporoot, venv_dir, f"{reporoot}/requirements.txt")

print("Executing update tasks in Makefile...")
proc.run(("make", "-C", reporoot, "update"), exit=True)
return 0
2 changes: 0 additions & 2 deletions model.requirements.txt

This file was deleted.

0 comments on commit f576ad2

Please sign in to comment.