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

User doesn't pass arguments to command #96

Open
ghost opened this issue May 14, 2023 · 8 comments
Open

User doesn't pass arguments to command #96

ghost opened this issue May 14, 2023 · 8 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@ghost
Copy link

ghost commented May 14, 2023

Machine:

macOS 12.6.5
Python 3.11.3
Pip 22.0.x (I'm not sure what the "x" is...)

Problem:

When calling the pygbag command in a terminal without any arguments, you get the following error:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.11/bin/pygbag", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pygbag/app.py", line 479, in main
    asyncio.run(main_run(app_folder, mainscript))
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pygbag/app.py", line 174, in main_run
    parser = argparse.ArgumentParser()
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 1760, in __init__
    prog = _os.path.basename(_sys.argv[0])
                             ~~~~~~~~~^^^

This is because the code tries to find an argument (with indices) when none are given, thus an IndexError is raised.

Solution (suggestion):

Instead of throwing an ugly, long error, just give the user the "help" message. I've seen this done in other CL tools. When I ran the command pygbag, I expected a help message. Logically, this makes sense as if the user is new to the tool, and runs the comand without any flags or arguments, maybe they are confused, or don't know the tool works. Thus, a help message would, well, be helpful.

@pmp-p pmp-p added the help wanted Extra attention is needed label May 15, 2023
@pmp-p
Copy link
Member

pmp-p commented May 15, 2023

"pygbag" is a shortcut generated by pip installer, the canonical way to run is python3 -m pygbag and that one seems to send correct error message, at least on linux. I never really had time to test on win/mac, so feel free to implement, test and PR. Patches and documentation are very welcome especially for win/mac.

@pmp-p pmp-p added the good first issue Good for newcomers label May 15, 2023
@ghost
Copy link
Author

ghost commented May 15, 2023

@pmp-p - Hello Paul,

I'll first do a bit of research and learning on CLI tools and how pygbag works before jumping into a PR. I have absolutely no experience with Python CLI tools and how pip really works 😅.

Based on what you've told me, I assume this is a problem with pygbag and not pip generating the shortcut incorrectly, correct?

@pmp-p
Copy link
Member

pmp-p commented May 16, 2023

i think pygbag is lacking a detection mechanism when len(sys.argv) is == 0 That situation may happen when calling it via pip entry point ( not really a shortcut, it is a tiny python program generated by pip in the path).

@ghost
Copy link
Author

ghost commented May 16, 2023

@pmp-p - Thanks, that helps a ton! 😄

@ghost
Copy link
Author

ghost commented May 16, 2023

Might make a PR...

Looks like this can be solved with some code in line 17 in ./pygbag/__main__.py. Maybe this would work:

if len(sys.argv) == 0:
    print("...")
    raise SystemExit(0)

@pmp-p - I'm not sure how you're printing the help or support message. Is it just a massive string or something else...?

@pmp-p
Copy link
Member

pmp-p commented Sep 26, 2023

Is it just a massive string or something else

it's a list of all what precedently failed, when that list is non-zero the program halts and report

@Rioran
Copy link

Rioran commented Apr 26, 2024

If I may, the way to call documentation is also slightly frustrating. I wasn't expecting --help to require folder as an argument.

@pmp-p
Copy link
Member

pmp-p commented Apr 26, 2024

--help is relative to current project target, it may change in the future based on projects templates.

pygbag roots in posix, usage and help are different things.

usage is not currently implemented on entry point script feel free to PR.

python -m pygbag -> usage is quite ok
python -m pygbag --help project/main.py -> help for project with specific paths.
pygbag -> usage is indeed missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants