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

Cli attempt #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Cli attempt #2

wants to merge 2 commits into from

Conversation

EJEmmett
Copy link
Contributor

@EJEmmett EJEmmett commented Nov 9, 2021

Hi,

I took a crack at making a Cli tool, as I noted in the commit, it's got a pretty significant limitation at the moment.

Using input("prompt") buffers the output of the prompt until user input has been given. This likely extends to other areas of user interaction as well. This also seemingly varies from terminal to terminal, PyCharms builtin terminal ignores this limitation and functions fine. Windows powershell and cmd both buffer the input, alongside the buffered input, both terminals also pass the prompt of the input to stderr instead of stdout.

I figured I'd let you take a glance and determine if you could spot any other methods of going about it.

While doing that I noticed that the method of getting the length was wrong in some edge cases. Those should be dealt with however, there is also an issue of CPython injecting content into the traceback after it's been pulled into the lower level environment. The new 3.10 suggestions don't appear in exceptions created by the traceback module at the moment, currently it seems the only way to match the sizing is the capture the output of stderr and parse that, but as always, that's a bit iffy.
image
The traceback module only creates up to not defined, everything past that is generated after the exception has been fired off.

image
image
image

…k are printed within the same buffer.

Changed the sizing method, taking the best of manual formatting and automatic formatting. `traceback` doesn't use cpythons current format for determining the pathname of an object, but it does format most of the messages correct.

Small limitation with 3.10 in mind, the suggestions added by 3.10's error handling update doesn't cross over to python's traceback. Namely the suggestion system added is done completely in python, negating the ability to grab it. The result of STDERR could be captured to parse that first, ensuring that it's always the correct length.
…age, `python -m __main__.py test.py` or by installing it through pip with the local sdist.

A console script was added to the setup.py and can be used as `assistant test.py`.

Notable limitation:
   Using `input("prompt")` buffers the output of the prompt until user input has been given. This likely extends to other areas of user interaction as well. This also seemingly varies from terminal to terminal, PyCharms builtin terminal ignores this limitation and functions fine. Windows powershell and cmd both buffer the input, alongside the buffered input, both terminals also pass the prompt of the input to stderr.
@lorlouis
Copy link
Owner

I looked at the code and the main looks a bit too hacky for me. But you laid the groundwork. I've sent you a PR on the branch so that you can see what I've done. As for CPython injecting text in the error messages, I haven't updated to python3.10 yet, If you could create an issue I could look into it once I have updated.

@lorlouis
Copy link
Owner

If you merge it I can then merge this PR with the changes you made to setup.py

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

Successfully merging this pull request may close these issues.

None yet

2 participants