|
@@ -290,7 +290,7 @@ def get_app(reload: bool = False) -> ModuleType:
|
|
"If this error occurs in a reflex test case, ensure that `get_app` is mocked."
|
|
"If this error occurs in a reflex test case, ensure that `get_app` is mocked."
|
|
)
|
|
)
|
|
module = config.module
|
|
module = config.module
|
|
- sys.path.insert(0, os.getcwd())
|
|
|
|
|
|
+ sys.path.insert(0, str(Path.cwd()))
|
|
app = __import__(module, fromlist=(constants.CompileVars.APP,))
|
|
app = __import__(module, fromlist=(constants.CompileVars.APP,))
|
|
|
|
|
|
if reload:
|
|
if reload:
|
|
@@ -438,9 +438,11 @@ def create_config(app_name: str):
|
|
from reflex.compiler import templates
|
|
from reflex.compiler import templates
|
|
|
|
|
|
config_name = f"{re.sub(r'[^a-zA-Z]', '', app_name).capitalize()}Config"
|
|
config_name = f"{re.sub(r'[^a-zA-Z]', '', app_name).capitalize()}Config"
|
|
- with open(constants.Config.FILE, "w") as f:
|
|
|
|
- console.debug(f"Creating {constants.Config.FILE}")
|
|
|
|
- f.write(templates.RXCONFIG.render(app_name=app_name, config_name=config_name))
|
|
|
|
|
|
+
|
|
|
|
+ console.debug(f"Creating {constants.Config.FILE}")
|
|
|
|
+ constants.Config.FILE.write_text(
|
|
|
|
+ templates.RXCONFIG.render(app_name=app_name, config_name=config_name)
|
|
|
|
+ )
|
|
|
|
|
|
|
|
|
|
def initialize_gitignore(
|
|
def initialize_gitignore(
|
|
@@ -494,14 +496,14 @@ def initialize_requirements_txt():
|
|
console.debug(f"Detected encoding for {fp} as {encoding}.")
|
|
console.debug(f"Detected encoding for {fp} as {encoding}.")
|
|
try:
|
|
try:
|
|
other_requirements_exist = False
|
|
other_requirements_exist = False
|
|
- with open(fp, "r", encoding=encoding) as f:
|
|
|
|
|
|
+ with fp.open("r", encoding=encoding) as f:
|
|
for req in f:
|
|
for req in f:
|
|
# Check if we have a package name that is reflex
|
|
# Check if we have a package name that is reflex
|
|
if re.match(r"^reflex[^a-zA-Z0-9]", req):
|
|
if re.match(r"^reflex[^a-zA-Z0-9]", req):
|
|
console.debug(f"{fp} already has reflex as dependency.")
|
|
console.debug(f"{fp} already has reflex as dependency.")
|
|
return
|
|
return
|
|
other_requirements_exist = True
|
|
other_requirements_exist = True
|
|
- with open(fp, "a", encoding=encoding) as f:
|
|
|
|
|
|
+ with fp.open("a", encoding=encoding) as f:
|
|
preceding_newline = "\n" if other_requirements_exist else ""
|
|
preceding_newline = "\n" if other_requirements_exist else ""
|
|
f.write(
|
|
f.write(
|
|
f"{preceding_newline}{constants.RequirementsTxt.DEFAULTS_STUB}{constants.Reflex.VERSION}\n"
|
|
f"{preceding_newline}{constants.RequirementsTxt.DEFAULTS_STUB}{constants.Reflex.VERSION}\n"
|
|
@@ -732,13 +734,13 @@ def download_and_run(url: str, *args, show_status: bool = False, **env):
|
|
response.raise_for_status()
|
|
response.raise_for_status()
|
|
|
|
|
|
# Save the script to a temporary file.
|
|
# Save the script to a temporary file.
|
|
- script = tempfile.NamedTemporaryFile()
|
|
|
|
- with open(script.name, "w") as f:
|
|
|
|
- f.write(response.text)
|
|
|
|
|
|
+ script = Path(tempfile.NamedTemporaryFile().name)
|
|
|
|
+
|
|
|
|
+ script.write_text(response.text)
|
|
|
|
|
|
# Run the script.
|
|
# Run the script.
|
|
env = {**os.environ, **env}
|
|
env = {**os.environ, **env}
|
|
- process = processes.new_process(["bash", f.name, *args], env=env)
|
|
|
|
|
|
+ process = processes.new_process(["bash", str(script), *args], env=env)
|
|
show = processes.show_status if show_status else processes.show_logs
|
|
show = processes.show_status if show_status else processes.show_logs
|
|
show(f"Installing {url}", process)
|
|
show(f"Installing {url}", process)
|
|
|
|
|
|
@@ -752,14 +754,14 @@ def download_and_extract_fnm_zip():
|
|
# Download the zip file
|
|
# Download the zip file
|
|
url = constants.Fnm.INSTALL_URL
|
|
url = constants.Fnm.INSTALL_URL
|
|
console.debug(f"Downloading {url}")
|
|
console.debug(f"Downloading {url}")
|
|
- fnm_zip_file = constants.Fnm.DIR / f"{constants.Fnm.FILENAME}.zip"
|
|
|
|
|
|
+ fnm_zip_file: Path = constants.Fnm.DIR / f"{constants.Fnm.FILENAME}.zip"
|
|
# Function to download and extract the FNM zip release.
|
|
# Function to download and extract the FNM zip release.
|
|
try:
|
|
try:
|
|
# Download the FNM zip release.
|
|
# Download the FNM zip release.
|
|
# TODO: show progress to improve UX
|
|
# TODO: show progress to improve UX
|
|
response = net.get(url, follow_redirects=True)
|
|
response = net.get(url, follow_redirects=True)
|
|
response.raise_for_status()
|
|
response.raise_for_status()
|
|
- with open(fnm_zip_file, "wb") as output_file:
|
|
|
|
|
|
+ with fnm_zip_file.open("wb") as output_file:
|
|
for chunk in response.iter_bytes():
|
|
for chunk in response.iter_bytes():
|
|
output_file.write(chunk)
|
|
output_file.write(chunk)
|
|
|
|
|
|
@@ -807,7 +809,7 @@ def install_node():
|
|
)
|
|
)
|
|
else: # All other platforms (Linux, MacOS).
|
|
else: # All other platforms (Linux, MacOS).
|
|
# Add execute permissions to fnm executable.
|
|
# Add execute permissions to fnm executable.
|
|
- os.chmod(constants.Fnm.EXE, stat.S_IXUSR)
|
|
|
|
|
|
+ constants.Fnm.EXE.chmod(stat.S_IXUSR)
|
|
# Install node.
|
|
# Install node.
|
|
# Specify arm64 arch explicitly for M1s and M2s.
|
|
# Specify arm64 arch explicitly for M1s and M2s.
|
|
architecture_arg = (
|
|
architecture_arg = (
|
|
@@ -1326,7 +1328,7 @@ def create_config_init_app_from_remote_template(app_name: str, template_url: str
|
|
raise typer.Exit(1) from ose
|
|
raise typer.Exit(1) from ose
|
|
|
|
|
|
# Use httpx GET with redirects to download the zip file.
|
|
# Use httpx GET with redirects to download the zip file.
|
|
- zip_file_path = Path(temp_dir) / "template.zip"
|
|
|
|
|
|
+ zip_file_path: Path = Path(temp_dir) / "template.zip"
|
|
try:
|
|
try:
|
|
# Note: following redirects can be risky. We only allow this for reflex built templates at the moment.
|
|
# Note: following redirects can be risky. We only allow this for reflex built templates at the moment.
|
|
response = net.get(template_url, follow_redirects=True)
|
|
response = net.get(template_url, follow_redirects=True)
|
|
@@ -1336,9 +1338,8 @@ def create_config_init_app_from_remote_template(app_name: str, template_url: str
|
|
console.error(f"Failed to download the template: {he}")
|
|
console.error(f"Failed to download the template: {he}")
|
|
raise typer.Exit(1) from he
|
|
raise typer.Exit(1) from he
|
|
try:
|
|
try:
|
|
- with open(zip_file_path, "wb") as f:
|
|
|
|
- f.write(response.content)
|
|
|
|
- console.debug(f"Downloaded the zip to {zip_file_path}")
|
|
|
|
|
|
+ zip_file_path.write_bytes(response.content)
|
|
|
|
+ console.debug(f"Downloaded the zip to {zip_file_path}")
|
|
except OSError as ose:
|
|
except OSError as ose:
|
|
console.error(f"Unable to write the downloaded zip to disk {ose}")
|
|
console.error(f"Unable to write the downloaded zip to disk {ose}")
|
|
raise typer.Exit(1) from ose
|
|
raise typer.Exit(1) from ose
|