Clean up doc string
This commit is contained in:
parent
05442a4aca
commit
7d0d72c0df
@ -2,11 +2,11 @@
|
|||||||
Only the app attribute is explicitly exposed.
|
Only the app attribute is explicitly exposed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import time
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
import time
|
|
||||||
from reflex import constants
|
from reflex import constants
|
||||||
|
from reflex.utils import telemetry
|
||||||
from reflex.utils.exec import is_prod_mode
|
from reflex.utils.exec import is_prod_mode
|
||||||
from reflex.utils.prerequisites import get_app
|
from reflex.utils.prerequisites import get_app
|
||||||
|
|
||||||
@ -20,17 +20,9 @@ app = getattr(app_module, constants.CompileVars.APP)
|
|||||||
app._apply_decorated_pages()
|
app._apply_decorated_pages()
|
||||||
start_time = time.perf_counter()
|
start_time = time.perf_counter()
|
||||||
|
|
||||||
def compile_callback(f):
|
|
||||||
from reflex.utils import telemetry
|
|
||||||
try:
|
|
||||||
# Force background compile errors to print eagerly
|
|
||||||
f.result()
|
|
||||||
finally:
|
|
||||||
telemetry.send("test-compile", duration=time.perf_counter()- start_time)
|
|
||||||
del telemetry
|
|
||||||
|
|
||||||
compile_future = ThreadPoolExecutor(max_workers=1).submit(app._compile)
|
compile_future = ThreadPoolExecutor(max_workers=1).submit(app._compile)
|
||||||
compile_future.add_done_callback(compile_callback)
|
compile_future.add_done_callback(lambda f: telemetry.compile_callback(f, start_time))
|
||||||
|
|
||||||
# Wait for the compile to finish in prod mode to ensure all optional endpoints are mounted.
|
# Wait for the compile to finish in prod mode to ensure all optional endpoints are mounted.
|
||||||
if is_prod_mode():
|
if is_prod_mode():
|
||||||
@ -41,6 +33,5 @@ del app_module
|
|||||||
del compile_future
|
del compile_future
|
||||||
del get_app
|
del get_app
|
||||||
del is_prod_mode
|
del is_prod_mode
|
||||||
|
|
||||||
del constants
|
del constants
|
||||||
del ThreadPoolExecutor
|
del ThreadPoolExecutor
|
||||||
|
@ -44,7 +44,7 @@ class Meta(BaseHTML): # Inherits common attributes from BaseHTML
|
|||||||
"""Display the meta element."""
|
"""Display the meta element."""
|
||||||
|
|
||||||
tag = "meta"
|
tag = "meta"
|
||||||
|
|
||||||
char_set: Var[Union[str, int, bool]]
|
char_set: Var[Union[str, int, bool]]
|
||||||
content: Var[Union[str, int, bool]]
|
content: Var[Union[str, int, bool]]
|
||||||
http_equiv: Var[Union[str, int, bool]]
|
http_equiv: Var[Union[str, int, bool]]
|
||||||
|
@ -4,11 +4,11 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import atexit
|
import atexit
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
import webbrowser
|
import webbrowser
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
import time
|
|
||||||
import typer
|
import typer
|
||||||
import typer.core
|
import typer.core
|
||||||
from reflex_cli.deployments import deployments_cli
|
from reflex_cli.deployments import deployments_cli
|
||||||
@ -110,10 +110,10 @@ def _init(
|
|||||||
template = constants.Templates.DEFAULT
|
template = constants.Templates.DEFAULT
|
||||||
|
|
||||||
start_time = time.perf_counter()
|
start_time = time.perf_counter()
|
||||||
|
|
||||||
# Check if the app is already initialized.
|
# Check if the app is already initialized.
|
||||||
reinit = os.path.exists(constants.Config.FILE)
|
reinit = os.path.exists(constants.Config.FILE)
|
||||||
|
|
||||||
# Initialize the app.
|
# Initialize the app.
|
||||||
prerequisites.initialize_app(app_name, template, reinit=reinit)
|
prerequisites.initialize_app(app_name, template, reinit=reinit)
|
||||||
|
|
||||||
@ -138,7 +138,8 @@ def _init(
|
|||||||
# Post telemetry event
|
# Post telemetry event
|
||||||
event_type = "reinit" if reinit else "init"
|
event_type = "reinit" if reinit else "init"
|
||||||
telemetry.send(event_type, duration=time.perf_counter() - start_time)
|
telemetry.send(event_type, duration=time.perf_counter() - start_time)
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
def init(
|
def init(
|
||||||
name: str = typer.Option(
|
name: str = typer.Option(
|
||||||
|
@ -1425,6 +1425,7 @@ def initialize_app(app_name: str, template: str | None = None, reinit: bool = Fa
|
|||||||
Args:
|
Args:
|
||||||
app_name: The name of the app.
|
app_name: The name of the app.
|
||||||
template: The name of the template to use.
|
template: The name of the template to use.
|
||||||
|
reinit: Whether to reinitialize the app.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
Exit: If template is directly provided in the command flag and is invalid.
|
Exit: If template is directly provided in the command flag and is invalid.
|
||||||
@ -1469,6 +1470,7 @@ def initialize_app(app_name: str, template: str | None = None, reinit: bool = Fa
|
|||||||
template_url=template_url,
|
template_url=template_url,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def initialize_main_module_index_from_generation(app_name: str, generation_hash: str):
|
def initialize_main_module_index_from_generation(app_name: str, generation_hash: str):
|
||||||
"""Overwrite the `index` function in the main module with reflex.build generated code.
|
"""Overwrite the `index` function in the main module with reflex.build generated code.
|
||||||
|
|
||||||
|
@ -4,9 +4,11 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
import time
|
||||||
import warnings
|
import warnings
|
||||||
import os
|
|
||||||
try:
|
try:
|
||||||
from datetime import UTC, datetime
|
from datetime import UTC, datetime
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -69,7 +71,7 @@ def get_cpu_count() -> int:
|
|||||||
"""
|
"""
|
||||||
return multiprocessing.cpu_count()
|
return multiprocessing.cpu_count()
|
||||||
|
|
||||||
|
|
||||||
def get_memory() -> int:
|
def get_memory() -> int:
|
||||||
"""Get the total memory in MB.
|
"""Get the total memory in MB.
|
||||||
|
|
||||||
@ -80,7 +82,8 @@ def get_memory() -> int:
|
|||||||
return psutil.virtual_memory().total >> 20
|
return psutil.virtual_memory().total >> 20
|
||||||
except ValueError: # needed to pass ubuntu test
|
except ValueError: # needed to pass ubuntu test
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def get_folder_size(folder: str) -> int:
|
def get_folder_size(folder: str) -> int:
|
||||||
"""Get the total size of a folder in bytes, ignoring 'node_modules' folder.
|
"""Get the total size of a folder in bytes, ignoring 'node_modules' folder.
|
||||||
|
|
||||||
@ -91,12 +94,11 @@ def get_folder_size(folder: str) -> int:
|
|||||||
The total size of the folder in bytes.
|
The total size of the folder in bytes.
|
||||||
"""
|
"""
|
||||||
total_files = 0
|
total_files = 0
|
||||||
for dirpath, dirnames, filenames in os.walk(folder):
|
for _, _, filenames in os.walk(folder):
|
||||||
total_files += len(filenames)
|
total_files += len(filenames)
|
||||||
return total_files
|
return total_files
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _raise_on_missing_project_hash() -> bool:
|
def _raise_on_missing_project_hash() -> bool:
|
||||||
"""Check if an error should be raised when project hash is missing.
|
"""Check if an error should be raised when project hash is missing.
|
||||||
|
|
||||||
@ -113,6 +115,20 @@ def _raise_on_missing_project_hash() -> bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def compile_callback(f, start_time):
|
||||||
|
"""Callback to send telemetry after compiling the app.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
f: The future object.
|
||||||
|
start_time: The start time of the compilation.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# Force background compile errors to print eagerly
|
||||||
|
f.result()
|
||||||
|
finally:
|
||||||
|
send("test-compile", duration=time.perf_counter() - start_time)
|
||||||
|
|
||||||
|
|
||||||
def _prepare_event(event: str, **kwargs) -> dict:
|
def _prepare_event(event: str, **kwargs) -> dict:
|
||||||
"""Prepare the event to be sent to the PostHog server.
|
"""Prepare the event to be sent to the PostHog server.
|
||||||
|
|
||||||
@ -160,7 +176,9 @@ def _prepare_event(event: str, **kwargs) -> dict:
|
|||||||
"cpu_count": get_cpu_count(),
|
"cpu_count": get_cpu_count(),
|
||||||
"memory": get_memory(),
|
"memory": get_memory(),
|
||||||
"cpu_info": dict(cpuinfo) if cpuinfo else {},
|
"cpu_info": dict(cpuinfo) if cpuinfo else {},
|
||||||
"pages_count": get_folder_size(".web/pages") if event == "test-compile" or event == "run-dev" else None,
|
"pages_count": get_folder_size(".web/pages")
|
||||||
|
if event == "test-compile" or event == "run-dev"
|
||||||
|
else None,
|
||||||
**additional_fields,
|
**additional_fields,
|
||||||
},
|
},
|
||||||
"timestamp": stamp,
|
"timestamp": stamp,
|
||||||
|
Loading…
Reference in New Issue
Block a user