Textualize / trogon

Easily turn your Click CLI into a powerful terminal application
MIT License
2.4k stars 54 forks source link

FileNotFoundError during trivial example #68

Closed famura closed 7 months ago

famura commented 7 months ago

When executing my small test script scripts/trogon_test.py

@tui()
@click.command()
@click.option(
    "--plot_opt_metrics/--no-plot_opt_metrics",
    type=click.BOOL,
    default=False,
    help="Whether to plot and display the loss, defects, and Lagrangian multipliers of the constrained optimization.",
)
def main(
    plot_opt_metrics: bool,
):
    """Create and run a dynamic experimental design."""
    print("printing the only option: ", plot_opt_metrics)

if __name__ == "__main__":
    main()

in the command line using

poetry run python scripts/trogon_test.py tui

it displays the desired TUI, however, instantly crashes when hitten Crtl + R for running it:

poetry run python scripts/trogon_test.py tui
Running trogon_test.py main
Traceback (most recent call last):
  File "scripts/trogon_test.py", line 52, in <module>
    main()
  File "/home/redacted/.venv/lib/python3.8/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/home/redacted/.venv/lib/python3.8/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/redacted/.venv/lib/python3.8/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/redacted/.venv/lib/python3.8/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/redacted/.venv/lib/python3.8/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/redacted/.venv/lib/python3.8/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/redacted/.venv/lib/python3.8/site-packages/trogon/trogon.py", line 296, in wrapped_tui
    Trogon(app, app_name=name, command_name=command, click_context=ctx).run()
  File "/home/redacted/.venv/lib/python3.8/site-packages/trogon/trogon.py", line 264, in run
    os.execvp(program_name, arguments)
  File "/home/muf2rng/.pyenv/versions/3.8.17/lib/python3.8/os.py", line 568, in execvp
    _execvpe(file, args)
  File "/home/muf2rng/.pyenv/versions/3.8.17/lib/python3.8/os.py", line 610, in _execvpe
    raise last_exc
  File "/home/muf2rng/.pyenv/versions/3.8.17/lib/python3.8/os.py", line 601, in _execvpe
    exec_func(fullname, *argrest)
FileNotFoundError: [Errno 2] No such file or directory
famura commented 7 months ago

The fault was on my side here. I needed to register my CLI via poetry in the pyproject.toml. For example:

[tool.poetry.scripts]
mycli = "project_name.file_with_cli:cli_name"

Next, I needed to run poetry install.

After that, I could run the TUI as stated before poetry run mycli tui