Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trogon script execution fails with FileNotFoundError: [Errno 2] No such file or directory #70

Open
arunabha opened this issue Dec 18, 2023 · 4 comments

Comments

@arunabha
Copy link

Running the nogroup_demo example fails with FileNotFoundError: [Errno 2] No such file or directory

The cwd and the program_name arguments to the os.execvp call seem to be correct, however the run still fails. The cli version works fine though.

I added a debug log just before the call to execvp listing the following
prog_name = nogroup_demo.py, args = ['nogroup_demo.py', 'add', '--category', 'work', 'foo'] app_name = nogroup_demo.py cwd = /Users/arunabhaghosh/dev/import_migrate_data

---- Details--------------------------

Running nogroup_demo.py add --category work foo
prog_name = nogroup_demo.py, args = ['nogroup_demo.py', 'add', '--category', 'work', 'foo'] app_name = nogroup_demo.py cwd = /Users/arunabhaghosh/dev/import_migrate_data
Traceback (most recent call last):
File "/Users/arunabhaghosh/dev/import_migrate_data/nogroup_demo.py", line 52, in
add()
File "/Users/arunabhaghosh/dev/import_migrate_data/venv/lib/python3.11/site-packages/click/core.py", line 1157, in call
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/arunabhaghosh/dev/import_migrate_data/venv/lib/python3.11/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/Users/arunabhaghosh/dev/import_migrate_data/venv/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/arunabhaghosh/dev/import_migrate_data/venv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/arunabhaghosh/dev/import_migrate_data/venv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/arunabhaghosh/dev/import_migrate_data/venv/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
return f(get_current_context(), *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/arunabhaghosh/dev/import_migrate_data/venv/lib/python3.11/site-packages/trogon/trogon.py", line 297, in wrapped_tui
Trogon(app, app_name=name, command_name=command, click_context=ctx).run()
File "/Users/arunabhaghosh/dev/import_migrate_data/venv/lib/python3.11/site-packages/trogon/trogon.py", line 265, in run
os.execvp(program_name, arguments)
File "", line 574, in execvp
File "", line 616, in _execvpe
File "", line 607, in _execvpe
FileNotFoundError: [Errno 2] No such file or directory

@mgielda
Copy link

mgielda commented Dec 28, 2023

I can confirm the bug. Also, if you don't select anything the demo fails with a different error, but the selection is not marked as compulsory. This is probably less of an issue but still got me confused initially.

Anyway the No such file or directory also occurs for me in my attempts to use this project in another practical app.

@iandennismiller
Copy link

@mgielda by any chance are you running trogon inside a virtual environment? I noticed that trogon echos a preview of the command it will run when ctrl-R is pressed. If that preview command were entered directly on the command line, would the environment be set correctly so the script would be in the path? In my case, the answer was no.

I solved this in my situation by activating the virtual environment in my shell before launching trogon. Previously, I had been launching in a different way that avoided the shell activation part of venv.

@42sol-eu
Copy link

I have the same issue.
Using Ctrl+R after setting values.

Could it be connected to trogon calling the python script directly instead of using `python ./{script_name}.py ?

I am not in a virtual environment and using the default python.
Running on Windows 10.

  • Click Version 8.0
  • Trogon latest
scripts main *% = $ python .\trogon_demo.py tui 

Running trogon_demo.py add test
Traceback (most recent call last):
  File "C:\_projects\onboarding_template\scripts\trogon_demo.py", line 89, in <module>
    cli(obj={})
  File "C:\python\v311\Lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\python\v311\Lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "C:\python\v311\Lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\python\v311\Lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\python\v311\Lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\python\v311\Lib\site-packages\click\decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\python\v311\Lib\site-packages\trogon\trogon.py", line 296, in wrapped_tui
    Trogon(app, app_name=name, command_name=command, click_context=ctx).run()
  File "C:\python\v311\Lib\site-packages\trogon\trogon.py", line 264, in run
    os.execvp(program_name, arguments)
  File "<frozen os>", line 574, in execvp
  File "<frozen os>", line 616, in _execvpe
  File "<frozen os>", line 607, in _execvpe
FileNotFoundError: [Errno 2] No such file or directory

@42sol-eu
Copy link

I confirm that extending trogon.py in the run function like the following solve my issue

                    arguments = [f"./{program_name}", *self.post_run_command]
                    print(f"{program_name=}, {arguments=}")
                    os.execvp("python", arguments)

meaning:

  • adding a ./ helps for my setup with a local defined script (and not an installed package)
  • prefixing python executable solve the issue.

It strangely does not work on the demo.py from the examples folder.

Maybe I have to recheck after a good nights sleep ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants