reflex icon indicating copy to clipboard operation
reflex copied to clipboard

Request: (Docs for) Using externally managed bun installation

Open AndydeCleyre opened this issue 2 years ago β€’ 5 comments

Describe the bug

I was surprised when starting a new pynecone project (pc init) resulted in bun getting installed without asking, dropping the installation in the user directory (as opposed to somewhere project-specific).

For development I like to use asdf-vm to manage runtimes, so for example the repo would have a .tool-versions file specifying the runtimes used for developing or deploying the pynecone project:

python 3.11.2
nodejs 19.6.1
bun 0.5.6

My request here is to add documentation on using pynecone such that it doesn't install new runtimes, but allows for the developer/user to manage external runtimes independently.

To Reproduce Steps to reproduce the behavior:

$ mkdir my_app_name
$ cd my_app_name
$ pc init

Expected behavior

Maybe the user could be prompted to approve or reject pynecone's automated installation of bun, along with a link to relevant docs.

Specifics (please complete the following information):

  • Python Version: 3.11.2

  • Pynecone Version: 0.1.16

  • OS: Pop!_OS 22.04 LTS

  • Browser (Optional):

AndydeCleyre avatar Feb 20 '23 21:02 AndydeCleyre

This makes sense we can ask the user if the agree to installation with a y/n option in the cli with link to docs. Should be a quick fix.

In general we prefer bun because it speeds up the pc init and run significantly, but does not seem to support windows yet.

Alek99 avatar Feb 20 '23 21:02 Alek99

I tried removing the pynecone-installed bun and just using the asdf-managed bun, but pynecone currently hardcodes the path of the bun executable AFAICT, so I think there must be a way to override that for this to make sense.

AndydeCleyre avatar Feb 20 '23 21:02 AndydeCleyre

Yes there is a way to specify the bun path using the bun_path in pcconfig.py

config = pc.Config(
    app_name="hello",
    bun_path="$HOME/.bun/bin/bun",
    db_url="sqlite:///pynecone.db",
    env=pc.Env.DEV,
    port=3000,
)

https://pynecone.io/docs/getting-started/project-structure

Alek99 avatar Feb 20 '23 21:02 Alek99

Great, thanks! In that case my next concern would just be that there be an option to confirm or reject ahead of time via CLI flag, for anyone scripting these steps.

AndydeCleyre avatar Feb 20 '23 21:02 AndydeCleyre

Got it will add thanks for the feedback!

Alek99 avatar Feb 20 '23 21:02 Alek99

@Alek99 for users of alternative Linux distros like Guix System and NixOS, we need to use the Nixpkg of Bun because these distros are not FHS-compliant.

The bun_path method works, sort of, but breaks using Reflex pre-releases, which is worrying.

When pointing bun_path to my own Nixpkg of Bun using Reflex v0.2.2, Reflex works but complains of version incompatibility and offers to delete my existing Bun installation. If I accept, Reflex runs successfully with my own Bun, despite the version mismatch, because Nixpkgs are saved to immutable store paths and can't be rm-ed.

11:49:29 (.venv) worldofgeese@mahakala debaser_studio Β±|main βœ—|β†’ reflex run
───────────────────────────── Starting Reflex App ──────────────────────────────
Compiling:  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 1/1 0:00:00
Bun version 0.7.0 is not supported by Reflex. Please change your to bun version 
to be between 0.5.9 and 0.6.9.
Enter 'yes' to install the latest supported bun version or 'no' to exit. 
[yes/no] (no): yes
[23:49:37] Removing bun...                                         console.py:30
───────────────────────── Installing frontend packages ─────────────────────────
bun install v0.7.0 (aa1ad7f0)
───────────────────────────────── App Running ──────────────────────────────────
App running at: http://localhost:3000
Compiling:  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 1/1 0:00:00

If I install the latest pre-release of Reflex, version 0.2.3a8, Reflex will refuse to run, complaining of a missing $HOME/.reflex/.bun/bin/bun, even if I mkdir -p the path and touch an executable bun.

Current behavior in 0.2.2 at least allows me to run my own Bun but with some friction. Pre-release behavior is more worrying, since I wouldn't be able to work around it.

Ideally, users should be able to provide their own Bun path, disable version checks, and disable Reflex's built-in method for installing Bun to run in atypical environments. In other words, disable all Bun-related checks and sourcing and just run whatever is provided at bun_path without guarantees.

worldofgeese avatar Jul 31 '23 06:07 worldofgeese

@Alek99 I can confirm that upgrading to the new release version of Reflex, v0.2.3, breaks Reflex for users of Guix System and NixOS. Logs included below the Details toggle πŸ‘‡πŸΌ . My hunch is that Reflex is no longer respecting bun_path.

Running

mkdir -p /home/worldofgeese/.reflex/.bun/bin
touch /home/worldofgeese/.reflex/.bun/bin/bun
chmod +x /home/worldofgeese/.reflex/.bun/bin/bun

does not bypass the FileNotFoundError: [Errno 2] No such file or directory: '/home/worldofgeese/.reflex/.bun/bin/bun' error.

If I rm /home/worldofgeese/.reflex/.bun/bin/bun, then echo -e "#!/bin/bash\necho 'Dummy bun script.'" > /home/worldofgeese/.reflex/.bun/bin/bun, then run reflex run again, Reflex appears to run but does not start the webserver at port 3000 and this leads me to believe Reflex is trying to run its own bun and not the one specified in bun_path, working in v0.2.2.

09:02:41 (.venv) worldofgeese@mahakala debaser_studio Β±|main βœ—|β†’ reflex run
───────────────────────────────────────────── Starting Reflex App ─────────────────────────────────────────────
Compiling:  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 1/1 0:00:00
───────────────────────────────────────────────── App Running ─────────────────────────────────────────────────
Compiling:  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 1/1 0:00:00
09:05:53 worldofgeese@mahakala ~ β†’ curl http://localhost:3000
curl: (7) Failed to connect to localhost port 3000 after 0 ms: Connection refused
08:49:06 (.venv) worldofgeese@mahakala debaser_studio Β±|main βœ—|β†’ reflex run
───────────────────────────────────────────── Starting Reflex App ─────────────────────────────────────────────
Compiling:  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 1/1 0:00:00
Traceback (most recent call last):
  File "/home/worldofgeese/Downloads/projects/debaser_studio/.venv/bin/reflex", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/worldofgeese/Downloads/projects/debaser_studio/.venv/lib/python3.11/site-packages/typer/main.py", line 214, in __call__
    return get_command(self)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/worldofgeese/Downloads/projects/debaser_studio/.venv/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/worldofgeese/Downloads/projects/debaser_studio/.venv/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/worldofgeese/Downloads/projects/debaser_studio/.venv/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/worldofgeese/Downloads/projects/debaser_studio/.venv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/worldofgeese/Downloads/projects/debaser_studio/.venv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/worldofgeese/Downloads/projects/debaser_studio/.venv/lib/python3.11/site-packages/typer/main.py", line 532, in wrapper
    return callback(**use_params)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/worldofgeese/Downloads/projects/debaser_studio/.venv/lib/python3.11/site-packages/reflex/reflex.py", line 172, in run
    setup_frontend(Path.cwd())
  File "/home/worldofgeese/Downloads/projects/debaser_studio/.venv/lib/python3.11/site-packages/reflex/utils/build.py", line 181, in setup_frontend
    prerequisites.install_frontend_packages()
  File "/home/worldofgeese/Downloads/projects/debaser_studio/.venv/lib/python3.11/site-packages/reflex/utils/prerequisites.py", line 370, in install_frontend_packages
    process = processes.new_process(
              ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/worldofgeese/Downloads/projects/debaser_studio/.venv/lib/python3.11/site-packages/reflex/utils/processes.py", line 153, in new_process
    return fn(args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/nix/store/4brzwdiqzj7zkkd4g5107d7zdv6sp168-devenv-profile/lib/python3.11/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/nix/store/4brzwdiqzj7zkkd4g5107d7zdv6sp168-devenv-profile/lib/python3.11/subprocess.py", line 1950, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/worldofgeese/.reflex/.bun/bin/bun'

worldofgeese avatar Jul 31 '23 06:07 worldofgeese

@Alek99 I can confirm that upgrading to the new release version of Reflex, v0.2.3, breaks Reflex for users of Guix System and NixOS. Logs included below the Details toggle πŸ‘‡πŸΌ . My hunch is that Reflex is no longer respecting bun_path.

Running

mkdir -p /home/worldofgeese/.reflex/.bun/bin
touch /home/worldofgeese/.reflex/.bun/bin/bun
chmod +x /home/worldofgeese/.reflex/.bun/bin/bun

does not bypass the FileNotFoundError: [Errno 2] No such file or directory: '/home/worldofgeese/.reflex/.bun/bin/bun' error.

If I rm /home/worldofgeese/.reflex/.bun/bin/bun, then echo -e "#!/bin/bash\necho 'Dummy bun script.'" > /home/worldofgeese/.reflex/.bun/bin/bun, then run reflex run again, Reflex appears to run but does not start the webserver at port 3000 and this leads me to believe Reflex is trying to run its own bun and not the one specified in bun_path, working in v0.2.2.

09:02:41 (.venv) worldofgeese@mahakala debaser_studio Β±|main βœ—|β†’ reflex run
───────────────────────────────────────────── Starting Reflex App ─────────────────────────────────────────────
Compiling:  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 1/1 0:00:00
───────────────────────────────────────────────── App Running ─────────────────────────────────────────────────
Compiling:  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 1/1 0:00:00
09:05:53 worldofgeese@mahakala ~ β†’ curl http://localhost:3000
curl: (7) Failed to connect to localhost port 3000 after 0 ms: Connection refused

Reflex using its own bun is expected behavior. In version 0.2.3, the support for specifying a bun_path is dropped, which means the installation of node and bun dependencies are abstracted and handled under the hood. The point of this is to allow reflex to ship with (or decide) which dependencies are compatible with it.

Does the app run if you rm -rf $HOME/.reflex and reflex init and reflex run?

ElijahAhianyo avatar Jul 31 '23 10:07 ElijahAhianyo

Reflex using its own bun is expected behavior. In version 0.2.3, the support for specifying a bun_path is dropped, which means the installation of node and bun dependencies are abstracted and handled under the hood. The point of this is to allow reflex to ship with (or decide) which dependencies are compatible with it.

I'd like to request bun_path support be returned otherwise non-FHS compatible distros, like my own, won't have any recourse moving forward. May I ask why the option was removed?

Does the app run if you rm -rf $HOME/.reflex and reflex init and reflex run?

No, because Guix System and NixOS don't use FHS. Dependencies are hermetically determined. Any locally managed Bun installed by Reflex won't have access to the paths it expects in an FHS-compliant distro.

If the option to specify your own bun_path wasn't harming anyone, I'd really appreciate an option to stay up to date with the latest Reflex.

worldofgeese avatar Jul 31 '23 10:07 worldofgeese

can you open a separate issue for this?

ElijahAhianyo avatar Jul 31 '23 11:07 ElijahAhianyo