-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dev): manage python through devenv (#6514)
this adds devenv to manage python + `.venv` future improvements: - auto-install rust - auto-install node+yarn for snuba admin --------- Co-authored-by: Oliver Newland <[email protected]> Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
- Loading branch information
1 parent
5c2e1c0
commit edd3ee5
Showing
4 changed files
with
66 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
#!/bin/bash | ||
# shellcheck disable=SC1091 | ||
|
||
if [ ! -d .venv ]; then | ||
echo "warning: creating virtualenv for the first time" | ||
if which pyenv > /dev/null; then | ||
eval "$(pyenv init -)" | ||
pyenv install -s | ||
else | ||
echo "warning: pyenv not installed, using python3 and hoping for the best" | ||
fi | ||
if [[ -f "${PWD}/.env" ]]; then | ||
dotenv | ||
fi | ||
|
||
python3 -m venv .venv | ||
source .venv/bin/activate | ||
pip install $(grep ^-- requirements.txt) --upgrade pip==22.2.2 wheel==0.37.1 | ||
make develop | ||
else | ||
source .venv/bin/activate | ||
unset PS1 | ||
PATH_add "${HOME}/.local/share/sentry-devenv/bin" | ||
|
||
if ! command -v devenv >/dev/null; then | ||
echo "install devenv: https://github.com/getsentry/devenv#install" | ||
return 1 | ||
fi | ||
|
||
PATH_add "${PWD}/.devenv/bin" | ||
|
||
if [ ! -d .venv ]; then | ||
devenv sync | ||
fi | ||
|
||
export PATH="$PWD/snuba/admin/node_modules/.bin/:$PATH" | ||
export VIRTUAL_ENV="${PWD}/.venv" | ||
PATH_add "${PWD}/.venv/bin" | ||
|
||
. scripts/rust-envvars |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
brew 'cmake' # for rust-snuba | ||
brew 'protobuf' # for rust-snuba > sentry_protos | ||
brew 'rustup' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[devenv] | ||
minimum_version = 1.16.0 | ||
|
||
[venv.venv] | ||
python = 3.11.11 | ||
path = .venv | ||
# TODO: need to combine requirements files into one | ||
requirements = requirements.txt | ||
editable = | ||
. | ||
|
||
[python3.11.11] | ||
darwin_x86_64 = https://github.com/astral-sh/python-build-standalone/releases/download/20250212/cpython-3.11.11+20250212-x86_64-apple-darwin-install_only.tar.gz | ||
darwin_x86_64_sha256 = 1f1afc064b523b67c06e6d4b024a8dbb8df5fa12f0f0018b218c855491833451 | ||
darwin_arm64 = https://github.com/astral-sh/python-build-standalone/releases/download/20250212/cpython-3.11.11+20250212-aarch64-apple-darwin-install_only.tar.gz | ||
darwin_arm64_sha256 = 6dd5603e5570b8c4e1abf1ef2a329f195dd052890b1fa3b01b7406552a4f45a1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
|
||
from devenv import constants | ||
from devenv.lib import brew, colima, config, proc, venv | ||
|
||
|
||
def main(context: dict[str, str]) -> int: | ||
reporoot = context["reporoot"] | ||
|
||
brew.install() | ||
|
||
proc.run( | ||
(f"{constants.homebrew_bin}/brew", "bundle"), | ||
cwd=reporoot, | ||
) | ||
|
||
venv_dir, python_version, requirements, editable_paths, bins = venv.get( | ||
reporoot, "venv" | ||
) | ||
url, sha256 = config.get_python(reporoot, python_version) | ||
print(f"ensuring venv at {venv_dir}...") | ||
venv.ensure(venv_dir, python_version, url, sha256) | ||
|
||
print(f"syncing venv with {requirements}...") | ||
venv.sync(reporoot, venv_dir, requirements, editable_paths, bins) | ||
|
||
print("running make develop...") | ||
os.system("make develop") | ||
|
||
# start colima if it's not already running | ||
colima.start(reporoot) | ||
|
||
return 0 |