Skip to content

Commit

Permalink
devenv: add repo-local sync (getsentry#65453)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuarli authored Feb 20, 2024
1 parent fc44acc commit 0d29aec
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 2 deletions.
24 changes: 22 additions & 2 deletions devenv/config.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
[python]
version = 3.11.6
[venv.sentry]
python = 3.11.6
path = .venv
requirements = requirements-dev.txt
editable =
.
# sourced by direnv
# bins =

[python3.11.6]
darwin_x86_64 = https://github.com/indygreg/python-build-standalone/releases/download/20231002/cpython-3.11.6+20231002-x86_64-apple-darwin-install_only.tar.gz
darwin_x86_64_sha256 = 178cb1716c2abc25cb56ae915096c1a083e60abeba57af001996e8bc6ce1a371
darwin_arm64 = https://github.com/indygreg/python-build-standalone/releases/download/20231002/cpython-3.11.6+20231002-aarch64-apple-darwin-install_only.tar.gz
Expand All @@ -20,3 +28,15 @@ linux_arm64 = https://github.com/abiosoft/colima/releases/download/v0.6.8/colima
linux_arm64_sha256 = e3bc5267cbe57ab43f181994330b7f89dc486ba80bc734ea9d1644db13458274
# used for autoupdate
version = v0.6.8

# kept here only for compatibility with older `devenv`
[python]
version = 3.11.6
darwin_x86_64 = https://github.com/indygreg/python-build-standalone/releases/download/20231002/cpython-3.11.6+20231002-x86_64-apple-darwin-install_only.tar.gz
darwin_x86_64_sha256 = 178cb1716c2abc25cb56ae915096c1a083e60abeba57af001996e8bc6ce1a371
darwin_arm64 = https://github.com/indygreg/python-build-standalone/releases/download/20231002/cpython-3.11.6+20231002-aarch64-apple-darwin-install_only.tar.gz
darwin_arm64_sha256 = 916c35125b5d8323a21526d7a9154ca626453f63d0878e95b9f613a95006c990
linux_x86_64 = https://github.com/indygreg/python-build-standalone/releases/download/20231002/cpython-3.11.6+20231002-x86_64-unknown-linux-gnu-install_only.tar.gz
linux_x86_64_sha256 = ee37a7eae6e80148c7e3abc56e48a397c1664f044920463ad0df0fc706eacea8
linux_arm64 = https://github.com/indygreg/python-build-standalone/releases/download/20231002/cpython-3.11.6+20231002-aarch64-unknown-linux-gnu-install_only.tar.gz
linux_arm64_sha256 = 3e26a672df17708c4dc928475a5974c3fb3a34a9b45c65fb4bd1e50504cc84ec
169 changes: 169 additions & 0 deletions devenv/sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
from __future__ import annotations

import configparser
import os
import subprocess

from devenv import constants
from devenv.lib import venv # type: ignore
from devenv.lib import colima, config, limactl, proc, volta


# TODO: need to replace this with a nicer process executor in devenv.lib
def run_procs(
repo: str,
reporoot: str,
venv_path: str,
_procs: tuple[tuple[str, tuple[str, ...]], ...],
) -> bool:
procs: list[tuple[str, tuple[str, ...], subprocess.Popen[bytes]]] = []

for name, cmd in _procs:
print(f"⏳ {name}")
if constants.DEBUG:
proc.xtrace(cmd)
procs.append(
(
name,
cmd,
subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
env={
**constants.user_environ,
**proc.base_env,
"VIRTUAL_ENV": venv_path,
"VOLTA_HOME": constants.VOLTA_HOME,
"PATH": f"{venv_path}/bin:{proc.base_path}",
},
cwd=reporoot,
),
)
)

all_good = True
for name, final_cmd, p in procs:
p.wait()
if p.returncode != 0:
all_good = False
if p.stdout is None:
out = ""
else:
out = p.stdout.read().decode()
print(
f"""
{name}
failed command (code p.returncode):
{proc.quote(final_cmd)}
Output:
{out}
"""
)
else:
print(f"✅ {name}")

return all_good


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

venv_dir, python_version, requirements, editable_paths, bins = venv.get(reporoot, "sentry")
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_dir} with {requirements}...")
venv.sync(venv_dir, requirements, editable_paths, bins)

if not run_procs(
repo,
reporoot,
venv_dir,
(
(
"git and precommit",
# this can't be done in paralell with python dependencies
# as multiple pips cannot act on the same venv
("make", "setup-git"),
),
),
):
return 1

# This is for engineers with existing dev environments transitioning over.
# Bootstrap will set devenv-managed volta up but they won't be running
# devenv bootstrap, just installing devenv then running devenv sync.
# make install-js-dev will fail since our run_procs expects devenv-managed
# volta.
volta.install()

if constants.DARWIN:
repo_config = configparser.ConfigParser()
repo_config.read(f"{reporoot}/devenv/config.ini")

# we don't officially support colima on linux yet
if constants.CI:
# colima 0.6.8 doesn't work with macos-13,
# but integration coverage is still handy
colima.install(
"v0.6.2",
"https://github.com/abiosoft/colima/releases/download/v0.6.2/colima-Darwin-x86_64",
"43ef3fc80a8347d51b8ec1706f9caf8863bd8727a6f7532caf1ccd20497d8485",
)
else:
colima.install(
repo_config["colima"]["version"],
repo_config["colima"][constants.SYSTEM_MACHINE],
repo_config["colima"][f"{constants.SYSTEM_MACHINE}_sha256"],
)

# TODO: move limactl version into per-repo config
limactl.install()

if not run_procs(
repo,
reporoot,
venv_dir,
(
("javascript dependencies", ("make", "install-js-dev")),
("python dependencies", ("make", "install-py-dev")),
),
):
return 1

if not os.path.exists(f"{constants.home}/.sentry/config.yml") or not os.path.exists(
f"{constants.home}/.sentry/sentry.conf.py"
):
proc.run((f"{venv_dir}/bin/sentry", "init", "--dev"))

# TODO: check healthchecks for redis and postgres to short circuit this
proc.run(
(
f"{venv_dir}/bin/sentry",
"devservices",
"up",
"redis",
"postgres",
),
exit=True,
)

if run_procs(
repo,
reporoot,
venv_dir,
(
(
"python migrations",
(f"{venv_dir}/bin/sentry", "upgrade", "--noinput"),
),
),
):
return 0

return 1
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ per-file-ignores =
# these scripts must have minimal dependencies so opt out of the usual sentry rules
tools/*: S
.github/*: S
devenv/sync.py: S
# testing the options manager itself
src/sentry/testutils/helpers/options.py, tests/sentry/options/test_manager.py: S011

Expand Down

0 comments on commit 0d29aec

Please sign in to comment.