From b612e48a606f0bd8ac6d6ffc8bc415040a7b101d Mon Sep 17 00:00:00 2001 From: ElijahAhianyo Date: Thu, 2 May 2024 08:53:14 +0000 Subject: [PATCH 1/9] CPU Info and Telemetry --- reflex/constants/__init__.py | 2 -- reflex/constants/base.py | 5 ---- reflex/utils/prerequisites.py | 54 +++++++++++++++++++++++++++++++++-- reflex/utils/telemetry.py | 5 +++- 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/reflex/constants/__init__.py b/reflex/constants/__init__.py index c5d3586cea..1f3325a8a3 100644 --- a/reflex/constants/__init__.py +++ b/reflex/constants/__init__.py @@ -4,7 +4,6 @@ COOKIES, ENV_MODE_ENV_VAR, IS_WINDOWS, - IS_WINDOWS_BUN_SUPPORTED_MACHINE, # type: ignore LOCAL_STORAGE, POLLING_MAX_HTTP_BUFFER_SIZE, PYTEST_CURRENT_TEST, @@ -87,7 +86,6 @@ Hooks, Imports, IS_WINDOWS, - IS_WINDOWS_BUN_SUPPORTED_MACHINE, LOCAL_STORAGE, LogLevel, MemoizationDisposition, diff --git a/reflex/constants/base.py b/reflex/constants/base.py index 820147ed2f..733859ad4b 100644 --- a/reflex/constants/base.py +++ b/reflex/constants/base.py @@ -11,11 +11,6 @@ from platformdirs import PlatformDirs IS_WINDOWS = platform.system() == "Windows" -# https://github.com/oven-sh/bun/blob/main/src/cli/install.ps1 -IS_WINDOWS_BUN_SUPPORTED_MACHINE = IS_WINDOWS and platform.machine() in [ - "AMD64", - "x86_64", -] # filter out 32 bit + ARM class Dirs(SimpleNamespace): diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index fb25496d44..0f6146c724 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -2,6 +2,7 @@ from __future__ import annotations +import functools import glob import importlib import inspect @@ -12,6 +13,7 @@ import re import shutil import stat +import subprocess import sys import tempfile import zipfile @@ -172,7 +174,7 @@ def get_install_package_manager() -> str | None: Returns: The path to the package manager. """ - if constants.IS_WINDOWS and not constants.IS_WINDOWS_BUN_SUPPORTED_MACHINE: + if constants.IS_WINDOWS and not is_windows_bun_supported(): return get_package_manager() return get_config().bun_path @@ -728,7 +730,8 @@ def install_bun(): Raises: FileNotFoundError: If required packages are not found. """ - if constants.IS_WINDOWS and not constants.IS_WINDOWS_BUN_SUPPORTED_MACHINE: + print(get_cpu_info()) + if constants.IS_WINDOWS and not is_windows_bun_supported(): console.warn( "Bun for Windows is currently only available for x86 64-bit Windows. Installation will fall back on npm." ) @@ -826,7 +829,7 @@ def install_frontend_packages(packages: set[str], config: Config): get_package_manager() if not constants.IS_WINDOWS or constants.IS_WINDOWS - and constants.IS_WINDOWS_BUN_SUPPORTED_MACHINE + and is_windows_bun_supported() else None ) processes.run_process_with_fallback( @@ -1411,3 +1414,48 @@ def initialize_app(app_name: str, template: str | None = None): ) telemetry.send("init", template=template) + + +def execute_command(command): + return subprocess.check_output(command, shell=True).decode() + + +@functools.lru_cache(maxsize=None) +def get_cpu_info(): + platform_os = platform.system() + if platform_os == "Windows": + + cmd = 'wmic cpu get caption,addresswidth, manufacturer' + output = subprocess.check_output(cmd, shell=True).decode() + return [y for y in output.splitlines() if y][1] + # return [x for x in [y for y in output.splitlines() if y][1].split(" ") if x] + elif platform_os == "Linux": + cpu_list = [] + output = subprocess.check_output(["lscpu"], shell=True).decode() + lines = output.split('\n') + for line in lines: + if "Architecture" in line: + cpu_list.append(line.split(':')[1].strip()) + if "Vendor ID:" in line: + cpu_list.append(line.split(':')[1].strip()) + cpu_list.append(platform.uname().release) + return " ".join(cpu_list) + elif platform_os == "Darwin": + cpu_bit = execute_command("getconf LONG_BIT") + manufacturer_id = execute_command("sysctl -n machdep.cpu.brand_string") + architecture = execute_command("uname -m") + + return f"{cpu_bit} {architecture} {manufacturer_id}" + + + + + return platform.platform() + + +@functools.lru_cache(maxsize=None) +def is_windows_bun_supported(): + cpu_info_list = [x for x in get_cpu_info().split(" ") if x] + return constants.IS_WINDOWS and cpu_info_list[0] == 64 and not "ARM" in cpu_info_list[1] + + diff --git a/reflex/utils/telemetry.py b/reflex/utils/telemetry.py index fc56ca3ece..9e29023552 100644 --- a/reflex/utils/telemetry.py +++ b/reflex/utils/telemetry.py @@ -29,7 +29,7 @@ def get_os() -> str: Returns: The operating system. """ - return platform.system() + return platform.platform() def get_python_version() -> str: @@ -97,6 +97,7 @@ def _prepare_event(event: str, **kwargs) -> dict: Returns: The event data. """ + from reflex.utils.prerequisites import get_cpu_info installation_id = ensure_reflex_installation_id() project_hash = get_project_hash(raise_on_fail=_raise_on_missing_project_hash()) @@ -123,6 +124,7 @@ def _prepare_event(event: str, **kwargs) -> dict: "python_version": get_python_version(), "cpu_count": get_cpu_count(), "memory": get_memory(), + "cpu_architecture": get_cpu_info(), **( {"template": template} if (template := kwargs.get("template")) is not None @@ -163,6 +165,7 @@ def send(event: str, telemetry_enabled: bool | None = None, **kwargs) -> bool: return False event_data = _prepare_event(event, **kwargs) + print(f"Event data: {event_data}") if not event_data: return False From c453fb1aa186517322236754f9193ed24a32b002 Mon Sep 17 00:00:00 2001 From: Elijah Date: Thu, 2 May 2024 10:52:17 +0000 Subject: [PATCH 2/9] refactor --- reflex/utils/prerequisites.py | 89 +++++++++++++++++++++++------------ reflex/utils/processes.py | 12 +++++ reflex/utils/telemetry.py | 7 +-- 3 files changed, 74 insertions(+), 34 deletions(-) diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index 0f6146c724..ec45d92f23 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -13,7 +13,6 @@ import re import shutil import stat -import subprocess import sys import tempfile import zipfile @@ -51,6 +50,14 @@ class Template(Base): demo_url: str +class CpuInfo(Base): + """Model to save cpu info.""" + + manufacturer_id: str + model_name: str + address_width: int + + def check_latest_package_version(package_name: str): """Check if the latest version of the package is installed. @@ -1416,46 +1423,66 @@ def initialize_app(app_name: str, template: str | None = None): telemetry.send("init", template=template) -def execute_command(command): - return subprocess.check_output(command, shell=True).decode() - - @functools.lru_cache(maxsize=None) -def get_cpu_info(): +def get_cpu_info() -> CpuInfo | None: + """Get the CPU info of the underlining host. + + Returns: + The CPU info. + """ platform_os = platform.system() + cpuinfo= {} if platform_os == "Windows": - - cmd = 'wmic cpu get caption,addresswidth, manufacturer' - output = subprocess.check_output(cmd, shell=True).decode() - return [y for y in output.splitlines() if y][1] - # return [x for x in [y for y in output.splitlines() if y][1].split(" ") if x] + cmd = "wmic cpu get caption,addresswidth, manufacturer" + output = processes.execute_command_and_return_output(cmd) + val = [x for x in [y for y in output.splitlines() if y][1].split(" ") if x] + cpuinfo["manufacturer_id"] = val[2] + cpuinfo["model_name"] = val[1] + cpuinfo["address_width"] = int(val[0]) elif platform_os == "Linux": - cpu_list = [] - output = subprocess.check_output(["lscpu"], shell=True).decode() - lines = output.split('\n') + output = processes.execute_command_and_return_output("lscpu") + lines = output.split("\n") for line in lines: if "Architecture" in line: - cpu_list.append(line.split(':')[1].strip()) + cpuinfo["address_width"] = ( + 64 if line.split(":")[1].strip() == "x86_64" else 32 + ) if "Vendor ID:" in line: - cpu_list.append(line.split(':')[1].strip()) - cpu_list.append(platform.uname().release) - return " ".join(cpu_list) + cpuinfo["manufacturer_id"] = line.split(":")[1].strip() + if "Model name" in line: + cpuinfo["model_name"] = line.split(":")[1].strip() elif platform_os == "Darwin": - cpu_bit = execute_command("getconf LONG_BIT") - manufacturer_id = execute_command("sysctl -n machdep.cpu.brand_string") - architecture = execute_command("uname -m") - - return f"{cpu_bit} {architecture} {manufacturer_id}" - - - + cpuinfo["address_width"] = int( + processes.execute_command_and_return_output("getconf LONG_BIT") + ) + cpuinfo["manufacturer_id"] = processes.execute_command_and_return_output( + "sysctl -n machdep.cpu.brand_string" + ) + cpuinfo["model_name"] = processes.execute_command_and_return_output("uname -m") - return platform.platform() + return ( + CpuInfo( + manufacturer_id=cpuinfo.get("manufacturer_id"), # type: ignore + model_name=cpuinfo.get("model_name"), # type: ignore + address_width=cpuinfo.get("address_width"), # type: ignore + ) + if cpuinfo + else None + ) @functools.lru_cache(maxsize=None) -def is_windows_bun_supported(): - cpu_info_list = [x for x in get_cpu_info().split(" ") if x] - return constants.IS_WINDOWS and cpu_info_list[0] == 64 and not "ARM" in cpu_info_list[1] - +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. + Returns: + Whether the host is qualified to use bun. + """ + cpu_info = get_cpu_info() + return ( + constants.IS_WINDOWS + and cpu_info is not None + and cpu_info.address_width == 64 + and "ARM" not in cpu_info.model_name + ) diff --git a/reflex/utils/processes.py b/reflex/utils/processes.py index dfe3f5cc63..e60380af1b 100644 --- a/reflex/utils/processes.py +++ b/reflex/utils/processes.py @@ -347,3 +347,15 @@ def run_process_with_fallback(args, *, show_status_message, fallback=None, **kwa fallback=None, **kwargs, ) + + +def execute_command_and_return_output(command): + """Execute a command and return the output. + + Args: + command: The command to run. + + Returns: + The output of the command. + """ + return subprocess.check_output(command, shell=True).decode().strip() diff --git a/reflex/utils/telemetry.py b/reflex/utils/telemetry.py index 9e29023552..4cdc6a34f3 100644 --- a/reflex/utils/telemetry.py +++ b/reflex/utils/telemetry.py @@ -98,6 +98,7 @@ def _prepare_event(event: str, **kwargs) -> dict: The event data. """ from reflex.utils.prerequisites import get_cpu_info + installation_id = ensure_reflex_installation_id() project_hash = get_project_hash(raise_on_fail=_raise_on_missing_project_hash()) @@ -124,7 +125,7 @@ def _prepare_event(event: str, **kwargs) -> dict: "python_version": get_python_version(), "cpu_count": get_cpu_count(), "memory": get_memory(), - "cpu_architecture": get_cpu_info(), + "cpu_info": dict(get_cpu_info()) if get_cpu_info() else {}, **( {"template": template} if (template := kwargs.get("template")) is not None @@ -168,5 +169,5 @@ def send(event: str, telemetry_enabled: bool | None = None, **kwargs) -> bool: print(f"Event data: {event_data}") if not event_data: return False - - return _send_event(event_data) + return True + # return _send_event(event_data) From dc61a8d0f577be3811e76b1fa1fd657640cdc0ec Mon Sep 17 00:00:00 2001 From: ElijahAhianyo Date: Thu, 2 May 2024 11:47:36 +0000 Subject: [PATCH 3/9] windows model name fix --- reflex/utils/prerequisites.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index ec45d92f23..579c3d1a8e 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -1433,11 +1433,11 @@ def get_cpu_info() -> CpuInfo | None: platform_os = platform.system() cpuinfo= {} if platform_os == "Windows": - cmd = "wmic cpu get caption,addresswidth, manufacturer" + cmd = "wmic cpu get addresswidth,caption,manufacturer /FORMAT:csv" output = processes.execute_command_and_return_output(cmd) - val = [x for x in [y for y in output.splitlines() if y][1].split(" ") if x] + val = output.splitlines()[-1].split(",")[1:] cpuinfo["manufacturer_id"] = val[2] - cpuinfo["model_name"] = val[1] + cpuinfo["model_name"] = val[1].split("Family")[0].strip() cpuinfo["address_width"] = int(val[0]) elif platform_os == "Linux": output = processes.execute_command_and_return_output("lscpu") From bef267e7702d95b4794615b1ac04f07017eec886 Mon Sep 17 00:00:00 2001 From: Elijah Date: Thu, 2 May 2024 12:44:03 +0000 Subject: [PATCH 4/9] fix tests --- reflex/utils/prerequisites.py | 2 +- reflex/utils/telemetry.py | 14 +++++++++++--- tests/test_telemetry.py | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index 579c3d1a8e..5adcb70c77 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -1431,7 +1431,7 @@ def get_cpu_info() -> CpuInfo | None: The CPU info. """ platform_os = platform.system() - cpuinfo= {} + cpuinfo = {} if platform_os == "Windows": cmd = "wmic cpu get addresswidth,caption,manufacturer /FORMAT:csv" output = processes.execute_command_and_return_output(cmd) diff --git a/reflex/utils/telemetry.py b/reflex/utils/telemetry.py index 4cdc6a34f3..5efb65eee1 100644 --- a/reflex/utils/telemetry.py +++ b/reflex/utils/telemetry.py @@ -29,6 +29,15 @@ def get_os() -> str: Returns: The operating system. """ + return platform.system() + + +def get_detailed_platform_str() -> str: + """Get the detailed os/platform string. + + Returns: + The platform string + """ return platform.platform() @@ -121,6 +130,7 @@ def _prepare_event(event: str, **kwargs) -> dict: "distinct_id": installation_id, "distinct_app_id": project_hash, "user_os": get_os(), + "user_os_detail": get_detailed_platform_str(), "reflex_version": get_reflex_version(), "python_version": get_python_version(), "cpu_count": get_cpu_count(), @@ -166,8 +176,6 @@ def send(event: str, telemetry_enabled: bool | None = None, **kwargs) -> bool: return False event_data = _prepare_event(event, **kwargs) - print(f"Event data: {event_data}") if not event_data: return False - return True - # return _send_event(event_data) + return _send_event(event_data) diff --git a/tests/test_telemetry.py b/tests/test_telemetry.py index 2cbbe0ee8c..58786c67be 100644 --- a/tests/test_telemetry.py +++ b/tests/test_telemetry.py @@ -41,6 +41,7 @@ def test_send(mocker, event): read_data='{"project_hash": "78285505863498957834586115958872998605"}' ), ) + mocker.patch("platform.platform", return_value="Mocked Platform") telemetry.send(event, telemetry_enabled=True) httpx.post.assert_called_once() From 130a526a171f56659c0804850f5b147545befcf3 Mon Sep 17 00:00:00 2001 From: Elijah Date: Thu, 2 May 2024 12:51:37 +0000 Subject: [PATCH 5/9] precommit fix --- reflex/utils/telemetry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reflex/utils/telemetry.py b/reflex/utils/telemetry.py index 5efb65eee1..1014bc39a5 100644 --- a/reflex/utils/telemetry.py +++ b/reflex/utils/telemetry.py @@ -135,7 +135,7 @@ def _prepare_event(event: str, **kwargs) -> dict: "python_version": get_python_version(), "cpu_count": get_cpu_count(), "memory": get_memory(), - "cpu_info": dict(get_cpu_info()) if get_cpu_info() else {}, + "cpu_info": dict(get_cpu_info()) if get_cpu_info() else {}, # type: ignore **( {"template": template} if (template := kwargs.get("template")) is not None From d12cc6ad2b798f270512db5f2826fbbe83165b4f Mon Sep 17 00:00:00 2001 From: Elijah Date: Thu, 2 May 2024 12:56:31 +0000 Subject: [PATCH 6/9] remove debug statement --- reflex/utils/prerequisites.py | 1 - 1 file changed, 1 deletion(-) diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index 5adcb70c77..319e5f7ec7 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -737,7 +737,6 @@ def install_bun(): Raises: FileNotFoundError: If required packages are not found. """ - print(get_cpu_info()) if constants.IS_WINDOWS and not is_windows_bun_supported(): console.warn( "Bun for Windows is currently only available for x86 64-bit Windows. Installation will fall back on npm." From 84a18e96770d3b57922435d9a5331bb8aaeeaf7f Mon Sep 17 00:00:00 2001 From: Elijah Date: Thu, 2 May 2024 13:08:25 +0000 Subject: [PATCH 7/9] add test --- tests/test_prerequisites.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_prerequisites.py b/tests/test_prerequisites.py index 28608c48c1..c4f57a9984 100644 --- a/tests/test_prerequisites.py +++ b/tests/test_prerequisites.py @@ -8,8 +8,10 @@ from reflex import constants from reflex.config import Config from reflex.utils.prerequisites import ( + CpuInfo, _update_next_config, cached_procedure, + get_cpu_info, initialize_requirements_txt, ) @@ -203,3 +205,14 @@ def _function_with_some_args(*args, **kwargs): assert call_count == 2 _function_with_some_args(100, y=300) assert call_count == 2 + + +def test_get_cpu_info(): + cpu_info = get_cpu_info() + assert cpu_info is not None + assert isinstance(cpu_info, CpuInfo) + assert cpu_info.model_name is not None + + for attr in ("manufacturer_id", "model_name", "address_width"): + value = getattr(cpu_info, attr) + assert value.strip() if attr != "address_width" else value From 829a6b33ccdb1be946a1d13c5732e5b7f8062a05 Mon Sep 17 00:00:00 2001 From: Elijah Date: Thu, 2 May 2024 13:57:26 +0000 Subject: [PATCH 8/9] add bun logs to system info output for windows --- reflex/utils/exec.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/reflex/utils/exec.py b/reflex/utils/exec.py index 4c6c81b520..097fffd75f 100644 --- a/reflex/utils/exec.py +++ b/reflex/utils/exec.py @@ -271,7 +271,11 @@ def output_system_info(): system = platform.system() - if system != "Windows": + if ( + system != "Windows" + or system == "Windows" + and prerequisites.is_windows_bun_supported() + ): dependencies.extend( [ f"[FNM {prerequisites.get_fnm_version()} (Expected: {constants.Fnm.VERSION}) (PATH: {constants.Fnm.EXE})]", From 9fb55f396121f2893517c8f11357c4f8451630d0 Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 3 May 2024 12:51:00 +0000 Subject: [PATCH 9/9] Handle exceptions --- reflex/utils/prerequisites.py | 90 ++++++++++++++++++++++------------- reflex/utils/processes.py | 10 +++- reflex/utils/telemetry.py | 5 +- 3 files changed, 69 insertions(+), 36 deletions(-) diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index 319e5f7ec7..0bbdaedf71 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -53,9 +53,9 @@ class Template(Base): class CpuInfo(Base): """Model to save cpu info.""" - manufacturer_id: str - model_name: str - address_width: int + manufacturer_id: Optional[str] + model_name: Optional[str] + address_width: Optional[int] def check_latest_package_version(package_name: str): @@ -1422,6 +1422,21 @@ def initialize_app(app_name: str, template: str | None = None): telemetry.send("init", template=template) +def format_address_width(address_width) -> int | None: + """Cast address width to an int. + + Args: + address_width: The address width. + + Returns: + Address width int + """ + try: + return int(address_width) if address_width else None + except ValueError: + return None + + @functools.lru_cache(maxsize=None) def get_cpu_info() -> CpuInfo | None: """Get the CPU info of the underlining host. @@ -1431,39 +1446,47 @@ def get_cpu_info() -> CpuInfo | None: """ platform_os = platform.system() cpuinfo = {} - if platform_os == "Windows": - cmd = "wmic cpu get addresswidth,caption,manufacturer /FORMAT:csv" - output = processes.execute_command_and_return_output(cmd) - val = output.splitlines()[-1].split(",")[1:] - cpuinfo["manufacturer_id"] = val[2] - cpuinfo["model_name"] = val[1].split("Family")[0].strip() - cpuinfo["address_width"] = int(val[0]) - elif platform_os == "Linux": - output = processes.execute_command_and_return_output("lscpu") - lines = output.split("\n") - for line in lines: - if "Architecture" in line: - cpuinfo["address_width"] = ( - 64 if line.split(":")[1].strip() == "x86_64" else 32 - ) - if "Vendor ID:" in line: - cpuinfo["manufacturer_id"] = line.split(":")[1].strip() - if "Model name" in line: - cpuinfo["model_name"] = line.split(":")[1].strip() - elif platform_os == "Darwin": - cpuinfo["address_width"] = int( - processes.execute_command_and_return_output("getconf LONG_BIT") - ) - cpuinfo["manufacturer_id"] = processes.execute_command_and_return_output( - "sysctl -n machdep.cpu.brand_string" - ) - cpuinfo["model_name"] = processes.execute_command_and_return_output("uname -m") + try: + if platform_os == "Windows": + cmd = "wmic cpu get addresswidth,caption,manufacturer /FORMAT:csv" + 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]) + elif platform_os == "Linux": + output = processes.execute_command_and_return_output("lscpu") + if output: + lines = output.split("\n") + for line in lines: + if "Architecture" in line: + cpuinfo["address_width"] = ( + 64 if line.split(":")[1].strip() == "x86_64" else 32 + ) + if "Vendor ID:" in line: + cpuinfo["manufacturer_id"] = line.split(":")[1].strip() + if "Model name" in line: + cpuinfo["model_name"] = line.split(":")[1].strip() + elif platform_os == "Darwin": + cpuinfo["address_width"] = format_address_width( + processes.execute_command_and_return_output("getconf LONG_BIT") + ) + cpuinfo["manufacturer_id"] = processes.execute_command_and_return_output( + "sysctl -n machdep.cpu.brand_string" + ) + cpuinfo["model_name"] = processes.execute_command_and_return_output( + "uname -m" + ) + except Exception as err: + console.error(f"Failed to retrieve CPU info. {err}") + return None return ( CpuInfo( - manufacturer_id=cpuinfo.get("manufacturer_id"), # type: ignore - model_name=cpuinfo.get("model_name"), # type: ignore - address_width=cpuinfo.get("address_width"), # type: ignore + manufacturer_id=cpuinfo.get("manufacturer_id"), + model_name=cpuinfo.get("model_name"), + address_width=cpuinfo.get("address_width"), ) if cpuinfo else None @@ -1483,5 +1506,6 @@ def is_windows_bun_supported() -> bool: 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 ) diff --git a/reflex/utils/processes.py b/reflex/utils/processes.py index e60380af1b..f63e1c709a 100644 --- a/reflex/utils/processes.py +++ b/reflex/utils/processes.py @@ -349,7 +349,7 @@ def run_process_with_fallback(args, *, show_status_message, fallback=None, **kwa ) -def execute_command_and_return_output(command): +def execute_command_and_return_output(command) -> str | None: """Execute a command and return the output. Args: @@ -358,4 +358,10 @@ def execute_command_and_return_output(command): Returns: The output of the command. """ - return subprocess.check_output(command, shell=True).decode().strip() + try: + return subprocess.check_output(command, shell=True).decode().strip() + except subprocess.SubprocessError as err: + console.error( + f"The command `{command}` failed with error: {err}. This will return None." + ) + return None diff --git a/reflex/utils/telemetry.py b/reflex/utils/telemetry.py index 1014bc39a5..e38c4fe793 100644 --- a/reflex/utils/telemetry.py +++ b/reflex/utils/telemetry.py @@ -123,6 +123,9 @@ def _prepare_event(event: str, **kwargs) -> dict: else: # for python 3.11 & 3.12 stamp = datetime.now(UTC).isoformat() + + cpuinfo = get_cpu_info() + return { "api_key": "phc_JoMo0fOyi0GQAooY3UyO9k0hebGkMyFJrrCw1Gt5SGb", "event": event, @@ -135,7 +138,7 @@ def _prepare_event(event: str, **kwargs) -> dict: "python_version": get_python_version(), "cpu_count": get_cpu_count(), "memory": get_memory(), - "cpu_info": dict(get_cpu_info()) if get_cpu_info() else {}, # type: ignore + "cpu_info": dict(cpuinfo) if cpuinfo else {}, **( {"template": template} if (template := kwargs.get("template")) is not None