Compare commits
2 Commits
main
...
masenf/win
Author | SHA1 | Date | |
---|---|---|---|
![]() |
af7af376d0 | ||
![]() |
ef457afe11 |
@ -26,6 +26,8 @@ class Ext(SimpleNamespace):
|
|||||||
CSS = ".css"
|
CSS = ".css"
|
||||||
# The extension for zip files.
|
# The extension for zip files.
|
||||||
ZIP = ".zip"
|
ZIP = ".zip"
|
||||||
|
# The extension for executable files on Windows.
|
||||||
|
EXE = ".exe"
|
||||||
|
|
||||||
|
|
||||||
class CompileVars(SimpleNamespace):
|
class CompileVars(SimpleNamespace):
|
||||||
|
@ -27,6 +27,15 @@ def set_log_level(log_level: LogLevel):
|
|||||||
_LOG_LEVEL = log_level
|
_LOG_LEVEL = log_level
|
||||||
|
|
||||||
|
|
||||||
|
def is_debug() -> bool:
|
||||||
|
"""Check if the log level is debug.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True if the log level is debug.
|
||||||
|
"""
|
||||||
|
return _LOG_LEVEL <= LogLevel.DEBUG
|
||||||
|
|
||||||
|
|
||||||
def print(msg: str, **kwargs):
|
def print(msg: str, **kwargs):
|
||||||
"""Print a message.
|
"""Print a message.
|
||||||
|
|
||||||
@ -44,7 +53,7 @@ def debug(msg: str, **kwargs):
|
|||||||
msg: The debug message.
|
msg: The debug message.
|
||||||
kwargs: Keyword arguments to pass to the print function.
|
kwargs: Keyword arguments to pass to the print function.
|
||||||
"""
|
"""
|
||||||
if _LOG_LEVEL <= LogLevel.DEBUG:
|
if is_debug():
|
||||||
msg_ = f"[blue]Debug: {msg}[/blue]"
|
msg_ = f"[blue]Debug: {msg}[/blue]"
|
||||||
if progress := kwargs.pop("progress", None):
|
if progress := kwargs.pop("progress", None):
|
||||||
progress.console.print(msg_, **kwargs)
|
progress.console.print(msg_, **kwargs)
|
||||||
|
@ -34,6 +34,8 @@ from reflex.compiler import templates
|
|||||||
from reflex.config import Config, get_config
|
from reflex.config import Config, get_config
|
||||||
from reflex.utils import console, path_ops, processes
|
from reflex.utils import console, path_ops, processes
|
||||||
|
|
||||||
|
CURRENTLY_INSTALLING_NODE = False
|
||||||
|
|
||||||
|
|
||||||
def check_latest_package_version(package_name: str):
|
def check_latest_package_version(package_name: str):
|
||||||
"""Check if the latest version of the package is installed.
|
"""Check if the latest version of the package is installed.
|
||||||
@ -103,8 +105,11 @@ def get_node_version() -> version.Version | None:
|
|||||||
Returns:
|
Returns:
|
||||||
The version of node.
|
The version of node.
|
||||||
"""
|
"""
|
||||||
|
node_path = path_ops.get_node_path()
|
||||||
|
if node_path is None:
|
||||||
|
return None
|
||||||
try:
|
try:
|
||||||
result = processes.new_process([path_ops.get_node_path(), "-v"], run=True)
|
result = processes.new_process([node_path, "-v"], run=True)
|
||||||
# The output will be in the form "vX.Y.Z", but version.parse() can handle it
|
# The output will be in the form "vX.Y.Z", but version.parse() can handle it
|
||||||
return version.parse(result.stdout) # type: ignore
|
return version.parse(result.stdout) # type: ignore
|
||||||
except (FileNotFoundError, TypeError):
|
except (FileNotFoundError, TypeError):
|
||||||
@ -140,16 +145,13 @@ def get_bun_version() -> version.Version | None:
|
|||||||
|
|
||||||
def get_install_package_manager() -> str | None:
|
def get_install_package_manager() -> str | None:
|
||||||
"""Get the package manager executable for installation.
|
"""Get the package manager executable for installation.
|
||||||
Currently on unix systems, bun is used for installation only.
|
Currently, bun is used for installation only.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The path to the package manager.
|
The path to the package manager.
|
||||||
"""
|
"""
|
||||||
# On Windows, we use npm instead of bun.
|
|
||||||
if constants.IS_WINDOWS:
|
if constants.IS_WINDOWS:
|
||||||
return get_package_manager()
|
return get_config().bun_path + constants.Ext.EXE
|
||||||
|
|
||||||
# On other platforms, we use bun.
|
|
||||||
return get_config().bun_path
|
return get_config().bun_path
|
||||||
|
|
||||||
|
|
||||||
@ -606,6 +608,11 @@ def install_node():
|
|||||||
console.debug("")
|
console.debug("")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Skip installation if check_node_version() checks out
|
||||||
|
if check_node_version():
|
||||||
|
console.debug("Skipping node installation as it is already installed.")
|
||||||
|
return
|
||||||
|
|
||||||
path_ops.mkdir(constants.Fnm.DIR)
|
path_ops.mkdir(constants.Fnm.DIR)
|
||||||
if not os.path.exists(constants.Fnm.EXE):
|
if not os.path.exists(constants.Fnm.EXE):
|
||||||
download_and_extract_fnm_zip()
|
download_and_extract_fnm_zip()
|
||||||
@ -622,10 +629,6 @@ def install_node():
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
else: # All other platforms (Linux, MacOS).
|
else: # All other platforms (Linux, MacOS).
|
||||||
# TODO we can skip installation if check_node_version() checks out
|
|
||||||
if check_node_version():
|
|
||||||
console.debug("Skipping node installation as it is already installed.")
|
|
||||||
return
|
|
||||||
# Add execute permissions to fnm executable.
|
# Add execute permissions to fnm executable.
|
||||||
os.chmod(constants.Fnm.EXE, stat.S_IXUSR)
|
os.chmod(constants.Fnm.EXE, stat.S_IXUSR)
|
||||||
# Install node.
|
# Install node.
|
||||||
@ -655,11 +658,6 @@ def install_bun():
|
|||||||
Raises:
|
Raises:
|
||||||
FileNotFoundError: If required packages are not found.
|
FileNotFoundError: If required packages are not found.
|
||||||
"""
|
"""
|
||||||
# Bun is not supported on Windows.
|
|
||||||
if constants.IS_WINDOWS:
|
|
||||||
console.debug("Skipping bun installation on Windows.")
|
|
||||||
return
|
|
||||||
|
|
||||||
# Skip if bun is already installed.
|
# Skip if bun is already installed.
|
||||||
if os.path.exists(get_config().bun_path) and get_bun_version() == version.parse(
|
if os.path.exists(get_config().bun_path) and get_bun_version() == version.parse(
|
||||||
constants.Bun.VERSION
|
constants.Bun.VERSION
|
||||||
@ -668,16 +666,25 @@ def install_bun():
|
|||||||
return
|
return
|
||||||
|
|
||||||
# if unzip is installed
|
# if unzip is installed
|
||||||
unzip_path = path_ops.which("unzip")
|
if constants.IS_WINDOWS:
|
||||||
if unzip_path is None:
|
processes.new_process(
|
||||||
raise FileNotFoundError("Reflex requires unzip to be installed.")
|
["powershell", "-c", f"irm {constants.Bun.INSTALL_URL}.ps1|iex"],
|
||||||
|
env={"BUN_INSTALL": constants.Bun.ROOT_PATH},
|
||||||
|
shell=True,
|
||||||
|
run=True,
|
||||||
|
show_logs=console.is_debug(),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
unzip_path = path_ops.which("unzip")
|
||||||
|
if unzip_path is None:
|
||||||
|
raise FileNotFoundError("Reflex requires unzip to be installed.")
|
||||||
|
|
||||||
# Run the bun install script.
|
# Run the bun install script.
|
||||||
download_and_run(
|
download_and_run(
|
||||||
constants.Bun.INSTALL_URL,
|
constants.Bun.INSTALL_URL,
|
||||||
f"bun-v{constants.Bun.VERSION}",
|
f"bun-v{constants.Bun.VERSION}",
|
||||||
BUN_INSTALL=constants.Bun.ROOT_PATH,
|
BUN_INSTALL=constants.Bun.ROOT_PATH,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _write_cached_procedure_file(payload: str, cache_file: str):
|
def _write_cached_procedure_file(payload: str, cache_file: str):
|
||||||
@ -874,9 +881,6 @@ def validate_frontend_dependencies(init=True):
|
|||||||
)
|
)
|
||||||
raise typer.Exit(1)
|
raise typer.Exit(1)
|
||||||
|
|
||||||
if constants.IS_WINDOWS:
|
|
||||||
return
|
|
||||||
|
|
||||||
if init:
|
if init:
|
||||||
# we only need bun for package install on `reflex init`.
|
# we only need bun for package install on `reflex init`.
|
||||||
validate_bun()
|
validate_bun()
|
||||||
@ -926,8 +930,12 @@ def initialize_frontend_dependencies():
|
|||||||
"""Initialize all the frontend dependencies."""
|
"""Initialize all the frontend dependencies."""
|
||||||
# validate dependencies before install
|
# validate dependencies before install
|
||||||
validate_frontend_dependencies()
|
validate_frontend_dependencies()
|
||||||
|
# Avoid warning about Node installation while we're trying to install it.
|
||||||
|
global CURRENTLY_INSTALLING_NODE
|
||||||
|
CURRENTLY_INSTALLING_NODE = True
|
||||||
# Install the frontend dependencies.
|
# Install the frontend dependencies.
|
||||||
processes.run_concurrently(install_node, install_bun)
|
processes.run_concurrently(install_node, install_bun)
|
||||||
|
CURRENTLY_INSTALLING_NODE = False
|
||||||
# Set up the web directory.
|
# Set up the web directory.
|
||||||
initialize_web_directory()
|
initialize_web_directory()
|
||||||
|
|
||||||
|
@ -135,13 +135,20 @@ def new_process(args, run: bool = False, show_logs: bool = False, **kwargs):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Execute a child program in a new process.
|
Execute a child program in a new process.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
Exit: When attempting to run a command with a None value.
|
||||||
"""
|
"""
|
||||||
node_bin_path = path_ops.get_node_bin_path()
|
node_bin_path = path_ops.get_node_bin_path()
|
||||||
if not node_bin_path:
|
if not node_bin_path and not prerequisites.CURRENTLY_INSTALLING_NODE:
|
||||||
console.warn(
|
console.warn(
|
||||||
"The path to the Node binary could not be found. Please ensure that Node is properly "
|
"The path to the Node binary could not be found. Please ensure that Node is properly "
|
||||||
"installed and added to your system's PATH environment variable."
|
"installed and added to your system's PATH environment variable or try running "
|
||||||
|
"`reflex init` again."
|
||||||
)
|
)
|
||||||
|
if None in args:
|
||||||
|
console.error(f"Invalid command: {args}")
|
||||||
|
raise typer.Exit(1)
|
||||||
# Add the node bin path to the PATH environment variable.
|
# Add the node bin path to the PATH environment variable.
|
||||||
env = {
|
env = {
|
||||||
**os.environ,
|
**os.environ,
|
||||||
|
Loading…
Reference in New Issue
Block a user