MCPcopy
hub / github.com/reflex-dev/reflex / run_process_and_launch_url

Function run_process_and_launch_url

reflex/utils/exec.py:220–281  ·  view source on GitHub ↗

Run the process and launch the URL. Args: run_command: The command to run. backend_present: Whether the backend is present.

(
    run_command: list[str | None], backend_present: bool = True
)

Source from the content-addressed store, hash-verified

218# only to launch the frontend
219# If this is not the case, might have to change the logic
220def run_process_and_launch_url(
221 run_command: list[str | None], backend_present: bool = True
222):
223 """Run the process and launch the URL.
224
225 Args:
226 run_command: The command to run.
227 backend_present: Whether the backend is present.
228 """
229 from reflex.utils import processes
230
231 json_file_path = get_web_dir() / constants.PackageJson.PATH
232 last_content, last_hash = get_package_json_and_hash(json_file_path)
233 process = None
234 first_run = True
235
236 while True:
237 if process is None:
238 kwargs: dict[str, Any] = {
239 "env": {
240 **os.environ,
241 "NO_COLOR": "1",
242 }
243 }
244 if constants.IS_WINDOWS and backend_present:
245 kwargs["creationflags"] = subprocess.CREATE_NEW_PROCESS_GROUP # pyright: ignore [reportAttributeAccessIssue]
246 process = processes.new_process(
247 run_command,
248 cwd=get_web_dir(),
249 shell=constants.IS_WINDOWS,
250 **kwargs,
251 )
252 global frontend_process
253 frontend_process = process
254 if process.stdout:
255 for line in processes.stream_logs("Starting frontend", process):
256 new_content, new_hash = get_package_json_and_hash(json_file_path)
257 if new_hash != last_hash:
258 dependencies_change, dev_dependencies_change = (
259 get_different_packages(last_content, new_content)
260 )
261 last_content, last_hash = new_content, new_hash
262 console.info(
263 "Detected changes in package.json.\n"
264 + format_change("Dependencies", dependencies_change)
265 + format_change("Dev Dependencies", dev_dependencies_change)
266 )
267
268 match = re.search(constants.ReactRouter.FRONTEND_LISTENING_REGEX, line)
269 if match:
270 if first_run:
271 url = match.group(1)
272
273 notify_frontend(url, backend_present)
274 if backend_present:
275 notify_backend()
276 first_run = False
277 else:

Callers 1

run_frontendFunction · 0.85

Calls 6

get_web_dirFunction · 0.90
get_different_packagesFunction · 0.85
format_changeFunction · 0.85
notify_frontendFunction · 0.85
notify_backendFunction · 0.85

Tested by

no test coverage detected