pw_build: Restore ._build_wheel for Python Pkgs

The new Python build system flag was inadvertently disabling the
._build_wheel targets for every python package. This was breaking the
pw_python_wheels template.

Also only add install_3p_deps as dep on python actions if the new
Python build system is enabled.

Change-Id: Idca81ccd6efd3323891e2f74c82da5038bd4a0a9
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/94280
Reviewed-by: Armando Montanez <amontanez@google.com>
Commit-Queue: Anthony DiGirolamo <tonymd@google.com>
diff --git a/pw_build/python.gni b/pw_build/python.gni
index 0b94463..184dbb5 100644
--- a/pw_build/python.gni
+++ b/pw_build/python.gni
@@ -490,58 +490,64 @@
       }
     }
 
-    if (_is_package && _pip_install_package) {
-      # Install this Python package and its dependencies in the current Python
-      # environment using pip.
-      pw_python_action("$target_name._run_pip_install") {
-        module = "pip"
-        public_deps = []
-        if (defined(invoker.public_deps)) {
-          public_deps += invoker.public_deps
-        }
+    if (_is_package) {
+      if (_pip_install_package) {
+        # Install this Python package and its dependencies in the current Python
+        # environment using pip.
+        pw_python_action("$target_name._run_pip_install") {
+          module = "pip"
+          public_deps = []
+          if (defined(invoker.public_deps)) {
+            public_deps += invoker.public_deps
+          }
 
-        args = [
-          "install",
+          args = [
+            "install",
 
-          # This speeds up pip installs. At this point in the gn build the
-          # virtualenv is already activated so build isolation isn't required.
-          # This requires that pip, setuptools, and wheel packages are
-          # installed.
-          "--no-build-isolation",
-        ]
-
-        inputs = pw_build_PIP_CONSTRAINTS
-        foreach(_constraints_file, pw_build_PIP_CONSTRAINTS) {
-          args += [
-            "--constraint",
-            rebase_path(_constraints_file, root_build_dir),
+            # This speeds up pip installs. At this point in the gn build the
+            # virtualenv is already activated so build isolation isn't required.
+            # This requires that pip, setuptools, and wheel packages are
+            # installed.
+            "--no-build-isolation",
           ]
+
+          inputs = pw_build_PIP_CONSTRAINTS
+          foreach(_constraints_file, pw_build_PIP_CONSTRAINTS) {
+            args += [
+              "--constraint",
+              rebase_path(_constraints_file, root_build_dir),
+            ]
+          }
+
+          # For generated packages, reinstall when any files change. For regular
+          # packages, only reinstall when setup.py changes.
+          if (_generate_package) {
+            public_deps += [ ":${invoker.target_name}" ]
+          } else {
+            inputs += invoker.setup
+
+            # Install with --editable since the complete package is in source.
+            args += [ "--editable" ]
+          }
+
+          args += [ rebase_path(_setup_dir, root_build_dir) ]
+
+          stamp = true
+
+          # Parallel pip installations don't work, so serialize pip invocations.
+          pool = "$dir_pw_build/pool:pip($default_toolchain)"
+
+          foreach(dep, _python_deps) {
+            # We need to add a suffix to the target name, but the label is
+            # formatted as "//path/to:target(toolchain)", so we can't just append
+            # ".subtarget". Instead, we replace the opening parenthesis of the
+            # toolchain with ".suffix(".
+            public_deps += [ string_replace(dep, "(", "._run_pip_install(") ]
+          }
         }
-
-        # For generated packages, reinstall when any files change. For regular
-        # packages, only reinstall when setup.py changes.
-        if (_generate_package) {
-          public_deps += [ ":${invoker.target_name}" ]
-        } else {
-          inputs += invoker.setup
-
-          # Install with --editable since the complete package is in source.
-          args += [ "--editable" ]
-        }
-
-        args += [ rebase_path(_setup_dir, root_build_dir) ]
-
-        stamp = true
-
-        # Parallel pip installations don't work, so serialize pip invocations.
-        pool = "$dir_pw_build/pool:pip($default_toolchain)"
-
-        foreach(dep, _python_deps) {
-          # We need to add a suffix to the target name, but the label is
-          # formatted as "//path/to:target(toolchain)", so we can't just append
-          # ".subtarget". Instead, we replace the opening parenthesis of the
-          # toolchain with ".suffix(".
-          public_deps += [ string_replace(dep, "(", "._run_pip_install(") ]
+      } else {
+        # Stubs for non-package targets.
+        group("$target_name._run_pip_install") {
         }
       }
 
diff --git a/pw_build/python_action.gni b/pw_build/python_action.gni
index 4029daf..b6d9fab 100644
--- a/pw_build/python_action.gni
+++ b/pw_build/python_action.gni
@@ -259,6 +259,9 @@
     _install_venv_3p_deps = false
   }
 
+  # If pw_build_USE_NEW_PYTHON_BUILD is false this variable is not needed.
+  not_needed([ "_install_venv_3p_deps" ])
+
   # Check that script or module is a present and not a no-op.
   _run_script_or_module = false
   if (defined(invoker.script) || defined(invoker.module)) {
@@ -280,8 +283,11 @@
     inputs = _inputs
     outputs = _outputs
     deps = _deps
-    if (_install_venv_3p_deps && _run_script_or_module) {
-      deps += [ "$dir_pw_env_setup:install_3p_deps($default_toolchain)" ]
+
+    if (pw_build_USE_NEW_PYTHON_BUILD) {
+      if (_install_venv_3p_deps && _run_script_or_module) {
+        deps += [ "$dir_pw_env_setup:install_3p_deps($default_toolchain)" ]
+      }
     }
   }
 }