Skip to content

Commit f356e28

Browse files
adhami3310masenf
andauthored
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 <[email protected]> * _retrieve_cpu_info * we forgot to change this guy before --------- Co-authored-by: Masen Furer <[email protected]>
1 parent 30d20af commit f356e28

File tree

2 files changed

+31
-51
lines changed

2 files changed

+31
-51
lines changed

reflex/utils/exec.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -524,17 +524,12 @@ def output_system_info():
524524

525525
fnm_info = f"[FNM {prerequisites.get_fnm_version()} (Expected: {constants.Fnm.VERSION}) (PATH: {constants.Fnm.EXE})]"
526526

527-
if system != "Windows" or (
528-
system == "Windows" and prerequisites.is_windows_bun_supported()
529-
):
530-
dependencies.extend(
531-
[
532-
fnm_info,
533-
f"[Bun {prerequisites.get_bun_version()} (Expected: {constants.Bun.VERSION}) (PATH: {path_ops.get_bun_path()})]",
534-
],
535-
)
536-
else:
537-
dependencies.append(fnm_info)
527+
dependencies.extend(
528+
[
529+
fnm_info,
530+
f"[Bun {prerequisites.get_bun_version()} (Expected: {constants.Bun.VERSION}) (PATH: {path_ops.get_bun_path()})]",
531+
],
532+
)
538533

539534
if system == "Linux":
540535
import distro # pyright: ignore[reportMissingImports]

reflex/utils/prerequisites.py

+25-40
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,7 @@ def get_install_package_manager(on_failure_return_none: bool = False) -> str | N
242242
The path to the package manager.
243243
"""
244244
if constants.IS_WINDOWS and (
245-
not is_windows_bun_supported()
246-
or windows_check_onedrive_in_path()
247-
or windows_npm_escape_hatch()
245+
windows_check_onedrive_in_path() or windows_npm_escape_hatch()
248246
):
249247
return get_package_manager(on_failure_return_none)
250248
return str(get_config().bun_path)
@@ -1064,17 +1062,11 @@ def install_bun():
10641062
Raises:
10651063
SystemPackageMissingError: If "unzip" is missing.
10661064
"""
1067-
win_supported = is_windows_bun_supported()
10681065
one_drive_in_path = windows_check_onedrive_in_path()
1069-
if constants.IS_WINDOWS and (not win_supported or one_drive_in_path):
1070-
if not win_supported:
1071-
console.warn(
1072-
"Bun for Windows is currently only available for x86 64-bit Windows. Installation will fall back on npm."
1073-
)
1074-
if one_drive_in_path:
1075-
console.warn(
1076-
"Creating project directories in OneDrive is not recommended for bun usage on windows. This will fallback to npm."
1077-
)
1066+
if constants.IS_WINDOWS and one_drive_in_path:
1067+
console.warn(
1068+
"Creating project directories in OneDrive is not recommended for bun usage on windows. This will fallback to npm."
1069+
)
10781070

10791071
# Skip if bun is already installed.
10801072
if get_bun_version() == version.parse(constants.Bun.VERSION):
@@ -1176,12 +1168,7 @@ def install_frontend_packages(packages: set[str], config: Config):
11761168
get_package_manager(on_failure_return_none=True)
11771169
if (
11781170
not constants.IS_WINDOWS
1179-
or (
1180-
constants.IS_WINDOWS
1181-
and (
1182-
is_windows_bun_supported() and not windows_check_onedrive_in_path()
1183-
)
1184-
)
1171+
or (constants.IS_WINDOWS and not windows_check_onedrive_in_path())
11851172
)
11861173
else None
11871174
)
@@ -1926,24 +1913,23 @@ def format_address_width(address_width: str | None) -> int | None:
19261913
return None
19271914

19281915

1929-
@functools.lru_cache(maxsize=None)
1930-
def get_cpu_info() -> CpuInfo | None:
1931-
"""Get the CPU info of the underlining host.
1916+
def _retrieve_cpu_info() -> CpuInfo | None:
1917+
"""Retrieve the CPU info of the host.
19321918
19331919
Returns:
1934-
The CPU info.
1920+
The CPU info.
19351921
"""
19361922
platform_os = platform.system()
19371923
cpuinfo = {}
19381924
try:
19391925
if platform_os == "Windows":
1940-
cmd = "wmic cpu get addresswidth,caption,manufacturer /FORMAT:csv"
1926+
cmd = 'powershell -Command "Get-CimInstance Win32_Processor | Select-Object -First 1 | Select-Object AddressWidth,Manufacturer,Name | ConvertTo-Json"'
19411927
output = processes.execute_command_and_return_output(cmd)
19421928
if output:
1943-
val = output.splitlines()[-1].split(",")[1:]
1944-
cpuinfo["manufacturer_id"] = val[2]
1945-
cpuinfo["model_name"] = val[1].split("Family")[0].strip()
1946-
cpuinfo["address_width"] = format_address_width(val[0])
1929+
cpu_data = json.loads(output)
1930+
cpuinfo["address_width"] = cpu_data["AddressWidth"]
1931+
cpuinfo["manufacturer_id"] = cpu_data["Manufacturer"]
1932+
cpuinfo["model_name"] = cpu_data["Name"]
19471933
elif platform_os == "Linux":
19481934
output = processes.execute_command_and_return_output("lscpu")
19491935
if output:
@@ -1983,21 +1969,20 @@ def get_cpu_info() -> CpuInfo | None:
19831969

19841970

19851971
@functools.lru_cache(maxsize=None)
1986-
def is_windows_bun_supported() -> bool:
1987-
"""Check whether the underlining host running windows qualifies to run bun.
1988-
We typically do not run bun on ARM or 32 bit devices that use windows.
1972+
def get_cpu_info() -> CpuInfo | None:
1973+
"""Get the CPU info of the underlining host.
19891974
19901975
Returns:
1991-
Whether the host is qualified to use bun.
1976+
The CPU info.
19921977
"""
1993-
cpu_info = get_cpu_info()
1994-
return (
1995-
constants.IS_WINDOWS
1996-
and cpu_info is not None
1997-
and cpu_info.address_width == 64
1998-
and cpu_info.model_name is not None
1999-
and "ARM" not in cpu_info.model_name
2000-
)
1978+
cpu_info_file = environment.REFLEX_DIR.get() / "cpu_info.json"
1979+
if cpu_info_file.exists() and (cpu_info := json.loads(cpu_info_file.read_text())):
1980+
return CpuInfo(**cpu_info)
1981+
cpu_info = _retrieve_cpu_info()
1982+
if cpu_info:
1983+
cpu_info_file.parent.mkdir(parents=True, exist_ok=True)
1984+
cpu_info_file.write_text(json.dumps(dataclasses.asdict(cpu_info)))
1985+
return cpu_info
20011986

20021987

20031988
def is_generation_hash(template: str) -> bool:

0 commit comments

Comments
 (0)