فهرست منبع

opt for powershell as opposed to wmic (#4862)

* opt for powershell as opposed to wmic

* remove that line

* cache cpu info in disk

* format doc

* mkdir of parents

* bun supports windows

* silly me

Co-authored-by: Masen Furer <m_github@0x26.net>

* _retrieve_cpu_info

* we forgot to change this guy before

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
Khaleel Al-Adhami 2 ماه پیش
والد
کامیت
f356e287ca
2فایلهای تغییر یافته به همراه31 افزوده شده و 51 حذف شده
  1. 6 11
      reflex/utils/exec.py
  2. 25 40
      reflex/utils/prerequisites.py

+ 6 - 11
reflex/utils/exec.py

@@ -524,17 +524,12 @@ def output_system_info():
 
     fnm_info = f"[FNM {prerequisites.get_fnm_version()} (Expected: {constants.Fnm.VERSION}) (PATH: {constants.Fnm.EXE})]"
 
-    if system != "Windows" or (
-        system == "Windows" and prerequisites.is_windows_bun_supported()
-    ):
-        dependencies.extend(
-            [
-                fnm_info,
-                f"[Bun {prerequisites.get_bun_version()} (Expected: {constants.Bun.VERSION}) (PATH: {path_ops.get_bun_path()})]",
-            ],
-        )
-    else:
-        dependencies.append(fnm_info)
+    dependencies.extend(
+        [
+            fnm_info,
+            f"[Bun {prerequisites.get_bun_version()} (Expected: {constants.Bun.VERSION}) (PATH: {path_ops.get_bun_path()})]",
+        ],
+    )
 
     if system == "Linux":
         import distro  # pyright: ignore[reportMissingImports]

+ 25 - 40
reflex/utils/prerequisites.py

@@ -242,9 +242,7 @@ def get_install_package_manager(on_failure_return_none: bool = False) -> str | N
         The path to the package manager.
     """
     if constants.IS_WINDOWS and (
-        not is_windows_bun_supported()
-        or windows_check_onedrive_in_path()
-        or windows_npm_escape_hatch()
+        windows_check_onedrive_in_path() or windows_npm_escape_hatch()
     ):
         return get_package_manager(on_failure_return_none)
     return str(get_config().bun_path)
@@ -1064,17 +1062,11 @@ def install_bun():
     Raises:
         SystemPackageMissingError: If "unzip" is missing.
     """
-    win_supported = is_windows_bun_supported()
     one_drive_in_path = windows_check_onedrive_in_path()
-    if constants.IS_WINDOWS and (not win_supported or one_drive_in_path):
-        if not win_supported:
-            console.warn(
-                "Bun for Windows is currently only available for x86 64-bit Windows. Installation will fall back on npm."
-            )
-        if one_drive_in_path:
-            console.warn(
-                "Creating project directories in OneDrive is not recommended for bun usage on windows. This will fallback to npm."
-            )
+    if constants.IS_WINDOWS and one_drive_in_path:
+        console.warn(
+            "Creating project directories in OneDrive is not recommended for bun usage on windows. This will fallback to npm."
+        )
 
     # Skip if bun is already installed.
     if get_bun_version() == version.parse(constants.Bun.VERSION):
@@ -1176,12 +1168,7 @@ def install_frontend_packages(packages: set[str], config: Config):
         get_package_manager(on_failure_return_none=True)
         if (
             not constants.IS_WINDOWS
-            or (
-                constants.IS_WINDOWS
-                and (
-                    is_windows_bun_supported() and not windows_check_onedrive_in_path()
-                )
-            )
+            or (constants.IS_WINDOWS and not windows_check_onedrive_in_path())
         )
         else None
     )
@@ -1926,24 +1913,23 @@ def format_address_width(address_width: str | None) -> int | None:
         return None
 
 
-@functools.lru_cache(maxsize=None)
-def get_cpu_info() -> CpuInfo | None:
-    """Get the CPU info of the underlining host.
+def _retrieve_cpu_info() -> CpuInfo | None:
+    """Retrieve the CPU info of the host.
 
     Returns:
-         The CPU info.
+        The CPU info.
     """
     platform_os = platform.system()
     cpuinfo = {}
     try:
         if platform_os == "Windows":
-            cmd = "wmic cpu get addresswidth,caption,manufacturer /FORMAT:csv"
+            cmd = 'powershell -Command "Get-CimInstance Win32_Processor | Select-Object -First 1 | Select-Object AddressWidth,Manufacturer,Name | ConvertTo-Json"'
             output = processes.execute_command_and_return_output(cmd)
             if output:
-                val = output.splitlines()[-1].split(",")[1:]
-                cpuinfo["manufacturer_id"] = val[2]
-                cpuinfo["model_name"] = val[1].split("Family")[0].strip()
-                cpuinfo["address_width"] = format_address_width(val[0])
+                cpu_data = json.loads(output)
+                cpuinfo["address_width"] = cpu_data["AddressWidth"]
+                cpuinfo["manufacturer_id"] = cpu_data["Manufacturer"]
+                cpuinfo["model_name"] = cpu_data["Name"]
         elif platform_os == "Linux":
             output = processes.execute_command_and_return_output("lscpu")
             if output:
@@ -1983,21 +1969,20 @@ def get_cpu_info() -> CpuInfo | None:
 
 
 @functools.lru_cache(maxsize=None)
-def is_windows_bun_supported() -> bool:
-    """Check whether the underlining host running windows qualifies to run bun.
-    We typically do not run bun on ARM or 32 bit devices that use windows.
+def get_cpu_info() -> CpuInfo | None:
+    """Get the CPU info of the underlining host.
 
     Returns:
-        Whether the host is qualified to use bun.
+        The CPU info.
     """
-    cpu_info = get_cpu_info()
-    return (
-        constants.IS_WINDOWS
-        and cpu_info is not None
-        and cpu_info.address_width == 64
-        and cpu_info.model_name is not None
-        and "ARM" not in cpu_info.model_name
-    )
+    cpu_info_file = environment.REFLEX_DIR.get() / "cpu_info.json"
+    if cpu_info_file.exists() and (cpu_info := json.loads(cpu_info_file.read_text())):
+        return CpuInfo(**cpu_info)
+    cpu_info = _retrieve_cpu_info()
+    if cpu_info:
+        cpu_info_file.parent.mkdir(parents=True, exist_ok=True)
+        cpu_info_file.write_text(json.dumps(dataclasses.asdict(cpu_info)))
+    return cpu_info
 
 
 def is_generation_hash(template: str) -> bool: