Explorar o código

using subprocess on all platform

Fred Lefévère-Laoide hai 1 ano
pai
achega
b4702ac688
Modificáronse 1 ficheiros con 9 adicións e 15 borrados
  1. 9 15
      tools/frontend/bundle_build.py

+ 9 - 15
tools/frontend/bundle_build.py

@@ -15,6 +15,8 @@ import subprocess
 import sys
 from pathlib import Path
 
+with_shell = platform.system() == "Windows"
+
 
 def build_gui(root_path: Path):
     print(f"Building taipy-gui frontend bundle in {root_path}.")
@@ -22,16 +24,11 @@ def build_gui(root_path: Path):
     if already_exists:
         print(f'Found taipy-gui frontend bundle in {root_path  / "taipy" / "gui" / "webapp"}.')
     else:
-        if platform.system() == "Windows":
-            subprocess.run(["npm", "ci"], cwd=root_path / "frontend" / "taipy-gui" / "dom", check=True, shell=True)
-            subprocess.run(
-                ["npm", "ci", "--omit=optional"], cwd=root_path / "frontend" / "taipy-gui", check=True, shell=True
-            )
-            subprocess.run(["npm", "run", "build"], cwd=root_path / "frontend" / "taipy-gui", check=True, shell=True)
-        else:
-            # subprocess does not work in GH Action *nix :-(
-            os.system(f'cd {root_path / "frontend" / "taipy-gui" / "dom"}; npm ci')
-            os.system(f'cd {root_path / "frontend" / "taipy-gui"}; npm ci --omit=optional && npm run build')
+        subprocess.run(["npm", "ci"], cwd=root_path / "frontend" / "taipy-gui" / "dom", check=True, shell=with_shell)
+        subprocess.run(
+            ["npm", "ci", "--omit=optional"], cwd=root_path / "frontend" / "taipy-gui", check=True, shell=with_shell
+        )
+        subprocess.run(["npm", "run", "build"], cwd=root_path / "frontend" / "taipy-gui", check=True, shell=with_shell)
 
 
 def build_taipy(root_path: Path):
@@ -45,11 +42,8 @@ def build_taipy(root_path: Path):
         if not env_file_path.exists():
             with open(env_file_path, "w") as env_file:
                 env_file.write(f"TAIPY_GUI_DIR={root_path}\n")
-        if platform.system() == "Windows":
-            subprocess.run(["npm", "ci"], cwd=root_path / "frontend" / "taipy", check=True, shell=True)
-            subprocess.run(["npm", "run", "build"], cwd=root_path / "frontend" / "taipy", check=True, shell=True)
-        else:
-            os.system(f'cd {root_path / "frontend" / "taipy"}; npm ci && npm run build')
+        subprocess.run(["npm", "ci"], cwd=root_path / "frontend" / "taipy", check=True, shell=with_shell)
+        subprocess.run(["npm", "run", "build"], cwd=root_path / "frontend" / "taipy", check=True, shell=with_shell)
 
 
 if __name__ == "__main__":