Browse Source

devenv: move install-js-dev to sync (#74384)

Frontend only devs can set `SENTRY_DEVENV_FRONTEND_ONLY=1` if they want
to omit colima + python migrations.
joshuarli 7 months ago
parent
commit
b2a1b6119b
4 changed files with 40 additions and 27 deletions
  1. 1 1
      .envrc
  2. 2 2
      Makefile
  3. 37 12
      devenv/sync.py
  4. 0 12
      scripts/lib.sh

+ 1 - 1
.envrc

@@ -186,7 +186,7 @@ make node-version-check
 
 if [ ! -x "node_modules/.bin/webpack" ]; then
     warn "You don't seem to have yarn packages installed."
-    commands_to_run+=("make install-js-dev")
+    commands_to_run+=("devenv sync")
 fi
 
 PATH_add node_modules/.bin

+ 2 - 2
Makefile

@@ -21,11 +21,11 @@ drop-db \
 create-db \
 apply-migrations \
 reset-db \
-node-version-check \
-install-js-dev :
+node-version-check :
 	@./scripts/do.sh $@
 
 develop \
+install-js-dev \
 install-py-dev :
 	@make devenv-sync
 

+ 37 - 12
devenv/sync.py

@@ -14,14 +14,23 @@ def run_procs(
     repo: str,
     reporoot: str,
     venv_path: str,
-    _procs: tuple[tuple[str, tuple[str, ...]], ...],
+    _procs: tuple[tuple[str, tuple[str, ...], dict[str, str]], ...],
 ) -> bool:
     procs: list[tuple[str, tuple[str, ...], subprocess.Popen[bytes]]] = []
 
-    for name, cmd in _procs:
+    for name, cmd, extra_env in _procs:
         print(f"⏳ {name}")
         if constants.DEBUG:
             proc.xtrace(cmd)
+        env = {
+            **constants.user_environ,
+            **proc.base_env,
+            "VIRTUAL_ENV": venv_path,
+            "VOLTA_HOME": f"{reporoot}/.devenv/bin/volta-home",
+            "PATH": f"{venv_path}/bin:{reporoot}/.devenv/bin:{proc.base_path}",
+        }
+        if extra_env:
+            env = {**env, **extra_env}
         procs.append(
             (
                 name,
@@ -30,13 +39,7 @@ def run_procs(
                     cmd,
                     stdout=subprocess.PIPE,
                     stderr=subprocess.STDOUT,
-                    env={
-                        **constants.user_environ,
-                        **proc.base_env,
-                        "VIRTUAL_ENV": venv_path,
-                        "VOLTA_HOME": f"{reporoot}/.devenv/bin/volta-home",
-                        "PATH": f"{venv_path}/bin:{reporoot}/.devenv/bin:{proc.base_path}",
-                    },
+                    env=env,
                     cwd=reporoot,
                 ),
             )
@@ -127,6 +130,7 @@ def main(context: dict[str, str]) -> int:
                     "requirements-dev-frozen.txt",
                     "pip",
                 ),
+                {},
             ),
         ),
     ):
@@ -137,6 +141,21 @@ def main(context: dict[str, str]) -> int:
         reporoot,
         venv_dir,
         (
+            (
+                # Spreading out the network load by installing js,
+                # then py in the next batch.
+                "javascript dependencies (1/1)",
+                (
+                    "yarn",
+                    "install",
+                    "--frozen-lockfile",
+                    "--no-progress",
+                    "--non-interactive",
+                ),
+                {
+                    "NODE_ENV": "development",
+                },
+            ),
             (
                 "python dependencies (2/4)",
                 (
@@ -146,6 +165,7 @@ def main(context: dict[str, str]) -> int:
                     "djangorestframework-stubs",
                     "django-stubs",
                 ),
+                {},
             ),
         ),
     ):
@@ -156,7 +176,6 @@ def main(context: dict[str, str]) -> int:
         reporoot,
         venv_dir,
         (
-            ("javascript dependencies", ("make", "install-js-dev")),
             # could opt out of syncing python if FRONTEND_ONLY but only if repo-local devenv
             # and pre-commit were moved to inside devenv and not the sentry venv
             (
@@ -169,6 +188,7 @@ def main(context: dict[str, str]) -> int:
                     "-r",
                     "requirements-dev-frozen.txt",
                 ),
+                {},
             ),
         ),
     ):
@@ -179,8 +199,12 @@ def main(context: dict[str, str]) -> int:
         reporoot,
         venv_dir,
         (
-            ("python dependencies (4/4)", ("python3", "-m", "tools.fast_editable", "--path", ".")),
-            ("pre-commit dependencies", ("pre-commit", "install", "--install-hooks", "-f")),
+            (
+                "python dependencies (4/4)",
+                ("python3", "-m", "tools.fast_editable", "--path", "."),
+                {},
+            ),
+            ("pre-commit dependencies", ("pre-commit", "install", "--install-hooks", "-f"), {}),
         ),
     ):
         return 1
@@ -219,6 +243,7 @@ def main(context: dict[str, str]) -> int:
             (
                 "python migrations",
                 ("make", "apply-migrations"),
+                {},
             ),
         ),
     ):

+ 0 - 12
scripts/lib.sh

@@ -89,18 +89,6 @@ node-version-check() {
         )
 }
 
-install-js-dev() {
-    node-version-check
-    echo "--> Installing Yarn packages (for development)"
-    # Use NODE_ENV=development so that yarn installs both dependencies + devDependencies
-    NODE_ENV=development yarn install --frozen-lockfile
-    # A common problem is with node packages not existing in `node_modules` even though `yarn install`
-    # says everything is up to date. Even though `yarn install` is run already, it doesn't take into
-    # account the state of the current filesystem (it only checks .yarn-integrity).
-    # Add an additional check against `node_modules`
-    yarn check --verify-tree || yarn install --check-files
-}
-
 init-config() {
     sentry init --dev --no-clobber
 }